private function getTypesDeep($refName, $exclude = []) { foreach ($this->pagesConfiguration->getPossibleChildTypes($refName) as $type) { $type = $type['class']; if (in_array($type, $exclude)) { continue; } (yield $type); $exclude[] = $type; foreach ($this->getTypesDeep($type, $exclude) as $subType) { $exclude[] = $subType; (yield $subType); } } }
/** * @param string $parentPageClass * @param string $childPageClass * @return bool */ private function canHaveChild($parentPageClass, $childPageClass) { $childTypes = $this->pagesConfiguration->getPossibleChildTypes($parentPageClass); foreach ($childTypes as $childType) { if ($childType['class'] == $childPageClass) { return true; } } return false; }
/** * @return ItemInterface */ public function createActionsMenu() { $activeNodeVersion = $this->getActiveNodeVersion(); $menu = $this->factory->createItem('root'); $menu->setChildrenAttribute('class', 'page-main-actions js-auto-collapse-buttons'); $menu->setChildrenAttribute('data-visible-buttons', '3'); if (null === $activeNodeVersion) { $this->dispatcher->dispatch(Events::CONFIGURE_ACTION_MENU, new ConfigureActionMenuEvent($this->factory, $menu, $activeNodeVersion)); return $menu; } $activeNodeTranslation = $activeNodeVersion->getNodeTranslation(); $node = $activeNodeTranslation->getNode(); $queuedNodeTranslationAction = $this->em->getRepository('KunstmaanNodeBundle:QueuedNodeTranslationAction')->findOneBy(array('nodeTranslation' => $activeNodeTranslation)); $isFirst = true; $canEdit = $this->context->isGranted(PermissionMap::PERMISSION_EDIT, $node); $canPublish = $this->context->isGranted(PermissionMap::PERMISSION_PUBLISH, $node); if ($activeNodeVersion->isDraft() && $this->isEditableNode) { if ($canEdit) { $menu->addChild('action.saveasdraft', array('linkAttributes' => array('type' => 'submit', 'class' => 'js-save-btn btn btn--raise-on-hover btn-primary', 'value' => 'save', 'name' => 'save'), 'extras' => array('renderType' => 'button'))); $isFirst = false; } $menu->addChild('action.preview', array('uri' => $this->router->generate('_slug_preview', array('url' => $activeNodeTranslation->getUrl(), 'version' => $activeNodeVersion->getId())), 'linkAttributes' => array('target' => '_blank', 'class' => 'btn btn-default btn--raise-on-hover'))); if (empty($queuedNodeTranslationAction) && $canPublish) { $menu->addChild('action.publish', array('linkAttributes' => array('data-toggle' => 'modal', 'data-target' => '#pub', 'class' => 'btn btn--raise-on-hover' . ($isFirst ? ' btn-primary btn-save' : ' btn-default')))); } } else { if ($canEdit && $canPublish) { $menu->addChild('action.save', array('linkAttributes' => array('type' => 'submit', 'class' => 'js-save-btn btn btn--raise-on-hover btn-primary', 'value' => 'save', 'name' => 'save'), 'extras' => array('renderType' => 'button'))); $isFirst = false; } if ($this->isEditableNode) { $menu->addChild('action.preview', array('uri' => $this->router->generate('_slug_preview', array('url' => $activeNodeTranslation->getUrl())), 'linkAttributes' => array('target' => '_blank', 'class' => 'btn btn-default btn--raise-on-hover'))); if (empty($queuedNodeTranslationAction) && $activeNodeTranslation->isOnline() && $this->context->isGranted(PermissionMap::PERMISSION_UNPUBLISH, $node)) { $menu->addChild('action.unpublish', array('linkAttributes' => array('class' => 'btn btn-default btn--raise-on-hover', 'data-toggle' => 'modal', 'data-keyboard' => 'true', 'data-target' => '#unpub'))); } elseif (empty($queuedNodeTranslationAction) && !$activeNodeTranslation->isOnline() && $canPublish) { $menu->addChild('action.publish', array('linkAttributes' => array('class' => 'btn btn-default btn--raise-on-hover', 'data-toggle' => 'modal', 'data-keyboard' => 'true', 'data-target' => '#pub'))); } if ($canEdit) { $menu->addChild('action.saveasdraft', array('linkAttributes' => array('type' => 'submit', 'class' => 'btn btn--raise-on-hover' . ($isFirst ? ' btn-primary btn-save' : ' btn-default'), 'value' => 'saveasdraft', 'name' => 'saveasdraft'), 'extras' => array('renderType' => 'button'))); } } } if ($this->pagesConfiguration->getPossibleChildTypes($node->getRefEntityName())) { $menu->addChild('action.addsubpage', array('linkAttributes' => array('type' => 'button', 'class' => 'btn btn-default btn--raise-on-hover', 'data-toggle' => 'modal', 'data-keyboard' => 'true', 'data-target' => '#add-subpage-modal'), 'extras' => array('renderType' => 'button'))); } if (null !== $node->getParent() && $canEdit) { $menu->addChild('action.duplicate', array('linkAttributes' => array('type' => 'button', 'class' => 'btn btn-default btn--raise-on-hover', 'data-toggle' => 'modal', 'data-keyboard' => 'true', 'data-target' => '#duplicate-page-modal'), 'extras' => array('renderType' => 'button'))); } if (null !== $node->getParent() && $this->context->isGranted(PermissionMap::PERMISSION_DELETE, $node)) { $menu->addChild('action.delete', array('linkAttributes' => array('type' => 'button', 'class' => 'btn btn-default btn--raise-on-hover', 'onClick' => 'oldEdited = isEdited; isEdited=false', 'data-toggle' => 'modal', 'data-keyboard' => 'true', 'data-target' => '#delete-page-modal'), 'extras' => array('renderType' => 'button'))); } $this->dispatcher->dispatch(Events::CONFIGURE_ACTION_MENU, new ConfigureActionMenuEvent($this->factory, $menu, $activeNodeVersion)); return $menu; }
/** * @param MenuBuilder $menu The menu builder * @param MenuItem[] &$children The children array that may be * adapted * @param NodeMenuItem[] $nodes The nodes * @param MenuItem $parent The parent menu item * @param array $activeNodeIds List with id's of all nodes that * should be expanded in the tree */ private function processNodes(MenuBuilder $menu, array &$children, array $nodes, MenuItem $parent = null, array $activeNodeIds) { foreach ($nodes as $child) { $menuItem = new MenuItem($menu); $refName = $child['ref_entity_name']; $menuItem->setRoute('KunstmaanNodeBundle_nodes_edit')->setRouteparams(array('id' => $child['id']))->setUniqueId('node-' . $child['id'])->setLabel($child['title'])->setParent($parent)->setOffline(!$child['online'] && !$this->pagesConfiguration->isStructureNode($refName))->setRole('page')->setWeight($child['weight'])->addAttributes(['page' => ['class' => $refName, 'children' => $this->pagesConfiguration->getPossibleChildTypes($refName), 'icon' => $this->pagesConfiguration->getIcon($refName)]]); if (in_array($child['id'], $activeNodeIds)) { $menuItem->setActive(true); } $children[] = $menuItem; } }
/** * @return array */ public function getHomepageTypes() { return $this->pagesConfiguration->getHomepageTypes(); }
/** * Returns a list of functions to add to the existing list. * * @return array An array of functions */ public function getFunctions() { return ['get_possible_child_types' => new \Twig_SimpleFunction('get_possible_child_types', function ($ref) { return $this->pagesConfiguration->getPossibleChildTypes($ref); })]; }