From e1ba74dacbc0a0e74323320efda5576a94e687bb Mon Sep 17 00:00:00 2001 From: Kris Pypen Date: Mon, 8 Dec 2014 14:35:59 +0100 Subject: [PATCH] pageparts should not depend on HasNodeInterface, but on HasPagePartsInterface. Now you can use pageparts (frontend and backend) also for non-node entities --- .../NodeBundle/Event/AdaptFormEvent.php | 7 +++--- .../NodeBundle/EventListener/NodeListener.php | 11 ++++++---- .../Entity/AbstractPagePart.php | 3 ++- .../Helper/FormWidgets/PagePartWidget.php | 3 ++- .../Helper/PagePartInterface.php | 2 +- .../SeoBundle/EventListener/NodeListener.php | 22 ++++++++++--------- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Event/AdaptFormEvent.php b/src/Kunstmaan/NodeBundle/Event/AdaptFormEvent.php index 478685d7b5..6a8ae52c29 100644 --- a/src/Kunstmaan/NodeBundle/Event/AdaptFormEvent.php +++ b/src/Kunstmaan/NodeBundle/Event/AdaptFormEvent.php @@ -10,6 +10,7 @@ use Kunstmaan\NodeBundle\Entity\HasNodeInterface; use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\TabPane; use Symfony\Component\HttpFoundation\Request; +use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface; /** * The event to pass metadata if the adaptForm event is triggered @@ -23,7 +24,7 @@ class AdaptFormEvent extends Event private $tabPane; /** - * @var HasNodeInterface + * @var HasPagePartsInterface */ private $page; @@ -55,7 +56,7 @@ class AdaptFormEvent extends Event * @param NodeTranslation $nodeTranslation The node translation * @param NodeVersion $nodeVersion The node version */ - public function __construct(Request $request, TabPane $tabPane, HasNodeInterface $page, Node $node, NodeTranslation $nodeTranslation, NodeVersion $nodeVersion) + public function __construct(Request $request, TabPane $tabPane, HasPagePartsInterface $page = null, Node $node = null, NodeTranslation $nodeTranslation = null, NodeVersion $nodeVersion = null) { $this->request = $request; $this->tabPane = $tabPane; @@ -90,7 +91,7 @@ public function getNodeVersion() } /** - * @return HasNodeInterface + * @return HasPagePartsInterface */ public function getPage() { diff --git a/src/Kunstmaan/NodeBundle/EventListener/NodeListener.php b/src/Kunstmaan/NodeBundle/EventListener/NodeListener.php index e3e6fed8fc..1bd04c6e87 100644 --- a/src/Kunstmaan/NodeBundle/EventListener/NodeListener.php +++ b/src/Kunstmaan/NodeBundle/EventListener/NodeListener.php @@ -9,6 +9,7 @@ use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMapInterface; use Symfony\Component\Security\Core\SecurityContextInterface; +use Kunstmaan\NodeBundle\Entity\HasNodeInterface; /** * NodeListener @@ -48,10 +49,12 @@ public function __construct(SecurityContextInterface $securityContext, Permissio */ public function adaptForm(AdaptFormEvent $event) { - if ($this->securityContext->isGranted('ROLE_PERMISSIONMANAGER')) { - $tabPane = $event->getTabPane(); - $tabPane->addTab(new Tab('Permissions', new PermissionsFormWidget($event->getPage(), $event->getNode(), $this->permissionAdmin, $this->permissionMap))); - } + if($event->getPage() instanceof HasNodeInterface) { + if ($this->securityContext->isGranted('ROLE_PERMISSIONMANAGER')) { + $tabPane = $event->getTabPane(); + $tabPane->addTab(new Tab('Permissions', new PermissionsFormWidget($event->getPage(), $event->getNode(), $this->permissionAdmin, $this->permissionMap))); + } + } } } diff --git a/src/Kunstmaan/PagePartBundle/Entity/AbstractPagePart.php b/src/Kunstmaan/PagePartBundle/Entity/AbstractPagePart.php index bdeaa566d4..bed1671a84 100644 --- a/src/Kunstmaan/PagePartBundle/Entity/AbstractPagePart.php +++ b/src/Kunstmaan/PagePartBundle/Entity/AbstractPagePart.php @@ -5,6 +5,7 @@ use Kunstmaan\PagePartBundle\Helper\PagePartInterface; use Kunstmaan\AdminBundle\Entity\AbstractEntity; use Doctrine\ORM\Mapping as ORM; +use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface; /** * Abstract ORM Pagepart @@ -29,7 +30,7 @@ public function getAdminView() * * @return string */ - public function getView(PageInterface $page = null) + public function getView(HasPagePartsInterface $page = null) { return $this->getDefaultView(); } diff --git a/src/Kunstmaan/PagePartBundle/Helper/FormWidgets/PagePartWidget.php b/src/Kunstmaan/PagePartBundle/Helper/FormWidgets/PagePartWidget.php index acb2834b9f..4c03730651 100644 --- a/src/Kunstmaan/PagePartBundle/Helper/FormWidgets/PagePartWidget.php +++ b/src/Kunstmaan/PagePartBundle/Helper/FormWidgets/PagePartWidget.php @@ -15,6 +15,7 @@ use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdmin; use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminFactory; use Kunstmaan\PagePartBundle\PagePartAdmin\AbstractPagePartAdminConfigurator; +use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface; /** * PagePartWidget @@ -65,7 +66,7 @@ class PagePartWidget extends FormWidget * @param FormFactoryInterface $formFactory The form factory * @param PagePartAdminFactory $pagePartAdminFactory The page part admin factory */ - public function __construct(HasNodeInterface $page, Request $request, EntityManager $em, AbstractPagePartAdminConfigurator $pagePartAdminConfigurator, FormFactoryInterface $formFactory, PagePartAdminFactory $pagePartAdminFactory) + public function __construct(HasPagePartsInterface $page, Request $request, EntityManager $em, AbstractPagePartAdminConfigurator $pagePartAdminConfigurator, FormFactoryInterface $formFactory, PagePartAdminFactory $pagePartAdminFactory) { parent::__construct(); diff --git a/src/Kunstmaan/PagePartBundle/Helper/PagePartInterface.php b/src/Kunstmaan/PagePartBundle/Helper/PagePartInterface.php index 571f7f10ea..35529cb113 100644 --- a/src/Kunstmaan/PagePartBundle/Helper/PagePartInterface.php +++ b/src/Kunstmaan/PagePartBundle/Helper/PagePartInterface.php @@ -30,7 +30,7 @@ public function getAdminView(); * @abstract * @return string */ - public function getView(PageInterface $page = null); + public function getView(HasPagePartsInterface $page = null); /** * @return AbstractType diff --git a/src/Kunstmaan/SeoBundle/EventListener/NodeListener.php b/src/Kunstmaan/SeoBundle/EventListener/NodeListener.php index f60660824d..567d259e6c 100644 --- a/src/Kunstmaan/SeoBundle/EventListener/NodeListener.php +++ b/src/Kunstmaan/SeoBundle/EventListener/NodeListener.php @@ -38,16 +38,18 @@ public function __construct(EntityManager $em) */ public function adaptForm(AdaptFormEvent $event) { - /* @var Seo $seo */ - $seo = $this->em->getRepository('KunstmaanSeoBundle:Seo')->findOrCreateFor($event->getPage()); - - $seoWidget = new FormWidget(); - $seoWidget->addType('seo', new SeoType(), $seo); - $event->getTabPane()->addTab(new Tab('SEO', $seoWidget)); - - $socialWidget = new FormWidget(); - $socialWidget->addType('social', new SocialType(), $seo); - $event->getTabPane()->addTab(new Tab('Social', $socialWidget)); + if($event->getPage() instanceof HasNodeInterface) { + /* @var Seo $seo */ + $seo = $this->em->getRepository('KunstmaanSeoBundle:Seo')->findOrCreateFor($event->getPage()); + + $seoWidget = new FormWidget(); + $seoWidget->addType('seo', new SeoType(), $seo); + $event->getTabPane()->addTab(new Tab('SEO', $seoWidget)); + + $socialWidget = new FormWidget(); + $socialWidget->addType('social', new SocialType(), $seo); + $event->getTabPane()->addTab(new Tab('Social', $socialWidget)); + } } }