Skip to content

Commit

Permalink
[!!!][TASK] Refactor create bookmark handling
Browse files Browse the repository at this point in the history
The backend shortcut / bookmark handlig API was designed to
hand over relevant get/post arguments as key only (eg. 'id').
The underlying code then pulled values from GET/POST or from
SOBE->MOD_SETTINGS. This is ugly, there shouldn't be such
magic: Only controllers know relevant keys and values, so
it should hand them over directly to the shortcut API.

The patch changes this:
* Old and unused ViewHelper f:be.buttons.shortcut is deprecated.
* ViewHelper be:moduleLayout.button.shortcutButton deprecates
  argument 'getVars' and adds new argument 'arguments'.
* Class ShortcutButton has a new setter 'setArguments' that
  accepts all relevant argument key/value pairs to create a
  shortcut. Existing get/set related methods are deprecated.
* Helper methods 'makeShortcutIcon' and 'makeShortcutUrl' of
  class ModuleTemplate are deprecated and implemented in class
  ShortcutButton directly.
* All core usages are adapted to new API.
* Shortcut handling was the last core usage of SOBE, so last
  $GLOBALS['SOBE'] = $this assignments can be finally removed.

Impact:
* Shortcuts to modules not directly reachable via main menu
  do not work due to limits of the module registration API. An
  example is the 'create multiple pages' controller. This issue
  exists before the patch, affected controllers no longer render
  a shortcut button for now.
* The old code usually added the 'route' argument twice for shortcuts.
  This has been resolved. As a side effect, the comparison if a
  shortcuts exists (yellow shortcut icon) fails currently for existing
  shortcuts when the patch is applied: The comparison relies on
  direct string equality since shortcuts always store the final url in
  the database. This storage strategy should be changed with another
  patch that will solve the 'no yellow icon' issue at the same time.

Change-Id: I3ccd2b8f6adab8e7780c5f9911fdea013ccfa99b
Resolves: #92132
Releases: master
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65503
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
lolli42 authored and maddy2101 committed Sep 5, 2020
1 parent 8184966 commit 5be7b80
Show file tree
Hide file tree
Showing 39 changed files with 503 additions and 238 deletions.
Expand Up @@ -115,7 +115,6 @@ class NewContentElementController
public function __construct()
{
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$GLOBALS['SOBE'] = $this;
$this->view = $this->getFluidTemplateObject();
$this->menuItemView = $this->getFluidTemplateObject('MenuItem.html');
$this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
Expand Down
34 changes: 22 additions & 12 deletions typo3/sysext/backend/Classes/Controller/EditDocumentController.php
Expand Up @@ -1298,7 +1298,7 @@ protected function getButtons(ServerRequestInterface $request): void
}

$this->registerOpenInNewWindowButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 2);
$this->registerShortcutButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 3);
$this->registerShortcutButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 3, $request);
$this->registerCshButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 4);
}

Expand Down Expand Up @@ -1794,21 +1794,31 @@ protected function registerOpenInNewWindowButtonToButtonBar(ButtonBar $buttonBar
* @param ButtonBar $buttonBar
* @param string $position
* @param int $group
* @param ServerRequestInterface $request
*/
protected function registerShortcutButtonToButtonBar(ButtonBar $buttonBar, string $position, int $group)
protected function registerShortcutButtonToButtonBar(ButtonBar $buttonBar, string $position, int $group, ServerRequestInterface $request)
{
if ($this->returnUrl !== $this->getCloseUrl()) {
$queryParams = $request->getQueryParams();
$potentialArguments = [
'returnUrl',
'edit',
'defVals',
'overrideVals',
'columnsOnly',
'returnNewPageId',
'noView'
];
$arguments = [
'route' => $queryParams['route'],
];
foreach ($potentialArguments as $argument) {
if (!empty($queryParams[$argument])) {
$arguments[$argument] = $queryParams[$argument];
}
}
$shortCutButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeShortcutButton();
$shortCutButton->setModuleName('xMOD_alt_doc.php')
->setGetVariables([
'returnUrl',
'edit',
'defVals',
'overrideVals',
'columnsOnly',
'returnNewPageId',
'noView']);

$shortCutButton->setModuleName('xMOD_alt_doc.php')->setArguments($arguments);
$buttonBar->addButton($shortCutButton, $position, $group);
}
}
Expand Down
17 changes: 10 additions & 7 deletions typo3/sysext/backend/Classes/Controller/HelpController.php
Expand Up @@ -170,14 +170,17 @@ protected function registerDocheaderButtons(ServerRequestInterface $request)
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();

if ($this->getBackendUser()->mayMakeShortcut()) {
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName('help_cshmanual')
->setGetVariables(['table', 'field', 'route']);
$buttonBar->addButton($shortcutButton);
}

$action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'index';
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName('help_cshmanual')
->setArguments([
'route' => $request->getQueryParams()['route'],
'action' => $action,
'table' => $request->getQueryParams()['table'] ?? '',
'field' => $request->getQueryParams()['field'] ?? ''
]);
$buttonBar->addButton($shortcutButton);

if ($action !== 'index') {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$backButton = $buttonBar->makeLinkButton()
Expand Down
Expand Up @@ -89,10 +89,7 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
->setIcon($iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
->setHref('#');
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName('pages_new')
->setGetVariables(['id']);
$buttonBar->addButton($cshButton)->addButton($viewButton)->addButton($shortcutButton);
$buttonBar->addButton($cshButton)->addButton($viewButton);

// Main view setup
$view = GeneralUtility::makeInstance(StandaloneView::class);
Expand Down
Expand Up @@ -87,10 +87,7 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
->setIcon($iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
->setHref('#');
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName('pages_sort')
->setGetVariables(['id']);
$buttonBar->addButton($cshButton)->addButton($viewButton)->addButton($shortcutButton);
$buttonBar->addButton($cshButton)->addButton($viewButton);

// Main view setup
$view = GeneralUtility::makeInstance(StandaloneView::class);
Expand Down
18 changes: 10 additions & 8 deletions typo3/sysext/backend/Classes/Controller/PageLayoutController.php
Expand Up @@ -174,7 +174,6 @@ class PageLayoutController
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$GLOBALS['SOBE'] = $this;
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$this->pageRenderer = $this->moduleTemplate->getPageRenderer();
$this->iconFactory = $this->moduleTemplate->getIconFactory();
Expand Down Expand Up @@ -303,7 +302,7 @@ protected function initActions(): array

/**
* This creates the dropdown menu with the different actions this module is able to provide.
* For now they are Columns, Quick Edit and Languages.
* For now they are Columns and Languages.
*
* @param array $actions array with the available actions
*/
Expand Down Expand Up @@ -784,12 +783,15 @@ protected function makeButtons(ServerRequestInterface $request): void
// Shortcut
$shortcutButton = $this->buttonBar->makeShortcutButton()
->setModuleName($this->moduleName)
->setGetVariables([
'id',
'route',
'edit_record',
])
->setSetVariables(array_keys($this->MOD_MENU));
->setArguments([
'route' => $request->getQueryParams()['route'],
'id' => (int)$this->id,
'SET' => [
'tt_content_showHidden' => (bool)$this->MOD_SETTINGS['tt_content_showHidden'],
'function' => (int)$this->MOD_SETTINGS['function'],
'language' => (int)$this->current_sys_language,
]
]);
$this->buttonBar->addButton($shortcutButton);

// Cache
Expand Down
Expand Up @@ -107,7 +107,6 @@ class SimpleDataHandlerController
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$GLOBALS['SOBE'] = $this;
$this->init($request);

$this->initializeClipboard();
Expand All @@ -129,7 +128,6 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
*/
public function processAjaxRequest(ServerRequestInterface $request): ResponseInterface
{
$GLOBALS['SOBE'] = $this;
$this->init($request);

// do the regular / main logic
Expand Down
Expand Up @@ -109,10 +109,12 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
/**
* List pages that have 'is_siteroot' flag set - those that have the globe icon in page tree.
* Link to Add / Edit / Delete for each.
*
* @param ServerRequestInterface $request
*/
protected function overviewAction(): void
protected function overviewAction(ServerRequestInterface $request): void
{
$this->configureOverViewDocHeader();
$this->configureOverViewDocHeader($request->getQueryParams()['route']);
$allSites = $this->siteFinder->getAllSites();
$pages = $this->getAllSitePages();
$unassignedSites = [];
Expand Down Expand Up @@ -607,8 +609,10 @@ protected function configureEditViewDocHeader(): void

/**
* Create document header buttons of "overview" action
*
* @param string $route
*/
protected function configureOverViewDocHeader(): void
protected function configureOverViewDocHeader(string $route): void
{
$iconFactory = $this->moduleTemplate->getIconFactory();
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
Expand All @@ -617,13 +621,12 @@ protected function configureOverViewDocHeader(): void
->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
$buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
if ($this->getBackendUser()->mayMakeShortcut()) {
$getVars = ['id', 'route'];
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName('site_configuration')
->setGetVariables($getVars);
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
}
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName('site_configuration')
->setArguments([
'route' => $route
]);
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
}

/**
Expand Down

0 comments on commit 5be7b80

Please sign in to comment.