/** * Invoke the given action using the given Request * * @param Request $request * @param string $action */ public function invokeAction(Request $request, $action, $params = array()) { $controllers = $this->getControllers($action, $params, array_merge($request->query->all(), $request->request->all())); foreach ($controllers as $controller) { $this->handler->render($controller); } }
public function esi(ControllerReference $controller) { $controller->attributes = array_map(function ($value) { return $this->getRefId($value, true); }, $controller->attributes); return $this->fragmentHandler->render($controller, 'esi', ['standalone' => true]); }
/** * @param string $place * @param array $attributes * @param array $options * * @return string */ public function widgets($place, array $attributes = [], array $options = []) { $result = ''; foreach ($this->widgets->getWidgetsForPlace($place) as $controller) { $result .= $this->handler->render(new ControllerReference($controller, $attributes, []), 'hinclude', $options); } return $result; }
/** * {@inheritdoc} */ public function execute(BlockContextInterface $blockContext, Response $response = null) { /** @var $block ActionBlock */ $block = $blockContext->getBlock(); if (!$block->getActionName()) { throw new \RuntimeException(sprintf('ActionBlock with id "%s" does not have an action name defined, implement a default or persist it in the document.', $block->getId())); } if (!$block->getEnabled()) { return new Response(); } $requestParams = $block->resolveRequestParams($this->request, $blockContext); return new Response($this->renderer->render(new ControllerReference($block->getActionName(), $requestParams))); }
public function testUnknownFragmentRenderer() { $context = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')->disableOriginalConstructor()->getMock(); $renderer = new FragmentHandler($context); $this->setExpectedException('InvalidArgumentException', 'The "inline" renderer does not exist.'); $renderer->render('/foo'); }
/** * Get the view for the placeholder * * @param array $context Passed automatically, when needs_context is set to TRUE * @param string $key * * @return string */ public function getPlaceholder($context, $key) { if (!array_key_exists('layout', $context)) { return; } $layouts = $context['layout']->getLayoutsAt($key); if (!$layouts) { return; } $content = ''; foreach ($layouts as $sublayout) { $context['layout'] = $sublayout; // If the sublayout has content, replace the context's content with // the sublayout's content if ($sublayout->getContent()) { $layoutContent = $this->contentManager->getRepository()->find($sublayout->getContent()); $context['content'] = $layoutContent; } // If the sublayout has parameters, set the parameter data to the context if ($sublayout->getParameters()) { $context['parameters'] = $sublayout->getParameters(); } // If the sublayout has an action, call the controller action before rendering. // Else, just render the template directly if ($sublayout->getAction()) { $action = new ControllerReference($sublayout->getAction(), $context, []); $content .= $this->fragmentHandler->render($action); } else { $content .= $this->twig->render($sublayout->getFilename(), $context); } } return $content; }
/** * {@inheritdoc} */ public function render($uri, $renderer = 'inline', array $options = array()) { if (isset($this->rendererIds[$renderer])) { $this->addRenderer($this->container->get($this->rendererIds[$renderer])); unset($this->rendererIds[$renderer]); } return parent::render($uri, $renderer, $options); }
/** * {@inheritdoc} */ public function get(array $keys) { $this->validateKeys($keys); $keys['_token'] = $this->computeHash($keys); $controllerReference = new ControllerReference('cmf.block.cache.varnish:cacheAction', $keys); $content = $this->fragmentHandler->render($controllerReference, 'esi'); return new CacheElement($keys, new Response($content)); }
/** * Process embed tags for a single tag type (embed or embed-inline) * @param \DOMDocument $xmlDoc * @param $tagName string name of the tag to extract */ protected function processTag(DOMDocument $xmlDoc, $tagName) { /** @var $embed \DOMElement */ foreach ($xmlDoc->getElementsByTagName($tagName) as $embed) { if (!($view = $embed->getAttribute("view"))) { $view = $tagName; } $embedContent = null; $parameters = $this->getParameters($embed); if ($contentId = $embed->getAttribute("object_id")) { try { /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */ $content = $this->repository->sudo(function (Repository $repository) use($contentId) { return $repository->getContentService()->loadContent($contentId); }); if (!$this->repository->canUser('content', 'read', $content) && !$this->repository->canUser('content', 'view_embed', $content)) { throw new UnauthorizedException('content', 'read', array('contentId' => $contentId)); } // Check published status of the Content if ($content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED && !$this->repository->canUser('content', 'versionread', $content)) { throw new UnauthorizedException('content', 'versionread', array('contentId' => $contentId)); } $embedContent = $this->fragmentHandler->render(new ControllerReference('ez_content:embedContent', array('contentId' => $contentId, 'viewType' => $view, 'layout' => false, 'params' => $parameters))); } catch (APINotFoundException $e) { if ($this->logger) { $this->logger->error("While generating embed for xmltext, could not locate " . "Content object with ID " . $contentId); } } } else { if ($locationId = $embed->getAttribute("node_id")) { try { /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */ $location = $this->repository->sudo(function (Repository $repository) use($locationId) { return $repository->getLocationService()->loadLocation($locationId); }); if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location) && !$this->repository->canUser('content', 'view_embed', $location->getContentInfo(), $location)) { throw new UnauthorizedException('content', 'read', array('locationId' => $location->id)); } $embedContent = $this->fragmentHandler->render(new ControllerReference('ez_content:embedLocation', array('locationId' => $locationId, 'viewType' => $view, 'layout' => false, 'params' => $parameters))); } catch (APINotFoundException $e) { if ($this->logger) { $this->logger->error("While generating embed for xmltext, could not locate " . "Location with ID " . $locationId); } } } } if ($embedContent === null) { // Remove empty embed $embed->parentNode->removeChild($embed); } else { $embed->appendChild($xmlDoc->createCDATASection($embedContent)); } } }
/** * @param \Twig_Environment $env * @param $context * @param TwigTemplateEvent $event * * @return string */ protected function render(\Twig_Environment $env, $context, TwigTemplateEvent $event) { $codes = $event->getCodes(); $compiled = ''; if (count($codes)) { foreach ($codes as $code) { if ($code instanceof TwigEventInclude) { $compiled .= $env->resolveTemplate($code->getTemplate())->render(array_replace_recursive($context, $code->getParameters())); continue; } if ($code instanceof TwigEventString) { $compiled .= $env->render($code->getTemplateString(), array_replace_recursive($context, $code->getParameters())); continue; } if ($code instanceof TwigEventRender) { $reference = new ControllerReference($code->getController(), $code->getAttributes(), $code->getQuery()); $compiled .= $this->fragment->render($reference, $code->getStrategy()); continue; } } } return $compiled; }
/** * @expectedException \InvalidArgumentException */ public function testRenderWhenRendererDoesNotExist() { $handler = new FragmentHandler(); $handler->render('/', 'foo'); }
/** * @expectedException \InvalidArgumentException */ public function testRenderWhenRendererDoesNotExist() { $handler = new FragmentHandler(array(), null, $this->requestStack); $handler->render('/', 'foo'); }
/** * @param BlockInterface $block * * @return null|string */ public function renderEsi(BlockInterface $block) { $reference = new ControllerReference('OpiferContentBundle:Frontend/Block:view', ['id' => $block->getId()], $this->getRequest()->query->all()); return $this->fragmentHandler->render($reference, 'esi'); }
/** * Process embed tags for a single tag type (embed or embed-inline) * @param \DOMDocument $xmlDoc * @param $tagName string name of the tag to extract */ protected function processTag(DOMDocument $xmlDoc, $tagName) { /** @var $embed \DOMElement */ foreach ($xmlDoc->getElementsByTagName($tagName) as $embed) { if (!($view = $embed->getAttribute("view"))) { $view = $tagName; } $embedContent = null; $parameters = array("noLayout" => true, "objectParameters" => array()); foreach ($embed->attributes as $attribute) { // We only consider tags in the custom namespace, and skip disallowed names if (!isset($this->excludedAttributes[$attribute->localName])) { $parameters["objectParameters"][$attribute->localName] = $attribute->nodeValue; } } if ($contentId = $embed->getAttribute("object_id")) { try { /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */ $content = $this->repository->sudo(function (Repository $repository) use($contentId) { return $repository->getContentService()->loadContent($contentId); }); if (!$this->repository->canUser('content', 'read', $content) && !$this->repository->canUser('content', 'view_embed', $content)) { throw new UnauthorizedException('content', 'read', array('contentId' => $contentId)); } // Check published status of the Content if ($content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED && !$this->repository->canUser('content', 'versionread', $content)) { throw new UnauthorizedException('content', 'versionread', array('contentId' => $contentId)); } $embedContent = $this->fragmentHandler->render(new ControllerReference('ez_content:embedContent', array('contentId' => $contentId, 'viewType' => $view, 'layout' => false, 'params' => $parameters))); } catch (APINotFoundException $e) { if ($this->logger) { $this->logger->error("While generating embed for xmltext, could not locate " . "Content object with ID " . $contentId); } } } else { if ($locationId = $embed->getAttribute("node_id")) { try { /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */ $location = $this->repository->sudo(function (Repository $repository) use($locationId) { return $repository->getLocationService()->loadLocation($locationId); }); if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location) && !$this->repository->canUser('content', 'view_embed', $location->getContentInfo(), $location)) { throw new UnauthorizedException('content', 'read', array('locationId' => $location->id)); } $embedContent = $this->fragmentHandler->render(new ControllerReference('ez_content:embedLocation', array('locationId' => $locationId, 'viewType' => $view, 'layout' => false, 'params' => $parameters))); } catch (APINotFoundException $e) { if ($this->logger) { $this->logger->error("While generating embed for xmltext, could not locate " . "Location with ID " . $locationId); } } } } if ($embedContent === null) { // Remove tmp paragraph if ($embed->parentNode->lookupNamespaceUri('tmp') !== null) { $embed->parentNode->parentNode->removeChild($embed->parentNode); } else { if ($embed->parentNode->localName === "link" && $embed->parentNode->childNodes->length === 1) { // Remove paragraph with empty link if ($embed->parentNode->parentNode->localName === "paragraph" && $embed->parentNode->parentNode->childNodes->length === 1) { $embed->parentNode->parentNode->parentNode->removeChild($embed->parentNode->parentNode); } else { $embed->parentNode->parentNode->removeChild($embed->parentNode); } } else { $embed->parentNode->removeChild($embed); } } } else { $embed->appendChild($xmlDoc->createCDATASection($embedContent)); } } }
/** * Renders an action * * @param string|ControllerReference $uri * * @return string */ public function render($uri) { return $this->handler->render($uri); }