vendor/kunstmaan/pagepart-bundle/EventListener/NodeListener.php line 65

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\PagePartBundle\EventListener;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Kunstmaan\AdminBundle\Helper\FormWidgets\ListWidget;
  5. use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\Tab;
  6. use Kunstmaan\NodeBundle\Event\AdaptFormEvent;
  7. use Kunstmaan\PagePartBundle\Helper\FormWidgets\PagePartWidget;
  8. use Kunstmaan\PagePartBundle\Helper\FormWidgets\PageTemplateWidget;
  9. use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface;
  10. use Kunstmaan\PagePartBundle\Helper\HasPageTemplateInterface;
  11. use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminFactory;
  12. use Kunstmaan\PagePartBundle\PagePartConfigurationReader\PagePartConfigurationReaderInterface;
  13. use Kunstmaan\PagePartBundle\PageTemplate\PageTemplateConfigurationReaderInterface;
  14. use Kunstmaan\PagePartBundle\PageTemplate\PageTemplateConfigurationService;
  15. /**
  16.  * NodeListener
  17.  */
  18. class NodeListener
  19. {
  20.     /**
  21.      * @var EntityManagerInterface
  22.      */
  23.     private $em;
  24.     /**
  25.      * @var PagePartAdminFactory
  26.      */
  27.     private $pagePartAdminFactory;
  28.     /**
  29.      * @var PageTemplateConfigurationReaderInterface
  30.      */
  31.     private $templateReader;
  32.     /**
  33.      * @var PagePartConfigurationReaderInterface
  34.      */
  35.     private $pagePartReader;
  36.     /**
  37.      * @var PageTemplateConfigurationService
  38.      */
  39.     private $pageTemplateConfiguratiorService;
  40.     public function __construct(
  41.         EntityManagerInterface $em,
  42.         PagePartAdminFactory $pagePartAdminFactory,
  43.         PageTemplateConfigurationReaderInterface $templateReader,
  44.         PagePartConfigurationReaderInterface $pagePartReader,
  45.         PageTemplateConfigurationService $pageTemplateConfiguratiorService
  46.     ) {
  47.         $this->em $em;
  48.         $this->pagePartAdminFactory $pagePartAdminFactory;
  49.         $this->templateReader $templateReader;
  50.         $this->pagePartReader $pagePartReader;
  51.         $this->pageTemplateConfiguratiorService $pageTemplateConfiguratiorService;
  52.     }
  53.     /**
  54.      * @param AdaptFormEvent $event
  55.      */
  56.     public function adaptForm(AdaptFormEvent $event)
  57.     {
  58.         $page $event->getPage();
  59.         $tabPane $event->getTabPane();
  60.         if ($page instanceof HasPageTemplateInterface) {
  61.             $pageTemplateWidget = new PageTemplateWidget($page$event->getRequest(), $this->em$this->pagePartAdminFactory$this->templateReader$this->pagePartReader$this->pageTemplateConfiguratiorService);
  62.             /* @var Tab $propertiesTab */
  63.             $propertiesTab $tabPane->getTabByTitle('kuma_node.tab.properties.title');
  64.             if (!\is_null($propertiesTab)) {
  65.                 $propertiesWidget $propertiesTab->getWidget();
  66.                 $tabPane->removeTab($propertiesTab);
  67.                 $tabPane->addTab(new Tab('kuma_pagepart.tab.content.title', new ListWidget(array($propertiesWidget$pageTemplateWidget))), 0);
  68.             } else {
  69.                 $tabPane->addTab(new Tab('kuma_pagepart.tab.content.title'$pageTemplateWidget), 0);
  70.             }
  71.         } elseif ($page instanceof HasPagePartsInterface) {
  72.             /* @var HasPagePartsInterface $page */
  73.             $pagePartAdminConfigurators $this->pagePartReader->getPagePartAdminConfigurators($page);
  74.             foreach ($pagePartAdminConfigurators as $index => $pagePartAdminConfiguration) {
  75.                 $pagePartWidget = new PagePartWidget($page$event->getRequest(), $this->em$pagePartAdminConfiguration$this->pagePartAdminFactory);
  76.                 if ($index == 0) {
  77.                     /* @var Tab $propertiesTab */
  78.                     $propertiesTab $tabPane->getTabByTitle('kuma_node.tab.properties.title');
  79.                     if (!\is_null($propertiesTab)) {
  80.                         $propertiesWidget $propertiesTab->getWidget();
  81.                         $tabPane->removeTab($propertiesTab);
  82.                         $tabPane->addTab(new Tab($pagePartAdminConfiguration->getName(), new ListWidget(array($propertiesWidget$pagePartWidget))), 0);
  83.                         continue;
  84.                     }
  85.                 }
  86.                 $tabPane->addTab(new Tab($pagePartAdminConfiguration->getName(), $pagePartWidget), \count($tabPane->getTabs()));
  87.             }
  88.         }
  89.     }
  90. }