Commit e8e9323a authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Christian Kuhn
Browse files

[FEATURE] Add button to create sys_note records directly in modules

System notes are being displayed in various modules.
Previously one however had to always switch to the list
module to add such note.

Therefore, a new button is added to the button bar of the
page, list and info module which allows to directly create
a new sys_note record for the current page. The new button
can be disabled via page TSconfig.

Resolves: #83814
Releases: master
Change-Id: Id7ab3b7a25d14c67a2a1b41753e1eae34eecd69e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66373

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 48eb23df
.. include:: ../../Includes.txt
========================================================================
Feature: #83814 - Add system notes creation button to modules button bar
========================================================================
See :issue:`83814`
Description
===========
System notes can be used to add internal information about a page in the backend.
The corresponing notes are being displayed in several modules, depending on the
records configuration, above or below the modules content. Previously, one had
to always switch to the list module and usually also to the "new record" wizard
to create such notes. To improve the usability, a new button is added to the
button bar in the top right of the page, list and info module. This allows to
directly create a new :php:`sys_note` record for the current page.
The new button can be disabled via page TSconfig:
.. code-block:: typoscript
mod.SHARED.disableSysNoteButton = 1
Impact
======
It's now possible to create system notes directly in the corresponding modules
using the new button in the modules top right button bar.
.. index:: Backend, TSConfig, ext:backend
<?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\SysNote\Hook;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Hook for the button bar
*
* @internal This is a specific hook implementation and is not considered part of the Public TYPO3 API.
*/
class ButtonBarHook
{
private const TABLE_NAME = 'sys_note';
private const ALLOWED_MODULES = ['web_layout', 'web_list', 'web_info'];
/**
* Add a sys_note creation button to the button bar of defined modules
*
* @param array $params
* @param ButtonBar $buttonBar
*
* @return array
* @throws RouteNotFoundException
*/
public function getButtons(array $params, ButtonBar $buttonBar): array
{
$buttons = $params['buttons'];
$request = $this->getRequest();
$id = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
$route = $request->getAttribute('route');
$normalizedParams = $request->getAttribute('normalizedParams');
$pageTSconfig = BackendUtility::getPagesTSconfig($id);
if (!$id
|| $route === null
|| $normalizedParams === null
|| !empty($pageTSconfig['mod.']['SHARED.']['disableSysNoteButton'])
|| !$this->canCreateNewRecord($id)
|| !in_array($route->getOption('moduleName'), self::ALLOWED_MODULES, true)
|| ($route->getOption('moduleName') === 'web_list' && !$this->isCreationAllowed($pageTSconfig['mod.']['web_list.'] ?? []))
) {
return $buttons;
}
$uri = (string)GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute(
'record_edit',
[
'edit' => [
self::TABLE_NAME => [
$id => 'new'
]
],
'returnUrl' => $normalizedParams->getRequestUri()
]
);
$buttons[ButtonBar::BUTTON_POSITION_RIGHT][2][] = $buttonBar
->makeLinkButton()
->setTitle(htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:sys_note/Resources/Private/Language/locallang.xlf:new_internal_note')))
->setIcon(GeneralUtility::makeInstance(IconFactory::class)->getIcon('sysnote-type-0', Icon::SIZE_SMALL))
->setHref($uri);
ksort($buttons[ButtonBar::BUTTON_POSITION_RIGHT]);
return $buttons;
}
/**
* Check if the user is allowed to create a sys_note record
*
* @param int $id
* @return bool
*/
protected function canCreateNewRecord(int $id): bool
{
$tableConfiguration = $GLOBALS['TCA'][self::TABLE_NAME]['ctrl'];
$pageRow = BackendUtility::getRecord('pages', $id);
$backendUser = $this->getBackendUserAuthentication();
return !($pageRow === null
|| ($tableConfiguration['readOnly'] ?? false)
|| ($tableConfiguration['hideTable'] ?? false)
|| ($tableConfiguration['is_static'] ?? false)
|| ($tableConfiguration['adminOnly'] && !$backendUser->isAdmin())
|| !$backendUser->doesUserHaveAccess($pageRow, Permission::CONTENT_EDIT)
|| !$backendUser->check('tables_modify', self::TABLE_NAME)
|| !$backendUser->workspaceCanCreateNewRecord(self::TABLE_NAME));
}
/**
* Check if creation is allowed / denied in web_list via mod TSconfig
*
* @param array $modTSconfig
* @return bool
*/
protected function isCreationAllowed(array $modTSconfig): bool
{
$allowedNewTables = GeneralUtility::trimExplode(',', $modTSconfig['allowedNewTables'] ?? '', true);
$deniedNewTables = GeneralUtility::trimExplode(',', $modTSconfig['deniedNewTables'] ?? '', true);
return ($allowedNewTables === [] && $deniedNewTables === [])
|| (!in_array(self::TABLE_NAME, $deniedNewTables)
&& ($allowedNewTables === [] || in_array(self::TABLE_NAME, $allowedNewTables)));
}
protected function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
protected function getBackendUserAuthentication(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
......@@ -6,6 +6,9 @@
<trans-unit id="internal_note" resname="internal_note">
<source>Internal notes</source>
</trans-unit>
<trans-unit id="new_internal_note" resname="new_internal_note">
<source>Create internal note for this page</source>
</trans-unit>
<trans-unit id="author" resname="author">
<source>Author</source>
</trans-unit>
......
......@@ -7,3 +7,5 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeade
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\PageHook::class . '->renderInFooter';
// Hook into the info module
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/web_info/class.tx_cms_webinfo.php']['drawFooterHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\InfoModuleHook::class . '->render';
// Hook into the button bar
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\ButtonBarHook::class . '->getButtons';
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment