Commit c08c298b authored by Christian Kuhn's avatar Christian Kuhn Committed by Benni Mack
Browse files

[!!!][TASK] Remove ext:backend ModuleLayout view helpers

Resolves: #96126
Related: #94209
Releases: master
Change-Id: If2edcfdbf6ab2e206c43c634fa58ccf75c75ab38
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72343

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 2a08fd09
<?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\Backend\ViewHelpers\ModuleLayout\Button;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton;
use TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
use TYPO3Fluid\Fluid\View\Exception;
/**
* @deprecated since TYPO3 v11.3, will be removed in TYPO3 v12.0.
*/
abstract class AbstractButtonViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* Initialize arguments.
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments(): void
{
$this->registerArgument('icon', 'string', 'Icon identifier for the button');
$this->registerArgument('title', 'string', 'Title of the button');
$this->registerArgument('disabled', 'bool', 'Whether the button is disabled', false, false);
$this->registerArgument('showLabel', 'bool', 'Defines whether to show the title as a label within the button', false, false);
$this->registerArgument('position', 'string', 'Position of the button (left or right)');
$this->registerArgument('group', 'integer', 'Button group of the button');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @throws \InvalidArgumentException
* @throws \TYPO3Fluid\Fluid\View\Exception
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): void {
trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED);
$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
self::ensureProperNesting($viewHelperVariableContainer);
/** @var ModuleTemplate $moduleTemplate */
$moduleTemplate = $viewHelperVariableContainer->get(ModuleLayoutViewHelper::class, ModuleTemplate::class);
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
$position = $arguments['position'] ?? ButtonBar::BUTTON_POSITION_LEFT;
$group = $arguments['group'] ?? 1;
$button = static::createButton($buttonBar, $arguments, $renderingContext);
if ($button instanceof AbstractButton) {
self::addDefaultAttributes($button, $arguments, $renderingContext);
}
$buttonBar->addButton($button, $position, $group);
}
abstract protected static function createButton(ButtonBar $buttonBar, array $arguments, RenderingContextInterface $renderingContext): ButtonInterface;
/**
* @param ViewHelperVariableContainer $viewHelperVariableContainer
* @throws Exception
*/
private static function ensureProperNesting(ViewHelperVariableContainer $viewHelperVariableContainer): void
{
if (!$viewHelperVariableContainer->exists(ModuleLayoutViewHelper::class, ModuleTemplate::class)) {
throw new Exception(sprintf('%s must be nested in <f.be.moduleLayout> ViewHelper', self::class), 1531216505);
}
}
private static function addDefaultAttributes(AbstractButton $button, array $arguments, RenderingContextInterface $renderingContext): void
{
$button->setShowLabelText($arguments['showLabel']);
if (isset($arguments['title'])) {
$button->setTitle($arguments['title']);
}
$button->setIcon(GeneralUtility::makeInstance(IconFactory::class)->getIcon($arguments['icon'], Icon::SIZE_SMALL));
}
}
<?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\Backend\ViewHelpers\ModuleLayout\Button;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* A ViewHelper for adding a link button to the doc header area.
* It must be a child of :ref:`<be:moduleLayout> <typo3-backend-modulelayout>`.
*
* Examples
* --------
*
* Default::
*
* <be:moduleLayout>
* <be:moduleLayout.button.linkButton
* icon="actions-add"
* title="Add record')}"
* link="{be:uri.newRecord(table: 'tx_my_table')}"
* />
* </be:moduleLayout>
*
* @deprecated since TYPO3 v11.3, will be removed in TYPO3 v12.0. Deprecation logged AbstractButtonViewHelper.
*/
class LinkButtonViewHelper extends AbstractButtonViewHelper
{
/**
* Initialize arguments.
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('link', 'string', 'Link for the button', true);
}
protected static function createButton(ButtonBar $buttonBar, array $arguments, RenderingContextInterface $renderingContext): ButtonInterface
{
return $buttonBar->makeLinkButton()->setHref($arguments['link']);
}
}
<?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\Backend\ViewHelpers\ModuleLayout\Button;
use TYPO3\CMS\Backend\Routing\Router;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* A ViewHelper for adding a shortcut button to the doc header area.
* It must be a child of :ref:`<be:moduleLayout> <typo3-backend-modulelayout>`.
*
* The 'arguments' argument should contain key/value pairs of all arguments
* relevant for the specific view.
*
* Examples
* --------
*
* Default::
*
* <be:moduleLayout>
* <be:moduleLayout.button.shortcutButton displayName="Shortcut label" arguments="{parameter: '{someValue}'}"/>
* </be:moduleLayout>
*
* @deprecated since TYPO3 v11.3, will be removed in TYPO3 v12.0. Deprecation logged AbstractButtonViewHelper.
*/
class ShortcutButtonViewHelper extends AbstractButtonViewHelper
{
/**
* Initialize arguments.
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('displayName', 'string', 'Name for the shortcut', false, '');
$this->registerArgument('arguments', 'array', 'List of relevant GET variables as key/values list to store', false, []);
$this->registerArgument('getVars', 'array', 'List of additional GET variables to store. The current id, module and all module arguments will always be stored', false, []);
}
protected static function createButton(ButtonBar $buttonBar, array $arguments, RenderingContextInterface $renderingContext): ButtonInterface
{
$currentRequest = $renderingContext->getRequest();
$moduleName = $currentRequest->getPluginName();
$displayName = $arguments['displayName'];
// Initialize the shortcut button
$shortcutButton = $buttonBar
->makeShortcutButton()
->setDisplayName($displayName)
->setRouteIdentifier(self::getRouteIdentifierForModuleName($moduleName));
if (!empty($arguments['arguments'])) {
$shortcutButton->setArguments($arguments['arguments']);
} else {
$extensionName = $currentRequest->getControllerExtensionName();
$argumentPrefix = GeneralUtility::makeInstance(ExtensionService::class)
->getPluginNamespace($extensionName, $moduleName);
$getVars = $arguments['getVars'];
$getVars[] = $argumentPrefix;
$shortcutButton->setGetVariables($getVars);
}
return $shortcutButton;
}
/**
* Tries to fetch the route identifier for a given module name
*
* @param string $moduleName
* @return string
*/
protected static function getRouteIdentifierForModuleName(string $moduleName): string
{
foreach (GeneralUtility::makeInstance(Router::class)->getRoutes() as $identifier => $route) {
if ($route->hasOption('moduleName') && $route->getOption('moduleName') === $moduleName) {
return $identifier;
}
}
return '';
}
}
<?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\Backend\ViewHelpers\ModuleLayout;
use TYPO3\CMS\Backend\Template\Components\Menu\Menu;
use TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
use TYPO3Fluid\Fluid\View\Exception;
/**
* A ViewHelper for adding a menu item to a doc header menu.
* It must be a child of :ref:`<be:moduleLayout.menu> <typo3-backend-modulelayout-menu>`.
*
* Examples
* ========
*
* Default::
*
* <be:moduleLayout>
* <be:moduleLayout.menu identifier="MenuIdentifier">
* <be:moduleLayout.menuItem label="Menu item 1" uri="{f:uri.action(action: 'index')}"/>
* </be:moduleLayout.menu>
* </be:moduleLayout>
*
* @deprecated since TYPO3 v11.3, will be removed in TYPO3 v12.0.
*/
class MenuItemViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* Initialize arguments.
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('label', 'string', 'Label of the menu item', true);
$this->registerArgument('uri', 'string', 'Action uri', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @throws Exception
* @throws \InvalidArgumentException
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED);
$request = $renderingContext->getRequest();
$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
self::ensureProperNesting($viewHelperVariableContainer);
/** @var Menu $menu */
$menu = $viewHelperVariableContainer->get(ModuleLayoutViewHelper::class, Menu::class);
$menuItem = $menu->makeMenuItem();
$menuItem->setTitle($arguments['label']);
$menuItem->setHref($arguments['uri']);
$menuItem->setActive($request->getAttribute('normalizedParams')->getRequestUri() === $arguments['uri']);
$menu->addMenuItem($menuItem);
}
/**
* @param ViewHelperVariableContainer $viewHelperVariableContainer
* @throws Exception
*/
private static function ensureProperNesting(ViewHelperVariableContainer $viewHelperVariableContainer): void
{
if (!$viewHelperVariableContainer->exists(ModuleLayoutViewHelper::class, Menu::class)) {
throw new Exception(sprintf('%s must be nested in <f.be.moduleLayout.menu> ViewHelper', self::class), 1531235592);
}
}
}
<?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\Backend\ViewHelpers\ModuleLayout;
use TYPO3\CMS\Backend\Template\Components\Menu\Menu;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
use TYPO3Fluid\Fluid\View\Exception;
/**
* A ViewHelper for adding a menu to the doc header area
* of :ref:`<be:moduleLayout> <typo3-backend-modulelayout>`. It accepts only
* :ref:`<be:moduleLayout.menuItem> <typo3-backend-modulelayout-menuitem>` view
* helpers as children.
*
* Examples
* ========
*
* Default::
*
* <be:moduleLayout>
* <be:moduleLayout.menu identifier="MenuIdentifier">
* <be:moduleLayout.menuItem label="Menu item 1" uri="{f:uri.action(action: 'index')}"/>
* </be:moduleLayout.menu>
* </be:moduleLayout>
*
* @deprecated since TYPO3 v11.3, will be removed in TYPO3 v12.0.
*/
class MenuViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* Initialize arguments.
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments()
{
$this->registerArgument('identifier', 'string', 'Identifier of the menu', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @throws Exception
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED);
$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
self::ensureProperNesting($viewHelperVariableContainer);
/** @var ModuleTemplate $moduleTemplate */
$moduleTemplate = $viewHelperVariableContainer->get(ModuleLayoutViewHelper::class, ModuleTemplate::class);
$menu = $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
$menu->setIdentifier($arguments['identifier']);
$viewHelperVariableContainer->add(ModuleLayoutViewHelper::class, Menu::class, $menu);
$renderChildrenClosure();
$moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
$viewHelperVariableContainer->remove(ModuleLayoutViewHelper::class, Menu::class);
}
/**
* @param ViewHelperVariableContainer $viewHelperVariableContainer
* @throws Exception
*/
private static function ensureProperNesting(ViewHelperVariableContainer $viewHelperVariableContainer): void
{
if (!$viewHelperVariableContainer->exists(ModuleLayoutViewHelper::class, ModuleTemplate::class)) {
throw new Exception(sprintf('%s must be nested in <f.be.moduleLayout> ViewHelper', self::class), 1531235715);
}
if ($viewHelperVariableContainer->exists(ModuleLayoutViewHelper::class, Menu::class)) {
throw new Exception(sprintf('%s can not be nested in <f.be.moduleLayout.menu> ViewHelper', self::class), 1531235777);
}
}
}
<?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\Backend\ViewHelpers;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3Fluid\Fluid\View\Exception;
/**
* A ViewHelper for having properly styled backend modules.
* It is recommended to use it in Fluid Layouts.
* It will render the required HTML for the doc header.
* All module specific output and further configuration of the doc header
* must be rendered as children of this ViewHelper.
*
* Examples
* ========
*
* Default::
*
* <be:moduleLayout>
* <f:render section="content" />
* </be:moduleLayout>
*
* Output::
*
* <!-- HTML of the backend module -->
*
* @deprecated since TYPO3 v11.3, will be removed in TYPO3 v12.0.
*/
class ModuleLayoutViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* Initialize arguments.
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('name', 'string', 'Name of the module, defaults to the current plugin name, if available', false);
$this->registerArgument('title', 'string', 'Title of the module.', false);
}
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED);
$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
if ($viewHelperVariableContainer->exists(self::class, ModuleTemplate::class)) {
throw new Exception('ModuleLayoutViewHelper can only be used once per module.', 1483292643);
}
$extensionService = GeneralUtility::makeInstance(ExtensionService::class);
$pluginNamespace = $extensionService->getPluginNamespace(
$renderingContext->getRequest()->getControllerExtensionName(),
$renderingContext->getRequest()->getPluginName()
);
$flashMessageQueue = GeneralUtility::makeInstance(FlashMessageService::class)
->getMessageQueueByIdentifier('extbase.flashmessages.' . $pluginNamespace);
$moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$moduleTemplate->setFlashMessageQueue($flashMessageQueue);
if (($arguments['name'] ?? null) !== null) {
$moduleTemplate->setModuleName($arguments['name']);
}
if (($arguments['title'] ?? null) !== null) {
$moduleTemplate->setTitle($arguments['title']);
}
$viewHelperVariableContainer->add(self::class, ModuleTemplate::class, $moduleTemplate);
$moduleTemplate->setContent($renderChildrenClosure());
$viewHelperVariableContainer->remove(self::class, ModuleTemplate::class);
return $moduleTemplate->renderContent();
}
}
......@@ -44,7 +44,6 @@ The following PHP static class methods that have previously been marked as depre
The following methods changed signature according to previous deprecations in v11 at the end of the argument list:
- :php:`\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->ATagParams` (argument 2 is removed)
- :php:`\Full\Class\Name->methodName` (argument 42 is now an integer)