Ejemplo n.º 1
0
 /**
  * @param $context
  * @param $key
  *
  * @return mixed
  */
 public function renderPlaceholder($context, $key = 0, $label = false)
 {
     if (isset($context['environment'])) {
         $this->blockEnvironment = $context['environment'];
     }
     $content = '';
     if ($this->blockEnvironment instanceof Environment) {
         /* @var BlockInterface $container */
         if (isset($context['block'])) {
             $container = $context['block'];
             if ($container instanceof CompositeBlock) {
                 $blocks = $this->blockEnvironment->getBlockChildren($container);
             } else {
                 throw new \Exception('Tried to render placeholder in a block which is not a CompositeBlock');
             }
         } else {
             $blocks = $this->blockEnvironment->getRootBlocks();
         }
         foreach ($blocks as $block) {
             if ($block->getPosition() === (int) $key || (int) $key === 0 && $block->getPosition() === 0) {
                 $content .= $this->renderBlock($block);
             }
         }
         if ($this->blockEnvironment->getBlockMode() === 'manage') {
             $content = $this->container->get('templating')->render('OpiferContentBundle:Block/Layout:placeholder.html.twig', ['content' => $content, 'key' => $key, 'id' => isset($container) ? $container->getId() : 0, 'manage_type' => 'placeholder']);
         }
     }
     return $content;
 }