-
Notifications
You must be signed in to change notification settings - Fork 21
/
OutputDataConfigToolkitListener.php
59 lines (54 loc) · 1.79 KB
/
OutputDataConfigToolkitListener.php
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
<?php
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/
namespace AppBundle\EventListener;
use OutputDataConfigToolkitBundle\Event\InitializeEvent;
use OutputDataConfigToolkitBundle\Event\OutputDataConfigToolkitEvents;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\DataObject\Folder;
use Pimcore\Model\DataObject\Product;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class OutputDataConfigToolkitListener
* @package AppBundle\EventListener
*/
class OutputDataConfigToolkitListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
OutputDataConfigToolkitEvents::INITIALIZE => "onInitialize"
];
}
/**
* Manipulate outputdataconfigtoolkit initialization
* - only show output config tab for product objects
* - always use product root
*
* @param InitializeEvent $event
*/
public function onInitialize(InitializeEvent $event)
{
$object = $event->getObject();
if (!$object instanceof Concrete || $object->getClassName() != substr(strrchr(Product::class, "\\"), 1)) {
$event->setHideConfigTab(true);
} else {
while (
$object->getParentId() != 1
&& !$object->getParent() instanceof Folder
&& ($object = $object->getParent())
);
}
$event->setObject($object);
}
}