public function getViewParameters(BlockInterface $block) { $parameters = ['block_service' => $this, 'block' => $block]; $homePage = $this->contentManager->findOneBySlug('index'); $currentPage = $this->contentManager->findOneBySlug($block->getOwner()->getSlug()); //get current page slug to mark it as active when listing $parameters['currentPageSlug'] = $currentPage->getSlug(); $parameters['breadcrumbs'] = $currentPage->getBreadCrumbs(); // add homepage link as first breadcrumb if not exists in breadcrumbs if (!array_key_exists('index', $parameters['breadcrumbs'])) { $parameters['breadcrumbs'] = array_merge(['index' => $homePage->getTitle()], $parameters['breadcrumbs']); } return $parameters; }
public function revertRecursiveFromNode(BlockInterface $block, $rootVersion) { if (!$block->getOwner()) { $this->revert($block, $rootVersion); return $block; } $owner = $block->getOwner(); $this->revert($owner, $rootVersion); $iterator = new \RecursiveIteratorIterator(new RecursiveBlockIterator($owner->getChildren()), \RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $item) { if ($block->getId() == $item->getId()) { return $item; } } throw new \Exception(sprintf('Unable to revert with recursion. Could not find your node %s in the tree anymore', $block)); }
/** * Gets the Block nodes siblings at a version. * * Retrieving siblings from the database could be simple if we did not need to take * the changesets into account, because then we would just get all blocks with the same * parent. However the changesets in BlockLogEntry probably store changed parents and * so they must be applied on the entire tree first before we can tell. * * @param BlockInterface $block * @param integer $version * * @return false|ArrayCollection */ public function getSiblings(BlockInterface $block, $version = false) { $owner = $block->getOwner(); $family = $this->findByOwner($owner, $version); $siblings = array(); foreach ($family as $member) { if ($member->getParent() && $member->getParent()->getId() == $block->getParent()->getId()) { array_push($siblings, $member); } } return $siblings; }