/** * Renders a block * * @param BlockManager $blockManager * @param string|null $template * @param bool $included * @param string $extraAttributes * @param array $extraOptions * @throws \Exception * @return string */ public function renderBlock(BlockManager $blockManager, $template = null, $included = false, $extraAttributes = '', array $extraOptions = null) { try { $block = $blockManager->toArray(); if (empty($block)) { return ""; } $templating = $this->container->get('templating'); $slotName = $block["Block"]["SlotName"]; $content = $this->blockContentToHtml($block['Content'], $extraOptions); if (strpos($content, '<script') !== false) { $content = sprintf('<div data-editor="true">%s</div>', $this->translator->translate('twig_extension_script_not_rendered', array(), 'RedKiteCmsBundle')); } if (null === $template) { $template = '_block.html.twig'; } if (!$blockManager->getEditorDisabled() && preg_match('/data\\-editor="true"/s', $content)) { $hideInEditMode = array_key_exists('HideInEditMode', $block) && $block['HideInEditMode'] ? 'true' : 'false'; $editorParameters = $blockManager->editorParameters(); $cmsAttributes = $templating->render('RedKiteCmsBundle:Block:Editor/_editable_block_attributes.html.twig', array('block_id' => $block['Block']["Id"], 'hide_in_edit_mode' => $hideInEditMode, 'slot_name' => $slotName, 'type' => $block['Block']['Type'], 'content' => $content, 'edit_inline' => $block['EditInline'], 'editor' => $editorParameters, 'extra_attributes' => $extraAttributes, 'included' => $included)); if (preg_match('/data\\-encoded\\-content=\'(.*?)\'/s', $cmsAttributes, $matches)) { $cmsAttributes = preg_replace('/data\\-encoded\\-content=\'(.*?)\'/s', 'data-encoded-content=\'' . rawurlencode($matches[1]) . '\'', $cmsAttributes); } $content = preg_replace('/data\\-editor="true"/', $cmsAttributes . ' data-editor="enabled"', $content); } return $templating->render('RedKiteCmsBundle:Slot:Page/' . $template, array('block_id' => $block['Block']["Id"], 'slot_name' => $slotName, 'type' => $block['Block']['Type'], 'content' => $content, 'edit_inline' => $block['EditInline'])); } catch (\Exception $ex) { throw $ex; } }