My page description
* My article title
* /path/to/image.jpg
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-page-meta
*/
final class MetaViewHelper extends AbstractViewHelper
{
public function __construct(private readonly MetaTagManagerRegistry $metaTagManagerRegistry) {}
public function initializeArguments(): void
{
$this->registerArgument('property', 'string', 'The meta property name (e.g. "description", "og:title")', true);
$this->registerArgument('type', 'string', 'The meta type attribute (name, property, http-equiv). If not set, the appropriate manager will determine the type.');
$this->registerArgument('subProperties', 'array', 'Array of sub-properties for complex meta tags (e.g. og:image width/height)', false, []);
$this->registerArgument('replace', 'bool', 'Replace existing meta tags with the same property', false, false);
}
public function render(): string
{
$property = $this->arguments['property'];
$content = $this->renderChildren();
if ($content === null || $content === '') {
return '';
}
$metaTagManager = $this->metaTagManagerRegistry->getManagerForProperty($property);
$metaTagManager->addProperty(
$property,
(string)$content,
$this->arguments['subProperties'],
$this->arguments['replace'],
$this->arguments['type'] ?? ''
);
return '';
}
}