/**
* 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));
}
}
}