Example #1
0
 /**
  * @inheritDoc
  */
 public function configure(ModelInterface $block, array $specs)
 {
     $specs = $this->prepareOptions($specs);
     foreach ($this->getOption('options', $specs) as $name => $option) {
         $block->setOption($name, $option);
     }
     foreach ($this->getOption('variables', $specs) as $name => $variable) {
         $block->setVariable($name, $variable);
     }
     foreach ($this->getOption('actions', $specs) as $params) {
         if (isset($params['method'])) {
             $method = (string) $params['method'];
             if (method_exists($block, $method)) {
                 $this->invokeArgs($block, $method, $params);
             } else {
                 throw new BadMethodCallException(sprintf('Call to undefined block method %s::%s()', get_class($block), $method));
             }
         }
     }
     if (!$block->getTemplate() && ($template = $this->getOption('template', $specs))) {
         $block->setTemplate($template);
     }
     $block->setCaptureTo($this->getOption('capture_to', $specs));
     $block->setAppend($this->getOption('append', $specs));
     $block->setVariable('block', $block);
     if ($block instanceof BlockInterface) {
         $block->setView($this->container->get('ViewRenderer'));
         $block->setRequest($this->container->get('Request'));
     }
     $results = $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, ['block' => $block, 'specs' => $specs], function ($result) {
         return $result instanceof ModelInterface;
     });
     if ($results->stopped()) {
         $block = $results->last();
     }
     return $block;
 }
Example #2
0
 /**
  * @param ModelInterface $block
  * @return mixed|string
  */
 private function determineAnonymousBlockId(ModelInterface $block)
 {
     $blockId = $block->getOption('block_id');
     if (!$blockId) {
         $blockId = sprintf(self::ANONYMOUS_ID_PATTERN, $block->captureTo(), self::$anonymousSuffix++);
         $block->setOption('block_id', $blockId);
     }
     return $blockId;
 }
Example #3
0
 /**
  * assign wrapper template to block
  *
  * @param ModelInterface $block
  * @param array|string $options
  */
 protected function wrapBlock(ModelInterface $block, $options)
 {
     $attributes = $options;
     if (is_string($options)) {
         $wrapperTemplate = $options;
         $attributes = [];
     } elseif (is_array($options) && !isset($options['template'])) {
         $wrapperTemplate = self::WRAPPER_DEFAULT;
     } else {
         $wrapperTemplate = $options['template'];
         unset($attributes['template']);
     }
     if (isset($options['tag'])) {
         $block->setVariable('wrapperTag', $options['tag']);
         unset($attributes['tag']);
     }
     $originalTemplate = $block->getTemplate();
     $block->setOption('is_wrapped', true);
     $block->setTemplate($wrapperTemplate);
     $block->setVariable('wrapperAttributes', $attributes);
     $block->setVariable('originalTemplate', $originalTemplate);
 }