vendor/kunstmaan/node-bundle/EventListener/EntityTabListener.php line 45

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\NodeBundle\EventListener;
  3. use Kunstmaan\AdminBundle\Event\AdaptSimpleFormEvent;
  4. use Kunstmaan\AdminBundle\Helper\FormWidgets\FormWidget;
  5. use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\Tab;
  6. use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\TabPane;
  7. use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
  8. use Kunstmaan\NodeBundle\Entity\PageTabInterface;
  9. use Symfony\Component\Form\FormFactoryInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. class EntityTabListener
  13. {
  14.     /**
  15.      * @var Request
  16.      */
  17.     private $request;
  18.     /**
  19.      * @var FormFactoryInterface
  20.      */
  21.     private $formFactory;
  22.     public function __construct(RequestStack $requestStackFormFactoryInterface $formFactory)
  23.     {
  24.         $this->request $requestStack->getCurrentRequest();
  25.         $this->formFactory $formFactory;
  26.     }
  27.     public function addTabs(TabPane $tabPanePageTabInterface $page)
  28.     {
  29.         foreach ($page->getTabs() as $pageTab) {
  30.             $formWidget = new FormWidget();
  31.             $formWidget->addType($pageTab->getInternalName(), $pageTab->getFormTypeClass(), $page);
  32.             $tabPane->addTab(new Tab($pageTab->getTabTitle(), $formWidget), $pageTab->getPosition());
  33.         }
  34.     }
  35.     /**
  36.      * @param AdaptSimpleFormEvent $event
  37.      */
  38.     public function adaptForm(AdaptSimpleFormEvent $event)
  39.     {
  40.         $entity $event->getData();
  41.         $tabPane $event->getTabPane();
  42.         if ($entity instanceof HasNodeInterface) {
  43.             return;
  44.         }
  45.         if ($entity instanceof PageTabInterface === false) {
  46.             return;
  47.         }
  48.         if ($tabPane instanceof TabPane === false) {
  49.             $tabPane = new TabPane('id'$this->request$this->formFactory);
  50.         }
  51.         $this->addTabs($tabPane$entity);
  52.         $tabPane->buildForm();
  53.         $event->setTabPane($tabPane);
  54.     }
  55. }