eZ\Publish\Core\MVC\Symfony\View\ViewManagerInterface::renderLocation PHP Méthode

renderLocation() public méthode

$content and $location will be injected in the selected template.
public renderLocation ( eZ\Publish\API\Repository\Values\Content\Location $location, string $viewType = self::VIEW_TYPE_FULL, array $parameters = [] ) : string
$location eZ\Publish\API\Repository\Values\Content\Location
$viewType string Variation of display for your content. Default is 'full'.
$parameters array Parameters to pass to the template called to render the view. By default, it's empty. 'location' and 'content' entries are reserved for the Location (and its Content) that is viewed.
Résultat string
    public function renderLocation(Location $location, $viewType = self::VIEW_TYPE_FULL, $parameters = array());

Usage Example

 /**
  * 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")) {
             /** @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');
             }
             // Check published status of the Content
             if ($content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED && !$this->repository->canUser('content', 'versionread', $content)) {
                 throw new UnauthorizedException('content', 'versionread');
             }
             $embedContent = $this->viewManager->renderContent($content, $view, $parameters);
         } else {
             if ($locationId = $embed->getAttribute("node_id")) {
                 /** @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');
                 }
                 $embedContent = $this->viewManager->renderLocation($location, $view, $parameters);
             }
         }
         if ($embedContent !== null) {
             $embed->appendChild($xmlDoc->createCDATASection($embedContent));
         }
     }
 }
All Usage Examples Of eZ\Publish\Core\MVC\Symfony\View\ViewManagerInterface::renderLocation