diff --git a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php index d325bddca9..aaac39479c 100644 --- a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php +++ b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php @@ -4,6 +4,7 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\QueryBuilder; +use Kunstmaan\AdminBundle\Entity\EntityInterface; use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface; use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper; use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition; @@ -46,6 +47,8 @@ class NodeAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator */ protected $authorizationChecker; + private ?Node $node = null; + /** * @param EntityManager $em The entity * manager @@ -54,7 +57,7 @@ class NodeAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator * locale * @param string $permission The permission */ - public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $permission, AuthorizationCheckerInterface $authorizationChecker) + public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $permission, AuthorizationCheckerInterface $authorizationChecker, ?Node $node = null) { parent::__construct($em, $aclHelper); $this->locale = $locale; @@ -66,6 +69,7 @@ public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $p 'n' ) ); + $this->node = $node; } public function setDomainConfiguration(DomainConfigurationInterface $domainConfiguration) @@ -111,6 +115,39 @@ public function buildListActions() ); } + public function buildItemActions(): void + { + $locale = $this->locale; + $acl = $this->authorizationChecker; + + $itemRoute = function (EntityInterface $item) use ($locale, $acl) { + if ($acl->isGranted(PermissionMap::PERMISSION_VIEW, $item->getNode())) { + return [ + 'path' => '_slug_preview', + 'params' => ['_locale' => $locale, 'url' => $item->getUrl()], + ]; + } + }; + $this->addSimpleItemAction('action.preview', $itemRoute, 'eye'); + + $nodeItemsRoute = function (EntityInterface $item) use ($acl) { + $node = $item->getNode(); + if (!$acl->isGranted(PermissionMap::PERMISSION_VIEW, $node)) { + return null; + } + + if ($node->getChildren()->count() === 0) { + return null; + } + + return [ + 'path' => 'KunstmaanNodeBundle_nodes_items', + 'params' => ['nodeId' => $node->getId()], + ]; + }; + $this->addSimpleItemAction('action.list_nodes', $nodeItemsRoute, 'th-list'); + } + /** * Configure filters */ @@ -243,6 +280,11 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder) ->addOrderBy('b.updated', 'DESC') ->setParameter('lang', $this->locale); + if ($this->node instanceof Node) { + $queryBuilder->andWhere('n.parent = :parent') + ->setParameter('parent', $this->node->getId()); + } + if (!$this->domainConfiguration) { return; } diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php index 640b24f26e..6d3d322d0b 100644 --- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php +++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php @@ -5,9 +5,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; -use InvalidArgumentException; use Kunstmaan\AdminBundle\Entity\BaseUser; -use Kunstmaan\AdminBundle\Entity\EntityInterface; use Kunstmaan\AdminBundle\FlashMessages\FlashTypes; use Kunstmaan\AdminBundle\Helper\CloneHelper; use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface; @@ -126,26 +124,7 @@ public function indexAction(Request $request): Response { $this->init($request); - $nodeAdminListConfigurator = new NodeAdminListConfigurator( - $this->em, - $this->aclHelper, - $this->locale, - PermissionMap::PERMISSION_VIEW, - $this->authorizationChecker - ); - - $locale = $this->locale; - $acl = $this->authorizationChecker; - $itemRoute = function (EntityInterface $item) use ($locale, $acl) { - if ($acl->isGranted(PermissionMap::PERMISSION_VIEW, $item->getNode())) { - return [ - 'path' => '_slug_preview', - 'params' => ['_locale' => $locale, 'url' => $item->getUrl()], - ]; - } - }; - $nodeAdminListConfigurator->addSimpleItemAction('action.preview', $itemRoute, 'eye'); - $nodeAdminListConfigurator->setDomainConfiguration($this->domainConfiguration); + $nodeAdminListConfigurator = $this->getAdminListConfigurator(); $nodeAdminListConfigurator->setShowAddHomepage($this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN')); /** @var AdminList $adminlist */ @@ -157,6 +136,43 @@ public function indexAction(Request $request): Response ]); } + #[Route(path: '/{nodeId}/items', name: 'KunstmaanNodeBundle_nodes_items')] + public function itemsAction(Request $request, int $nodeId): Response + { + $this->init($request); + + $node = $this->em->getRepository(Node::class)->find($nodeId); + if (!$node) { + throw $this->createNotFoundException(sprintf('No node found for id "%s"', $nodeId)); + } + + $nodeAdminListConfigurator = $this->getAdminListConfigurator($node); + + /** @var AdminList $adminlist */ + $adminlist = $this->container->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator); + $adminlist->bindRequest($request); + + return $this->render('@KunstmaanNode/Admin/list.html.twig', [ + 'adminlist' => $adminlist, + ]); + } + + public function getAdminListConfigurator(?Node $node = null): NodeAdminListConfigurator + { + $nodeAdminListConfigurator = new NodeAdminListConfigurator( + $this->em, + $this->aclHelper, + $this->locale, + PermissionMap::PERMISSION_VIEW, + $this->authorizationChecker, + $node + ); + + $nodeAdminListConfigurator->setDomainConfiguration($this->domainConfiguration); + + return $nodeAdminListConfigurator; + } + /** * @param int $id The node id * diff --git a/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml b/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml index 7dca63cd67..29694ade90 100644 --- a/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml +++ b/src/Kunstmaan/NodeBundle/Resources/translations/messages.en.yml @@ -13,6 +13,7 @@ action: addsubpage: "Add subpage" duplicate: "Duplicate" duplicate_with_children: "Duplicate with sub pages" + list_nodes: "List nodes" modal: sourcelanguage: "Source language"