first commit

This commit is contained in:
salam committed 2026-10-19 08:18:39 +02:00
commit 1218dd1517
12716 files changed
+989233

No files matched your search

@@ -0,0 +1,117 @@
<?php
namespace TYPO3\CMS\Backend\ViewHelpers;
/*
* 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!
*/
use TYPO3\CMS\Backend\Backend\Avatar\Avatar;
use TYPO3\CMS\Core\Database\ConnectionPool;
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;
/**
* Render the avatar markup, including the :html:`<img>` tag, for a given backend user.
*
* Examples
* ========
*
* Default
* -------
*
* ::
*
* <be:avatar backendUser="{user.uid}" size="32" showIcon="true" />
*
* Output::
*
* <span class="avatar">
* <span class="avatar-image">
* <img src="/typo3/sysext/core/Resources/Public/Icons/T3Icons/avatar/avatar-default.svg" width="32" height="32" />
* </span>
* </span>
*
* If the given backend user hasn't added a custom avatar yet, a default one is used.
*
* Inline notation
* ---------------
*
* ::
*
* {be:avatar(backendUser: user.id, size: 32, showIcon: 'true')}
*
* Output::
*
* <span class="avatar">
* <span class="avatar-image">
* <img src="/fileadmin/_processed_/7/9/csm_custom-avatar_4ea4a18f58.jpg" width="32" height="32" />
* </span>
* </span>
*/
class AvatarViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var bool
*/
protected $escapeOutput = false;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
$this->registerArgument('backendUser', 'int', 'uid of the backend user', false, 0);
$this->registerArgument('size', 'int', 'width and height of the image', false, 32);
$this->registerArgument('showIcon', 'bool', 'show the record icon as well', false, false);
}
/**
* Resolve user avatar from a given backend user id.
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
if ($arguments['backendUser'] > 0) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
$queryBuilder->getRestrictions()->removeAll();
$backendUser = $queryBuilder
->select('*')
->from('be_users')
->where(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($arguments['backendUser'], \PDO::PARAM_INT)
)
)
->execute()
->fetch();
} else {
$backendUser = $GLOBALS['BE_USER']->user;
}
if ($backendUser === false) {
// no BE user can be retrieved from DB, probably deleted
return '';
}
$avatar = GeneralUtility::makeInstance(Avatar::class);
return $avatar->render($backendUser, $arguments['size'], $arguments['showIcon']);
}
}
@@ -0,0 +1,86 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\Link;
/*
* 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!
*/
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* Use this ViewHelper to provide edit links to records. The ViewHelper will
* pass the uid and table to FormEngine.
*
* The uid must be given as a positive integer.
* For new records, use the :ref:`<be:link.newRecordViewHelper> <typo3-backend-link-newrecord>`.
*
* Examples
* ========
*
* Link to the record-edit action passed to FormEngine::
*
* <be:link.editRecord uid="42" table="a_table" returnUrl="foo/bar" />
*
* Output::
*
* <a href="/typo3/index.php?route=/record/edit&edit[a_table][42]=edit&returnUrl=foo/bar">
* Edit record
* </a>
*
* Link to edit page uid=3 and then return back to the BE module "web_MyextensionList"::
*
* <be:link.editRecord uid="3" table="pages" returnUrl="{f:be.uri(route: 'web_MyextensionList')}">
*/
class EditRecordViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'a';
public function initializeArguments()
{
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerArgument('uid', 'int', 'uid of record to be edited', true);
$this->registerArgument('table', 'string', 'target database table', true);
$this->registerArgument('returnUrl', 'string', 'return to this URL after closing the edit dialog', false, '');
}
/**
* @return string
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
*/
public function render(): string
{
if ($this->arguments['uid'] < 1) {
throw new \InvalidArgumentException('Uid must be a positive integer, ' . $this->arguments['uid'] . ' given.', 1526127158);
}
if (empty($this->arguments['returnUrl'])) {
$this->arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
}
$params = [
'edit' => [$this->arguments['table'] => [$this->arguments['uid'] => 'edit']],
'returnUrl' => $this->arguments['returnUrl']
];
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uri = (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
$this->tag->addAttribute('href', $uri);
$this->tag->setContent($this->renderChildren());
$this->tag->forceClosingTag(true);
return $this->tag->render();
}
}
@@ -0,0 +1,124 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\Link;
/*
* 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!
*/
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* Use this ViewHelper to provide 'create new record' links.
* The ViewHelper will pass the command to FormEngine.
*
* The table argument is mandatory, it decides what record is to be created.
*
* The pid argument will put the new record on this page, if ``0`` given it will
* be placed to the root page.
*
* The uid argument accepts only negative values. If this is given, the new
* record will be placed (by sorting field) behind the record with the uid.
* It will end up on the same pid as this given record, so the pid must not
* be given explicitly by pid argument.
*
* An exception will be thrown, if both uid and pid are given.
* An exception will be thrown, if the uid argument is not a negative integer.
*
* To edit records, use the :ref:`<be:link.editRecordViewHelper> <typo3-backend-link-editrecord>`.
*
* Examples
* ========
*
* Link to create a new record of a_table after record 17 on the same pid::
*
* <be:link.newRecord table="a_table" returnUrl="foo/bar" uid="-17"/>
*
* Output::
*
* <a href="/typo3/index.php?route=/record/edit&edit[a_table][-17]=new&returnUrl=foo/bar">
* Edit record
* </a>
*
* Link to create a new record of a_table on root page::
*
* <be:link.newRecord table="a_table" returnUrl="foo/bar""/>
*
* Output::
*
* <a href="/typo3/index.php?route=/record/edit&edit[a_table][]=new&returnUrl=foo/bar">
* Edit record
* </a>
*
* Link to create a new record of a_table on page 17::
*
* <be:link.newRecord table="a_table" returnUrl="foo/bar" pid="17"/>
*
* Output::
*
* <a href="/typo3/index.php?route=/record/edit&edit[a_table][-17]=new&returnUrl=foo/bar">
* Edit record
* </a>
*
* Link to create a new record then return back to the BE module "web_MyextensionList"::
*
* <be:link.newRecord table="a_table" returnUrl="{f:be.uri(route: 'web_MyextensionList')}" pid="17">
*/
class NewRecordViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'a';
public function initializeArguments()
{
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerArgument('uid', 'int', 'uid < 0 will insert the record after the given uid', false);
$this->registerArgument('pid', 'int', 'the page id where the record will be created', false);
$this->registerArgument('table', 'string', 'target database table', true);
$this->registerArgument('returnUrl', 'string', 'return to this URL after closing the edit dialog', false, '');
}
/**
* @return string
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
*/
public function render(): string
{
if ($this->arguments['uid'] && $this->arguments['pid']) {
throw new \InvalidArgumentException('Can\'t handle both uid and pid for new records', 1526129969);
}
if (isset($this->arguments['uid']) && $this->arguments['uid'] >= 0) {
throw new \InvalidArgumentException('Uid must be negative integer, ' . $this->arguments['uid'] . ' given', 1526134901);
}
if (empty($this->arguments['returnUrl'])) {
$this->arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
}
$params = [
'edit' => [$this->arguments['table'] => [$this->arguments['uid'] ?? $this->arguments['pid'] ?? 0 => 'new']],
'returnUrl' => $this->arguments['returnUrl']
];
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uri = (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
$this->tag->addAttribute('href', $uri);
$this->tag->setContent($this->renderChildren());
$this->tag->forceClosingTag(true);
return $this->tag->render();
}
}
@@ -0,0 +1,100 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button;
/*
* 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!
*/
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 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;
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 {
$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']);
}
/** @var ModuleTemplate $moduleTemplate */
$moduleTemplate = $renderingContext->getViewHelperVariableContainer()->get(ModuleLayoutViewHelper::class, ModuleTemplate::class);
$button->setIcon($moduleTemplate->getIconFactory()->getIcon($arguments['icon'], Icon::SIZE_SMALL));
}
}
@@ -0,0 +1,56 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button;
/*
* 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!
*/
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>
*/
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']);
}
}
@@ -0,0 +1,71 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button;
/*
* 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!
*/
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\Object\ObjectManager;
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>`.
*
* Examples
* --------
*
* Default::
*
* <be:moduleLayout>
* <be:moduleLayout.button.shortcutButton displayName="Shortcut label" />
* </be:moduleLayout>
*/
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');
$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->getControllerContext()->getRequest();
$extensionName = $currentRequest->getControllerExtensionName();
$moduleName = $currentRequest->getPluginName();
$argumentPrefix = GeneralUtility::makeInstance(ObjectManager::class)
->get(ExtensionService::class)
->getPluginNamespace($extensionName, $moduleName);
$getVars = $arguments['getVars'];
$getVars[] = $argumentPrefix;
$shortcutButton = $buttonBar->makeShortcutButton()
->setDisplayName($arguments['displayName'])
->setGetVariables($getVars)
->setModuleName($moduleName);
return $shortcutButton;
}
}
@@ -0,0 +1,101 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\ModuleLayout;
/*
* 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!
*/
use TYPO3\CMS\Backend\Template\Components\Menu\Menu;
use TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper;
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;
/**
* 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>
*/
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
) {
$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(self::isCurrentUri($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);
}
}
/**
* @param string $uri
* @return bool
*/
protected static function isCurrentUri(string $uri): bool
{
return GeneralUtility::getIndpEnv('REQUEST_URI') === $uri;
}
}
@@ -0,0 +1,96 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\ModuleLayout;
/*
* 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!
*/
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>
*/
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
) {
$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);
}
}
}
@@ -0,0 +1,73 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers;
/*
* 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!
*/
use TYPO3\CMS\Backend\Template\ModuleTemplate;
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\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 -->
*/
class ModuleLayoutViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
if ($viewHelperVariableContainer->exists(self::class, ModuleTemplate::class)) {
throw new Exception('ModuleLayoutViewHelper can only be used once per module.', 1483292643);
}
$moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$moduleTemplate->setFlashMessageQueue($renderingContext->getControllerContext()->getFlashMessageQueue());
$viewHelperVariableContainer->add(self::class, ModuleTemplate::class, $moduleTemplate);
$moduleTemplate->setContent($renderChildrenClosure());
$viewHelperVariableContainer->remove(self::class, ModuleTemplate::class);
return $moduleTemplate->renderContent();
}
}
@@ -0,0 +1,79 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers;
/*
* 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!
*/
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\ArrayUtility;
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;
/**
* Create internal link within backend.
*
* Examples
* ========
*
* Default::
*
* <form action="{be:moduleLink(route:'pages_new', arguments:'{id:pageUid}')}" method="post">
* <!-- form content -->
* </form>
*
* Output::
*
* <form action="/pages/new" method="post">
* <!-- form content -->
* </form>
*/
class ModuleLinkViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
$this->registerArgument('route', 'string', 'The route to link to', true);
$this->registerArgument('arguments', 'array', 'Additional link arguments', false, []);
$this->registerArgument('query', 'string', 'Additional link arguments as string');
$this->registerArgument('currentUrlParameterName', 'string', 'Add current url as given parameter');
}
/**
* Render module link with arguments
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$parameters = $arguments['arguments'];
if ($arguments['query'] !== null) {
ArrayUtility::mergeRecursiveWithOverrule($parameters, GeneralUtility::explodeUrl2Array($arguments['query']));
}
if ($arguments['currentUrlParameterName'] !== null) {
$parameters[$arguments['currentUrlParameterName']] = GeneralUtility::getIndpEnv('REQUEST_URI');
}
return (string)$uriBuilder->buildUriFromRoute($arguments['route'], $parameters);
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\Uri;
/*
* 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!
*/
use TYPO3\CMS\Backend\Routing\UriBuilder;
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 this ViewHelper to provide edit links (only the uri) to records. The ViewHelper will
* pass the uid and table to FormEngine.
*
* The uid must be given as a positive integer.
* For new records, use the :ref:`<be:uri.newRecord> <typo3-backend-uri-newrecord>`.
*
* Examples
* ========
*
* URI to the record-edit action passed to FormEngine::
*
* <be:uri.editRecord uid="42" table="a_table" returnUrl="foo/bar" />
*
* ``/typo3/index.php?route=/record/edit&edit[a_table][42]=edit&returnUrl=foo/bar``
*/
class EditRecordViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
public function initializeArguments()
{
$this->registerArgument('uid', 'int', 'uid of record to be edited, 0 for creation', true);
$this->registerArgument('table', 'string', 'target database table', true);
$this->registerArgument('returnUrl', 'string', '', false, '');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
if ($arguments['uid'] < 1) {
throw new \InvalidArgumentException('Uid must be a positive integer, ' . $arguments['uid'] . ' given.', 1526128259);
}
if (empty($arguments['returnUrl'])) {
$arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
}
$params = [
'edit' => [$arguments['table'] => [$arguments['uid'] => 'edit']],
'returnUrl' => $arguments['returnUrl']
];
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
return (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
}
}
@@ -0,0 +1,105 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\ViewHelpers\Uri;
/*
* 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!
*/
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Use this ViewHelper to provide 'create new record' links.
* The ViewHelper will pass the command to FormEngine.
*
* The table argument is mandatory, it decides what record is to be created.
*
* The pid argument will put the new record on this page, if ``0`` given it will
* be placed to the root page.
*
* The uid argument accepts only negative values. If this is given, the new
* record will be placed (by sorting field) behind the record with the uid.
* It will end up on the same pid as this given record, so the pid must not
* be given explicitly by pid argument.
*
* An exception will be thrown, if both uid and pid are given.
* An exception will be thrown, if the uid argument is not a negative integer.
*
* To edit records, use the :ref:`<be:uri.editRecord> <typo3-backend-uri-editrecord>`.
*
* Examples
* ========
*
* Uri to create a new record of a_table after record 17 on the same pid::
*
* <be:uri.newRecord table="a_table" returnUrl="foo/bar" uid="-17"/>
*
* ``/typo3/index.php?route=/record/edit&edit[a_table][-17]=new&returnUrl=foo/bar``
*
* Uri to create a new record of a_table on root page::
*
* <be:uri.newRecord table="a_table" returnUrl="foo/bar""/>
*
* ``/typo3/index.php?route=/record/edit&edit[a_table][]=new&returnUrl=foo/bar``
*
* Uri to create a new record of a_table on page 17::
*
* <be:uri.newRecord table="a_table" returnUrl="foo/bar" pid="17"/>
*
* ``/typo3/index.php?route=/record/edit&edit[a_table][-17]=new&returnUrl=foo/bar``
*/
class NewRecordViewHelper extends AbstractTagBasedViewHelper
{
use CompileWithRenderStatic;
public function initializeArguments()
{
$this->registerArgument('uid', 'int', 'uid < 0 will insert the record after the given uid', false);
$this->registerArgument('pid', 'int', 'the page id where the record will be created', false);
$this->registerArgument('table', 'string', 'target database table', true);
$this->registerArgument('returnUrl', 'string', '', false, '');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
if ($arguments['uid'] && $arguments['pid']) {
throw new \InvalidArgumentException('Can\'t handle both uid and pid for new records', 1526136338);
}
if (isset($arguments['uid']) && $arguments['uid'] >= 0) {
throw new \InvalidArgumentException('Uid must be negative integer, ' . $arguments['uid'] . ' given', 1526136362);
}
if (empty($arguments['returnUrl'])) {
$arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
}
$params = [
'edit' => [$arguments['table'] => [$arguments['uid'] ?? $arguments['pid'] ?? 0 => 'new']],
'returnUrl' => $arguments['returnUrl']
];
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
return (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
}
}