cObj->stdWrapValue('renderMode', $conf); if ($renderMode === 'inline') { return $this->renderInline($conf); } return $this->renderObject($conf); } protected function renderInline(array $conf): string { $resource = $this->resolveResource($conf); [$width, $height, $isDefaultWidth, $isDefaultHeight] = $this->getDimensions($conf); $content = $svgContent = ''; if ($resource instanceof SystemResourceInterface) { try { $svgContent = $resource->getContents(); } catch (SystemResourceDoesNotExistException) { } } if ($svgContent !== '') { try { $document = $this->svgDocumentFactory->fromStringAndSanitize($svgContent); if (!$isDefaultWidth) { $document->documentElement->setAttribute('width', (string)$width); } if (!$isDefaultHeight) { $document->documentElement->setAttribute('height', (string)$height); } $content = $this->svgDocumentService->toInlineMarkup($document); } catch (InvalidSvgException) { $content = ''; } } else { $value = $this->cObj->stdWrapValue('value', $conf); if (!empty($value)) { $content = []; $content[] = ''; $content[] = $value; $content[] = ''; $content = implode(LF, $content); } } if (isset($conf['stdWrap.'])) { $content = $this->cObj->stdWrap($content, $conf['stdWrap.']); } return $content; } /** * Render the SVG as tag */ protected function renderObject(array $conf): string { $resource = $this->resolveResource($conf); [$width, $height] = $this->getDimensions($conf); $content = []; if ($resource !== null) { $uri = $this->resourcePublisher->generateUri($resource, $this->request); $content[] = ''; $content[] = ''; $content[] = ' '; $content[] = ''; $content[] = ''; } $content = implode(LF, $content); if (isset($conf['stdWrap.'])) { $content = $this->cObj->stdWrap($content, $conf['stdWrap.']); } return $content; } protected function resolveResource(array $conf): ?PublicResourceInterface { try { $resourceIdentifier = (string)$this->cObj->stdWrapValue('src', $conf); return $this->resourceFactory->createPublicResource($resourceIdentifier); } catch (SystemResourceException) { return null; } } protected function getDimensions(array $conf): array { $isDefaultWidth = false; $isDefaultHeight = false; $width = $this->cObj->stdWrapValue('width', $conf); $height = $this->cObj->stdWrapValue('height', $conf); if (empty($width)) { $isDefaultWidth = true; $width = 600; } if (empty($height)) { $isDefaultHeight = true; $height = 400; } return [$width, $height, $isDefaultWidth, $isDefaultHeight]; } }