/** * applies view helpers * * @todo refactor * @param MvcEvent $e * @return LayoutModifierListener */ public function applyViewHelpers(EventInterface $e) { $viewHelperInstructions = $this->updater->getLayoutStructure()->get(LayoutUpdaterInterface::INSTRUCTION_VIEW_HELPERS); if ($viewHelperInstructions instanceof Config) { $viewHelperInstructions = $viewHelperInstructions->toArray(); } foreach ($this->helperConfig as $helper => $config) { if (!isset($viewHelperInstructions[$helper])) { continue; } $defaultMethod = isset($config['default_method']) ? $config['default_method'] : '__invoke'; $viewHelper = $this->viewHelperManager->get($helper); $viewHelperInstructions[$helper] = (array) $viewHelperInstructions[$helper]; foreach ($viewHelperInstructions[$helper] as $value) { if (!$value) { continue; } $value = (array) $value; $method = $this->getHelperMethod($value, $defaultMethod, $viewHelper); $args = isset($value['args']) ? (array) $value['args'] : array_values($value); $args[0] = $this->prepareHelperValue($args[0], $helper); call_user_func_array([$viewHelper, $method], $args); } } return $this; }
public function testIncludedHandleDoesNotOverride() { $this->updater->setHandles([new Handle('handle/with-include', 10)]); $layoutStructure = $this->updater->getLayoutStructure(); $block = $layoutStructure->blocks->get('do.not.override'); $includedBlock = $layoutStructure->blocks->get('some.included.block'); $this->assertEquals('some/tpl', $includedBlock->get('template')); $this->assertFalse($block->remove); }
/** * set layout template if no template was set e.g. through controller * layout plugin * * @param MvcEvent $e */ public function setLayoutTemplate(MvcEvent $e) { /* @var $layout ModelInterface */ $layout = $e->getViewModel(); $template = $layout->getTemplate(); if ($template === '') { $layoutTemplate = $this->updater->getLayoutStructure()->get(LayoutUpdaterInterface::INSTRUCTION_LAYOUT_TEMPLATE, 'layout/layout'); $layout->setTemplate($layoutTemplate); } }
/** * collect data for zdt * * @param MvcEvent $mvcEvent * @return LayoutCollector */ public function collect(MvcEvent $mvcEvent) { $layout = $mvcEvent->getViewModel(); $blocks = []; foreach ($this->layout->getBlocks() as $blockName => $block) { $blocks[$blockName] = ['template' => $block->getTemplate(), 'capture_to' => $block->captureTo(), 'class' => get_class($block)]; } $data = ['handles' => $this->updater->getHandles(true), 'layout_structure' => $this->updater->getLayoutStructure()->toArray(), 'blocks' => $blocks, 'layout_template' => $layout->getTemplate(), 'current_area' => $this->updater->getArea()]; $this->data = $data; return $this; }
/** * collect data for zdt * * @param MvcEvent $mvcEvent * @return LayoutCollector */ public function collect(MvcEvent $mvcEvent) { $layout = $mvcEvent->getViewModel(); $blocks = []; foreach ($this->layout->getBlocks() as $blockId => $block) { if ($parentBlock = $block->getOption('parent')) { $captureTo = $parentBlock . '::' . $block->captureTo(); } else { $captureTo = $block->captureTo(); } $blocks[$blockId] = ['instance' => $block, 'template' => $this->resolveTemplate($block->getTemplate()), 'capture_to' => $captureTo, 'class' => get_class($block)]; } $data = ['handles' => $this->updater->getHandles(true), 'layout_structure' => $this->updater->getLayoutStructure()->toArray(), 'blocks' => $blocks, 'layout_template' => $layout->getTemplate(), 'current_area' => $this->updater->getArea()]; $this->data = $data; return $this; }
/** * @param array $generators * @return mixed|void */ public function generate(array $generators = []) { $layoutStructure = $this->updater->getLayoutStructure(); foreach ($this->generators as $name => $generator) { if (!$this->isGeneratorLoaded($name) && (empty($generators) || isset($generators[$name]))) { $generator->generate($layoutStructure); $this->loadedGenerators[$name] = true; } } }
/** * removes blocks defined in layout instructions */ protected function removeBlocksByInstructions() { if (!$this->blocksRemoved) { $removedBlocks = $this->updater->getLayoutStructure()->get(LayoutUpdaterInterface::INSTRUCTION_REMOVE_BLOCKS, []); if ($removedBlocks instanceof Config) { $removedBlocks = $removedBlocks->toArray(); foreach ($removedBlocks as $removedBlockId => $value) { if ($value) { $this->removeBlock($removedBlockId); } } } $this->blocksRemoved = true; } }
/** * @inheritDoc */ public function getLayoutStructure() { return $this->updater->getLayoutStructure(); }