bundles/IndabaExtensionBundle/EventListener/ClassEventListener.php line 19

Open in your IDE?
  1. <?php
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. namespace IndabaExtensionBundle\EventListener;
  8. use Symfony\Component\EventDispatcher\GenericEvent;
  9. /**
  10.  * Description of ClassEventListener
  11.  *
  12.  * @author PcCom
  13.  */
  14. class ClassEventListener
  15. {
  16.     public function changeObjectbricksTree(GenericEvent $event)
  17.     {
  18.         if (\Pimcore::getContainer()->getParameter("indabaExtension.dataObject.onlyAllowedObjectbricks")) {
  19.             $list $event->getArgument('list');
  20.             $objectId $event->getArgument('objectId');
  21.             if ($objectId 0) {
  22.                 $object \Pimcore\Model\DataObject\AbstractObject::getById($objectId);
  23.                 $allowedString $object->getProperty("allowedObjectbricks");
  24.                 $allowedList = array();
  25.                 if (!empty($allowedString)) {
  26.                     $allowedList explode(","str_replace(" """$allowedString));
  27.                 }
  28.                 if (is_array($allowedList) && count($allowedList) > 0) {
  29.                     if ("none" === reset($allowedList)) {
  30.                         $list = [];
  31.                     } else {
  32.                         foreach ($list as $key1 => $objectbrick_node1) {
  33.                             if (array_key_exists("children"$objectbrick_node1)) {
  34.                                 foreach ($objectbrick_node1['children'] as $key2 => $objectbrick_node2) {
  35.                                     if (!in_array($objectbrick_node2['id'], $allowedList)) {
  36.                                         unset($list[$key1]["children"][$key2]);
  37.                                     }
  38.                                 }
  39.                                 if (== count($list[$key1]["children"])) {
  40.                                     unset($list[$key1]);
  41.                                 }
  42.                             } else {
  43.                                 if (!in_array($objectbrick_node1['id'], $allowedList)) {
  44.                                     unset($list[$key1]);
  45.                                 }
  46.                             }
  47.                         }
  48.                         sort($list);
  49.                     }
  50.                 }
  51.             }
  52.             $event->setArgument('list'$list);
  53.         }
  54.     }
  55. }