-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathIconDataSource.php
More file actions
63 lines (56 loc) · 2.06 KB
/
IconDataSource.php
File metadata and controls
63 lines (56 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Sitegeist\Stampede\DataSource;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Service\DataSource\AbstractDataSource;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Sitegeist\Stampede\Domain\IconCollection;
use Sitegeist\Stampede\Domain\IconCollectionRepository;
class IconDataSource extends AbstractDataSource
{
/**
* @var string
*/
protected static $identifier = 'sitegeist-stampede-icons';
/**
* @var IconCollectionRepository
* @Flow\Inject
*/
protected $iconCollectionRepository;
/**
* Get data
*
* @param NodeInterface|null $node The node that is currently edited (optional)
* @param array $arguments Additional arguments (key / value)
* @return array JSON serializable data
*/
public function getData(?NodeInterface $node = null, array $arguments = [])
{
$result = [];
if (array_key_exists('collections', $arguments) && !empty($arguments['collections'])) {
/**
* @var IconCollection[]
*/
$iconCollections = [];
foreach ($arguments['collections'] as $iconCollection) {
$collection = $this->iconCollectionRepository->findOneByIdentifier($iconCollection);
if ($collection) {
$iconCollections[] = $collection;
}
}
} else {
$iconCollections = $this->iconCollectionRepository->findAll();
}
foreach ($iconCollections as $iconCollection) {
foreach ($iconCollection->findAll() as $icon) {
$result[] = [
'group' => $iconCollection->getLabel(),
'value' => $iconCollection->getIdentifier() . ':' . $icon->getIdentifier(),
'icon' => $iconCollection->getIdentifier() . ':' . $icon->getIdentifier(),
'label' => $icon->getLabel(),
'preview' => 'data:image/svg+xml;base64,' . base64_encode($icon->getSvg())
];
}
}
return $result;
}
}