TYPO3 v15 dev-main snapshot ()

This commit is contained in:
2026-08-10 22:31:20 +02:00
commit c7a46689ff
115 changed files with 11736 additions and 0 deletions
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* The abstract base class for all backend ViewHelpers
* Note: backend ViewHelpers are still experimental!
*
* @deprecated since TYPO3 v15.0, will be removed in TYPO3 v16.0.
*/
abstract class AbstractBackendViewHelper extends AbstractViewHelper
{
/**
* Gets instance of template if exists or create a new one.
* Saves instance in viewHelperVariableContainer
*/
public function getModuleTemplate(): ModuleTemplate
{
trigger_error(
'AbstractBackendViewHelper::getModuleTemplate() has been deprecated in TYPO3 v15.0 and will be removed in v16.0.',
E_USER_DEPRECATED
);
$viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
if ($viewHelperVariableContainer->exists(self::class, 'ModuleTemplate')) {
$moduleTemplate = $viewHelperVariableContainer->get(self::class, 'ModuleTemplate');
} else {
$moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$viewHelperVariableContainer->add(self::class, 'ModuleTemplate', $moduleTemplate);
}
return $moduleTemplate;
}
/**
* Gets instance of PageRenderer if exists or create a new one.
* Saves instance in viewHelperVariableContainer
*/
public function getPageRenderer(): PageRenderer
{
trigger_error(
'AbstractBackendViewHelper::getPageRenderer() has been deprecated in TYPO3 v15.0 and will be removed in v16.0.',
E_USER_DEPRECATED
);
$viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
if ($viewHelperVariableContainer->exists(self::class, 'PageRenderer')) {
$pageRenderer = $viewHelperVariableContainer->get(self::class, 'PageRenderer');
} else {
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$viewHelperVariableContainer->add(self::class, 'PageRenderer', $pageRenderer);
}
return $pageRenderer;
}
}
@@ -0,0 +1,101 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper for rendering a styled content infobox markup.
*
* ```
* <f:be.infobox title="Message title">your box content</f:be.infobox>
* <f:be.infobox title="Error!" state="{f:constant(name: 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::ERROR')}" iconName="check">your box content</f:be.infobox>
* ```
*
* @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 = ''
. '<div class="callout-icon">'
. '<span class="icon-emphasized">'
. $this->iconFactory->getIcon($icon, IconSize::SMALL)->render()
. '</span>'
. '</div>';
}
$titleTemplate = '';
if ($title !== '') {
$titleTemplate = '<div class="callout-title">' . htmlspecialchars($title) . '</div>';
}
return '<div class="callout callout-' . htmlspecialchars($severity->getCssClass()) . '">'
. $iconTemplate
. '<div class="callout-content">'
. $titleTemplate
. '<div class="callout-body">' . $message . '</div>'
. '</div>'
. '</div>';
}
/**
* Explicitly set argument name to be used as content.
*/
public function getContentArgumentName(): string
{
return 'message';
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* ViewHelper for creating URIs to backend modules.
*
* ```
* <f:be.link route="web_ts" parameters="{id: 92}">Go to web_ts</f:be.link>
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-link
*/
final class LinkViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'a';
public function __construct(
private readonly UriBuilder $uriBuilder
) {
parent::__construct();
}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('route', 'string', 'The name of the route', true);
$this->registerArgument('parameters', 'array', 'An array of parameters', false, []);
$this->registerArgument('referenceType', 'string', 'The type of reference to be generated (one of the constants)', false, UriBuilder::ABSOLUTE_PATH);
}
public function render(): string
{
$route = $this->arguments['route'];
$parameters = $this->arguments['parameters'];
$referenceType = $this->arguments['referenceType'];
$uri = $this->uriBuilder->buildUriFromRoute($route, $parameters, $referenceType);
$this->tag->addAttribute('href', (string)$uri);
$this->tag->setContent((string)$this->renderChildren());
$this->tag->forceClosingTag(true);
return $this->tag->render();
}
}
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* ViewHelper which groups options within a `<f:be.menus.actionMenu>` group.
*
* ```
* <f:be.menus.actionMenu>
* <f:be.menus.actionMenuItem label="First Menu" controller="Default" action="index" />
* <f:be.menus.actionMenuItemGroup label="Information">
* <f:be.menus.actionMenuItem label="PHP Information" controller="Information" action="listPhpInfo" />
* <f:be.menus.actionMenuItem label="{f:translate(key:'documentation')}" controller="Information" action="documentation" />
* ...
* </f:be.menus.actionMenuItemGroup>
* </f:be.menus.actionMenu>
* ```
*
* **NOTE**: This ViewHelper is experimental and tailored to be used only in extbase context.
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-menus-actionmenuitemgroup
*/
final class ActionMenuItemGroupViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'optgroup';
public function initializeArguments(): void
{
parent::initializeArguments();
// @todo: deprecate
$this->registerArgument('defaultController', 'string', 'Unused');
$this->registerArgument('label', 'string', 'The label of the option group', false, '');
}
public function render(): string
{
$this->tag->addAttribute('label', $this->arguments['label']);
$options = '';
foreach ($this->viewHelperNode->getChildNodes() as $childNode) {
if ($childNode instanceof ViewHelperNode) {
$options .= $childNode->evaluate($this->renderingContext);
}
}
$this->tag->setContent($options);
return $this->tag->render();
}
}
@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* ViewHelper which returns an option tag within a `<f:be.menus.actionMenu>` group.
*
* ```
* <f:be.menus.actionMenu>
* <f:be.menus.actionMenuItem label="First Menu" controller="Default" action="index" />
* <f:be.menus.actionMenuItemGroup label="Information">
* <f:be.menus.actionMenuItem label="PHP Information" controller="Information" action="listPhpInfo" />
* <f:be.menus.actionMenuItem label="{f:translate(key:'documentation')}" controller="Information" action="documentation" />
* ...
* </f:be.menus.actionMenuItemGroup>
* </f:be.menus.actionMenu>
* ```
*
* **Note:** This ViewHelper is experimental and tailored to be used only in extbase context.
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-menus-actionmenuitem
*/
final class ActionMenuItemViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'option';
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('label', 'string', 'label of the option tag', true);
$this->registerArgument('controller', 'string', 'controller to be associated with this ActionMenuItem', true);
$this->registerArgument('action', 'string', 'the action to be associated with this ActionMenuItem', true);
$this->registerArgument('arguments', 'array', 'additional controller arguments to be passed to the action when this ActionMenuItem is selected', false, []);
}
public function render(): string
{
$label = $this->arguments['label'];
$controller = $this->arguments['controller'];
$action = $this->arguments['action'];
$arguments = $this->arguments['arguments'];
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
if (!$this->renderingContext->hasAttribute(ServerRequestInterface::class)
|| !$this->renderingContext->getAttribute(ServerRequestInterface::class) instanceof RequestInterface) {
// Throw if not an extbase request
throw new \RuntimeException(
'ViewHelper f:be.menus.actionMenuItem needs an extbase Request object to create URIs.',
1639741792
);
}
/** @var RequestInterface $request */
$request = $this->renderingContext->getAttribute(ServerRequestInterface::class);
$uriBuilder->setRequest($request);
$uri = $uriBuilder->reset()->uriFor($action, $arguments, $controller);
$this->tag->addAttribute('value', $uri);
if (!$this->tag->hasAttribute('selected')) {
$this->evaluateSelectItemState($controller, $action, $arguments);
}
$this->tag->setContent(htmlspecialchars($label, ENT_QUOTES, '', true));
return $this->tag->render();
}
private function evaluateSelectItemState(string $controller, string $action, array $arguments): void
{
/** @var RequestInterface $request */
$request = $this->renderingContext->getAttribute(ServerRequestInterface::class);
$flatRequestArguments = ArrayUtility::flattenPlain(
array_merge([
'controller' => $request->getControllerName(),
'action' => $request->getControllerActionName(),
], $request->getArguments())
);
$flatViewHelperArguments = ArrayUtility::flattenPlain(
array_merge(['controller' => $controller, 'action' => $action], $arguments)
);
if (
($this->arguments['selected'] ?? false)
|| array_diff($flatRequestArguments, $flatViewHelperArguments) === []
) {
$this->tag->addAttribute('selected', 'selected');
}
}
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* ViewHelper which returns a select box that can be used to switch between
* multiple actions and controllers and looks similar to TYPO3s "funcMenu".
*
* ```
* <f:be.menus.actionMenu>
* <f:be.menus.actionMenuItem label="First Menu" controller="Default" action="index" />
* <f:be.menus.actionMenuItemGroup label="Information">
* <f:be.menus.actionMenuItem label="PHP Information" controller="Information" action="listPhpInfo" />
* <f:be.menus.actionMenuItem label="{f:translate(key:'documentation')}" controller="Information" action="documentation" />
* ...
* </f:be.menus.actionMenuItemGroup>
* </f:be.menus.actionMenu>
* ```
*
* **Note:** This ViewHelper is experimental and tailored to be used only in extbase context.
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-menus-actionmenu
*/
final class ActionMenuViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'select';
public function __construct(
private readonly PageRenderer $pageRenderer
) {
parent::__construct();
}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('defaultController', 'string', 'The default controller to be used');
}
public function render(): string
{
$options = '';
foreach ($this->viewHelperNode->getChildNodes() as $childNode) {
if ($childNode instanceof ViewHelperNode) {
$options .= $childNode->evaluate($this->renderingContext);
}
}
$this->tag->addAttributes([
'data-global-event' => 'change',
'data-action-navigate' => '$value',
]);
$this->tag->setContent($options);
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/global-event-handler.js');
return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
}
/**
* @param string $argumentsName
* @param string $closureName
* @param string $initializationPhpCode
*/
public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler): string
{
// @todo: replace with a true compiling method to make compilable!
$compiler->disable();
return '';
}
}
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper which returns the page info icon as known from TYPO3 backend modules.
*
* ```
* <f:be.pageInfo />
* ```
*
* **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 = '<span title="' . $altText . '">' . $this->iconFactory->getIconForRecord('pages', $pageRecord, IconSize::SMALL)->render() . '</span>';
// Make Icon:
$theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages', $pageRecord['uid']);
// Setting icon with context menu + uid
$theIcon .= ' <em>[PID: ' . $pageRecord['uid'] . ']</em>';
} else {
// On root-level of page tree
// Make Icon
$theIcon = '<span title="' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '">' . $this->iconFactory->getIcon('apps-pagetree-page-domain', IconSize::SMALL)->render() . '</span>';
if ($GLOBALS['BE_USER']->isAdmin()) {
$theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages');
}
}
return $theIcon;
}
}
@@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3Fluid\Fluid\Core\Parser\ParsingState;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperNodeInitializedEventInterface;
/**
* ViewHelper which returns the current page path as known from TYPO3 backend modules.
*
* ```
* <f:be.pagePath />
* ```
*
* **Note:** This ViewHelper is experimental!
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-pagepath
* @deprecated since TYPO3 v15.0, will be removed in TYPO3 v16.0.
*/
final class PagePathViewHelper extends AbstractViewHelper implements ViewHelperNodeInitializedEventInterface
{
/**
* This ViewHelper renders HTML, thus output must not be escaped
*
* @var bool
*/
protected $escapeOutput = false;
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));
// Is this a real page
if ($pageRecord['_thePathFull'] ?? false) {
$title = (string)$pageRecord['_thePathFull'];
} else {
$title = (string)$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
}
// Setting the path of the page
$pagePath = htmlspecialchars(self::getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path')) . ': <span class="typo3-docheader-pagePath">';
$croppedTitle = BackendUtility::cropToTitleLength($title, null, true);
if ($croppedTitle !== $title) {
$pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
} else {
$pagePath .= htmlspecialchars($title);
}
$pagePath .= '</span>';
return $pagePath;
}
public static function nodeInitializedEvent(ViewHelperNode $node, array $arguments, ParsingState $parsingState): void
{
trigger_error(
'<f:be.pagePath> has been deprecated in TYPO3 v15.0 and will be removed in v16.0.',
E_USER_DEPRECATED
);
}
private static function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
@@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper to register backend module resources like CSS and JavaScript using the PageRenderer.
*
* ```
* <f:be.pageRenderer
* pageTitle="foo"
* includeCssFiles="{0: 'EXT:my_ext/Resources/Public/Css/Stylesheet.css'}"
* includeJsFiles="{0: 'EXT:my_ext/Resources/Public/JavaScript/Library1.js', 1: 'EXT:my_ext/Resources/Public/JavaScript/Library2.js'}"
* addJsInlineLabels="{'my_ext.label1': 'LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf:label1'}"
* includeJavaScriptModules="{0: '@my-vendor/my-ext/my-module.js'}"
* addInlineSettings="{'some.setting.key': 'some.setting.value'}"
* />
* ```
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-pagerenderer
*/
final class PageRendererViewHelper extends AbstractViewHelper
{
public function __construct(
private readonly PageRenderer $pageRenderer
) {}
public function initializeArguments(): void
{
$this->registerArgument('pageTitle', 'string', 'title tag of the module. Not required by default, as BE modules are shown in a frame', false, '');
$this->registerArgument('includeCssFiles', 'array', 'List of custom CSS file to be loaded');
$this->registerArgument('includeJsFiles', 'array', 'List of custom JavaScript file to be loaded');
$this->registerArgument('addJsInlineLabels', 'array', 'Custom labels to add to JavaScript inline labels');
$this->registerArgument('includeJavaScriptModules', 'array', 'List of JavaScript modules to be loaded');
$this->registerArgument('addInlineSettings', 'array', 'Adds Javascript Inline Setting');
}
public function render(): string
{
$pageTitle = $this->arguments['pageTitle'];
$includeCssFiles = $this->arguments['includeCssFiles'];
$includeJsFiles = $this->arguments['includeJsFiles'];
$addJsInlineLabels = $this->arguments['addJsInlineLabels'];
$includeJavaScriptModules = $this->arguments['includeJavaScriptModules'];
$addInlineSettings = $this->arguments['addInlineSettings'];
if ($pageTitle) {
$this->pageRenderer->setTitle($pageTitle);
}
// Include custom CSS and JS files
if (is_array($includeCssFiles)) {
foreach ($includeCssFiles as $addCssFile) {
$this->pageRenderer->addCssFile($addCssFile);
}
}
if (is_array($includeJsFiles)) {
foreach ($includeJsFiles as $addJsFile) {
$this->pageRenderer->addJsFile($addJsFile);
}
}
if (is_array($includeJavaScriptModules)) {
foreach ($includeJavaScriptModules as $addJavaScriptModule) {
$this->pageRenderer->loadJavaScriptModule($addJavaScriptModule);
}
}
if (is_array($addInlineSettings)) {
$this->pageRenderer->addInlineSettingArray('', $addInlineSettings);
}
// Add inline language labels
if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
if ($this->renderingContext->hasAttribute(ServerRequestInterface::class)
&& $this->renderingContext->getAttribute(ServerRequestInterface::class) instanceof RequestInterface) {
// Extbase request resolves extension key and allows overriding labels using TypoScript configuration.
$extensionKey = $this->renderingContext->getAttribute(ServerRequestInterface::class)->getControllerExtensionKey();
foreach ($addJsInlineLabels as $key) {
$label = LocalizationUtility::translate($key, $extensionKey);
$this->pageRenderer->addInlineLanguageLabel($key, $label);
}
} else {
// No extbase request, labels should follow "LLL:EXT:some_ext/Resources/Private/someFile.xlf:key"
// syntax, and are not overridden by TypoScript extbase module / plugin configuration.
foreach ($addJsInlineLabels as &$labelKey) {
$labelKey = self::getLanguageService()->sL($labelKey);
}
$this->pageRenderer->addInlineLanguageLabelArray($addJsInlineLabels);
}
}
return '';
}
private static function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Security;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* ViewHelper implementing an ifAuthenticated/else condition for backend
* users and backend groups.
*
* ```
* <f:be.security.ifAuthenticated>
* <f:then>
* This is being shown in case you have access.
* </f:then>
* <f:else>
* This is being displayed in case you do not have access.
* </f:else>
* </f:be.security.ifAuthenticated>
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-security-ifauthenticated
*/
final class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
{
public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool
{
return isset($GLOBALS['BE_USER']) && $GLOBALS['BE_USER']->user['uid'] > 0;
}
}
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Security;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* ViewHelper implementing an ifHasRole/else condition for backend users
* and backend groups ("Role").
*
* ```
* <f:be.security.ifHasRole role="Administrator">
* <f:then>
* This is being shown in case you have the role.
* </f:then>
* <f:else>
* This is being displayed in case you do not have the role.
* </f:else>
* </f:be.security.ifHasRole>
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-security-ifhasrole
*/
final class IfHasRoleViewHelper extends AbstractConditionViewHelper
{
/**
* Initializes the "role" argument.
* Renders <f:then> child if the current logged in BE user belongs to the specified role (aka usergroup)
* otherwise renders <f:else> child.
*/
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('role', 'string', 'The usergroup (either the usergroup uid or its title).');
}
public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool
{
$role = $arguments['role'];
if (!is_array($GLOBALS['BE_USER']->userGroups) || $arguments['role'] === null) {
return false;
}
if (is_numeric($role)) {
foreach ($GLOBALS['BE_USER']->userGroups as $userGroup) {
if ((int)$userGroup['uid'] === (int)$role) {
return true;
}
}
} else {
foreach ($GLOBALS['BE_USER']->userGroups as $userGroup) {
if ($userGroup['title'] === $role) {
return true;
}
}
}
return false;
}
}
@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Module\ModuleData;
use TYPO3\CMS\Backend\RecordList\DatabaseRecordList;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper which renders a record list as known from the TYPO3 records module.
*
* ```
* <f:be.tableList tableName="fe_users"
* fieldList="{0: 'name', 1: 'email'}"
* storagePid="1"
* levels="2"
* filter="foo"
* recordsPerPage="10"
* sortField="name"
* sortDescending="true"
* readOnly="true"
* enableClickMenu="false"
* enableControlPanels="true"
* clickTitleMode="info"
* />
* ```
*
* **Note:** This feature is experimental!
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-tablelist
*/
final class TableListViewHelper extends AbstractViewHelper
{
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var bool
*/
protected $escapeOutput = false;
public function __construct(
private readonly ConfigurationManagerInterface $configurationManager,
private readonly PageRenderer $pageRenderer,
) {}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('tableName', 'string', 'name of the database table', true);
$this->registerArgument('fieldList', 'array', 'list of fields to be displayed. If empty, only the title column (configured in $TCA[$tableName][\'ctrl\'][\'title\']) is shown', false, []);
$this->registerArgument('storagePid', 'int', 'by default, records are fetched from the storage PID configured in persistence.storagePid. With this argument, the storage PID can be overwritten');
$this->registerArgument('levels', 'int', 'corresponds to the level selector of the TYPO3 records module. By default only records from the current storagePid are fetched', false, 0);
$this->registerArgument('filter', 'string', 'corresponds to the "Search String" textbox of the TYPO3 records module. If not empty, only records matching the string will be fetched', false, '');
$this->registerArgument('recordsPerPage', 'int', 'amount of records to be displayed at once. Defaults to 100', false, 0);
$this->registerArgument('sortField', 'string', 'table field to sort the results by', false, '');
$this->registerArgument('sortDescending', 'bool', 'if TRUE records will be sorted in descending order', false, false);
$this->registerArgument('readOnly', 'bool', 'if TRUE, the edit icons won\'t be shown. Otherwise edit icons will be shown, if the current BE user has edit rights for the specified table!', false, false);
$this->registerArgument('enableClickMenu', 'bool', 'enables context menu', false, true);
$this->registerArgument('enableControlPanels', 'bool', 'enables control panels', false, false);
$this->registerArgument('clickTitleMode', 'string', 'one of "edit", "show" (only pages, tt_content), "info', false, '');
}
/**
* Renders a record list as known from the TYPO3 records module
* Note: This feature is experimental!
*
* @see DatabaseRecordList
*/
public function render(): string
{
$tableName = $this->arguments['tableName'];
$fieldList = $this->arguments['fieldList'];
$storagePid = $this->arguments['storagePid'];
$levels = $this->arguments['levels'];
$filter = $this->arguments['filter'];
$recordsPerPage = $this->arguments['recordsPerPage'];
$sortField = $this->arguments['sortField'];
$sortDescending = $this->arguments['sortDescending'];
$readOnly = $this->arguments['readOnly'];
$enableClickMenu = $this->arguments['enableClickMenu'];
$clickTitleMode = $this->arguments['clickTitleMode'];
$enableControlPanels = $this->arguments['enableControlPanels'];
$backendUser = $this->getBackendUser();
if (!$this->renderingContext->hasAttribute(ServerRequestInterface::class)) {
// All views in backend have at least ServerRequestInterface. Should be fine
// to assume having a request here, the early return is just sanitation.
return '';
}
$request = $this->renderingContext->getAttribute(ServerRequestInterface::class);
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/recordlist.js');
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/record-download-button.js');
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/action-dispatcher.js');
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/page-wizard/new-page-wizard-button.js');
if ($enableControlPanels === true) {
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/multi-record-selection.js');
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/multi-record-selection-delete-action.js');
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/context-menu.js');
}
$pageId = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
$pointer = (int)($request->getParsedBody()['pointer'] ?? $request->getQueryParams()['pointer'] ?? 0);
$pageInfo = BackendUtility::readPageAccess($pageId, $backendUser->getPagePermsClause(Permission::PAGE_SHOW)) ?: [];
$existingModuleData = $backendUser->getModuleData('records');
$moduleData = new ModuleData('records', is_array($existingModuleData) ? $existingModuleData : []);
$dbList = GeneralUtility::makeInstance(DatabaseRecordList::class);
$dbList->setRequest($request->withoutAttribute('pageContext'));
$dbList->setModuleData($moduleData);
$dbList->pageRow = $pageInfo;
if ($readOnly) {
$dbList->setIsEditable(false);
} else {
$dbList->calcPerms = new Permission($backendUser->calcPerms($pageInfo));
}
$dbList->disableSingleTableView = true;
$dbList->clickTitleMode = $clickTitleMode;
$dbList->clickMenuEnabled = $enableClickMenu;
if ($storagePid === null) {
$frameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$storagePid = $frameworkConfiguration['persistence']['storagePid'];
}
$dbList->start($storagePid, $tableName, $pointer, $filter, $levels, $recordsPerPage);
// Column selector is disabled since fields are defined by the "fieldList" argument
$dbList->displayColumnSelector = false;
$dbList->setFields = [$tableName => $fieldList];
$dbList->noControlPanels = !$enableControlPanels;
$dbList->sortField = $sortField;
$dbList->sortRev = $sortDescending;
return $dbList->generateList();
}
private function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper for creating URIs to backend modules.
*
* ```
* <f:be.uri route="web_ts" parameters="{id: 92}" />
* ```
*
* @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-be-uri
*/
final class UriViewHelper extends AbstractViewHelper
{
public function __construct(
private readonly UriBuilder $uriBuilder
) {}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('route', 'string', 'The name of the route', true);
$this->registerArgument('parameters', 'array', 'An array of parameters', false, []);
$this->registerArgument(
'referenceType',
'string',
'The type of reference to be generated (one of the constants)',
false,
UriBuilder::ABSOLUTE_PATH
);
}
public function render(): string
{
$route = $this->arguments['route'];
$parameters = $this->arguments['parameters'];
$referenceType = $this->arguments['referenceType'];
$uri = $this->uriBuilder->buildUriFromRoute($route, $parameters, $referenceType);
return (string)$uri;
}
}