first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
+100
@@ -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']);
|
||||
}
|
||||
}
|
||||
+71
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user