protected function getBlocksRecursive($owner = null, $blocks = array()) { $draft = $this->draft && ($owner === $this->object || $owner === null) ? true : false; $owned = $this->blockManager->findByOwner($owner, $draft); if ($owned instanceof PersistentCollection) { $owned = $owned->getValues(); } $blocks = array_merge($blocks, $owned); if ($owner instanceof TemplatedInterface && $owner->getTemplate()) { $blocks = $this->getBlocksRecursive($owner->getTemplate(), $blocks); } return $blocks; }
/** * Loads all blocks needed to display the document for caching purposes. This * includes loading blocks that are owned by the Template. * * @return Environment */ protected function loadBlocks() { if ($this->isLoaded) { return; } $blockOwners = $this->getBlockOwners(); $blocks = array(); foreach ($blockOwners as $blockOwner) { $version = $this->getVersion($blockOwner->getId()); $owned = $this->blockManager->findByOwner($blockOwner, $version); $blocks = array_merge($blocks, $owned); } $blocks = $this->blockManager->sortBlocks(array_merge($blocks, $blockOwners)); $cacheKey = $this->getCacheKey(); $this->blockCache[$cacheKey] = array_filter($blocks, function ($item) { return $item instanceof DocumentBlock ? false : true; }); $this->isLoaded = true; return $this; }