your box content
* your box content
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-infobox
*/
final class InfoboxViewHelper extends AbstractViewHelper
{
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var bool
*/
protected $escapeOutput = false;
public function __construct(
private readonly IconFactory $iconFactory
) {}
public function initializeArguments(): void
{
$this->registerArgument('message', 'string', 'The message of the info box, if NULL tag content is used');
$this->registerArgument('title', 'string', 'The title of the info box');
$this->registerArgument('state', 'mixed', 'The state of the box, accepts ContextualFeedbackSeverity enum or integer value', false, ContextualFeedbackSeverity::NOTICE);
$this->registerArgument('iconName', 'string', 'Identifier of the icon as registered in the Icon Registry. NULL sets default icon');
$this->registerArgument('disableIcon', 'bool', 'If set to TRUE, the icon is not rendered.', false, false);
}
public function render(): string
{
$title = (string)$this->arguments['title'];
$message = (string)$this->renderChildren();
$state = $this->arguments['state'];
// The state argument accepts both a ContextualFeedbackSeverity enum and a raw integer value
if ($state instanceof ContextualFeedbackSeverity) {
$severity = $state;
} else {
$state = (int)$state;
$severity = ContextualFeedbackSeverity::from($state);
}
$disableIcon = $this->arguments['disableIcon'];
$icon = $this->arguments['iconName'] ?? $severity->getIconIdentifier();
$iconTemplate = '';
if (!$disableIcon) {
$iconTemplate = ''
. '
'
. ''
. $this->iconFactory->getIcon($icon, IconSize::SMALL)->render()
. ''
. '
';
}
$titleTemplate = '';
if ($title !== '') {
$titleTemplate = '' . htmlspecialchars($title) . '
';
}
return ''
. $iconTemplate
. '
'
. $titleTemplate
. '
' . $message . '
'
. '
'
. '
';
}
/**
* Explicitly set argument name to be used as content.
*/
public function getContentArgumentName(): string
{
return 'message';
}
}