Skip to content

Commit

Permalink
Merge pull request #70 from krispypen/feature/pageparts_for_non-nodes
Browse files Browse the repository at this point in the history
pageparts should not depend on HasNodeInterface, but on HasPagePartsInte...
  • Loading branch information
krispypen committed Dec 9, 2014
2 parents 452bbc4 + e1ba74d commit 60e3511
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
7 changes: 4 additions & 3 deletions src/Kunstmaan/NodeBundle/Event/AdaptFormEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +24,7 @@ class AdaptFormEvent extends Event
private $tabPane;

/**
* @var HasNodeInterface
* @var HasPagePartsInterface
*/
private $page;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +91,7 @@ public function getNodeVersion()
}

/**
* @return HasNodeInterface
* @return HasPagePartsInterface
*/
public function getPage()
{
Expand Down
11 changes: 7 additions & 4 deletions src/Kunstmaan/NodeBundle/EventListener/NodeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMapInterface;

use Symfony\Component\Security\Core\SecurityContextInterface;
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;

/**
* NodeListener
Expand Down Expand Up @@ -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)));
}
}
}

}
3 changes: 2 additions & 1 deletion src/Kunstmaan/PagePartBundle/Entity/AbstractPagePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +30,7 @@ public function getAdminView()
*
* @return string
*/
public function getView(PageInterface $page = null)
public function getView(HasPagePartsInterface $page = null)
{
return $this->getDefaultView();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/PagePartBundle/Helper/PagePartInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getAdminView();
* @abstract
* @return string
*/
public function getView(PageInterface $page = null);
public function getView(HasPagePartsInterface $page = null);

/**
* @return AbstractType
Expand Down
22 changes: 12 additions & 10 deletions src/Kunstmaan/SeoBundle/EventListener/NodeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

}

0 comments on commit 60e3511

Please # to comment.