* ```
*
* **Note:** This ViewHelper is experimental!
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-pageinfo
* @todo: Candidate to deprecate? The page info is typically displayed in doc header, done by ModuleTemplate in controllers.
*/
final class PageInfoViewHelper extends AbstractViewHelper
{
/**
* This ViewHelper renders HTML, thus output must not be escaped
*
* @var bool
*/
protected $escapeOutput = false;
public function __construct(
private readonly IconFactory $iconFactory
) {}
public function render(): string
{
$id = 0;
if ($this->renderingContext->hasAttribute(ServerRequestInterface::class)) {
$request = $this->renderingContext->getAttribute(ServerRequestInterface::class);
$id = $request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0;
}
$pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW));
// Add icon with context menu, etc:
if (is_array($pageRecord) && ($pageRecord['uid'] ?? false)) {
// If there IS a real page
$altText = BackendUtility::getRecordIconAltText($pageRecord, 'pages');
$theIcon = '' . $this->iconFactory->getIconForRecord('pages', $pageRecord, IconSize::SMALL)->render() . '';
// Make Icon:
$theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages', $pageRecord['uid']);
// Setting icon with context menu + uid
$theIcon .= ' [PID: ' . $pageRecord['uid'] . ']';
} else {
// On root-level of page tree
// Make Icon
$theIcon = '' . $this->iconFactory->getIcon('apps-pagetree-page-domain', IconSize::SMALL)->render() . '';
if ($GLOBALS['BE_USER']->isAdmin()) {
$theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages');
}
}
return $theIcon;
}
}