first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace TYPO3\CMS\Adminpanel\Service;
|
||||
|
||||
/*
|
||||
* 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 Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\OnSubmitActorInterface;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface;
|
||||
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\SingletonInterface;
|
||||
|
||||
/**
|
||||
* Admin Panel Service Class for Configuration Handling
|
||||
*
|
||||
* Scope: User TSConfig + Backend User UC
|
||||
*/
|
||||
class ConfigurationService implements SingletonInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $mainConfiguration;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->mainConfiguration = $this->getBackendUser()->getTSConfig()['admPanel.'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MainConfiguration (User TSConfig admPanel)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMainConfiguration(): array
|
||||
{
|
||||
return $this->mainConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to return configuration options
|
||||
* Checks User TSConfig overrides and current backend user session
|
||||
*
|
||||
* @param string $identifier
|
||||
* @param string $option
|
||||
* @return string
|
||||
*/
|
||||
public function getConfigurationOption(string $identifier, string $option): string
|
||||
{
|
||||
if ($identifier === '' || $option === '') {
|
||||
throw new \InvalidArgumentException('Identifier and option may not be empty', 1532861423);
|
||||
}
|
||||
|
||||
if (isset($this->mainConfiguration['override.'][$identifier . '.'][$option])) {
|
||||
$returnValue = $this->mainConfiguration['override.'][$identifier . '.'][$option];
|
||||
} else {
|
||||
$returnValue = $this->getBackendUser()->uc['AdminPanel'][$identifier . '_' . $option] ?? '';
|
||||
}
|
||||
|
||||
return (string)$returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save admin panel configuration to backend user UC
|
||||
* triggers onSubmit method of modules to enable each module
|
||||
* to enhance the save action
|
||||
*
|
||||
* @param \TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface[] $modules
|
||||
* @param ServerRequestInterface $request
|
||||
*/
|
||||
public function saveConfiguration(array $modules, ServerRequestInterface $request): void
|
||||
{
|
||||
$configurationToSave = $request->getParsedBody()['TSFE_ADMIN_PANEL'] ?? [];
|
||||
$beUser = $this->getBackendUser();
|
||||
$this->triggerOnSubmitActors($modules, $request, $configurationToSave);
|
||||
|
||||
$existingConfiguration = $beUser->uc['AdminPanel'] ?? [];
|
||||
$existingConfiguration = is_array($existingConfiguration) ? $existingConfiguration : [];
|
||||
|
||||
// Settings
|
||||
$beUser->uc['AdminPanel'] = array_merge($existingConfiguration, $configurationToSave);
|
||||
unset($beUser->uc['AdminPanel']['action']);
|
||||
// Saving
|
||||
$beUser->writeUC();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current BE user.
|
||||
*
|
||||
* @return BackendUserAuthentication|FrontendBackendUserAuthentication
|
||||
*/
|
||||
protected function getBackendUser(): BackendUserAuthentication
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $modules
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
* @param $configurationToSave
|
||||
*/
|
||||
protected function triggerOnSubmitActors(
|
||||
array $modules,
|
||||
ServerRequestInterface $request,
|
||||
$configurationToSave
|
||||
): void {
|
||||
foreach ($modules as $module) {
|
||||
if (
|
||||
$module instanceof OnSubmitActorInterface
|
||||
&& (
|
||||
($module instanceof ConfigurableInterface && $module->isEnabled())
|
||||
|| !($module instanceof ConfigurableInterface)
|
||||
)
|
||||
) {
|
||||
$module->onSubmit($configurationToSave, $request);
|
||||
}
|
||||
if ($module instanceof SubmoduleProviderInterface) {
|
||||
$this->triggerOnSubmitActors($module->getSubModules(), $request, $configurationToSave);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace TYPO3\CMS\Adminpanel\Service;
|
||||
|
||||
/*
|
||||
* 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\FrontendBackendUserAuthentication;
|
||||
use TYPO3\CMS\Backend\Routing\UriBuilder;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Core\Context\Context;
|
||||
use TYPO3\CMS\Core\Context\LanguageAspect;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
|
||||
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;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
|
||||
/**
|
||||
* Class for the Edit Toolbar
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class EditToolbarService
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates the tool bar links for the "edit" section of the Admin Panel.
|
||||
*
|
||||
* @return string A string containing images wrapped in <a>-tags linking them to proper functions.
|
||||
*/
|
||||
public function createToolbar(): string
|
||||
{
|
||||
/** @var LanguageAspect $languageAspect */
|
||||
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
|
||||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
|
||||
$tsfe = $this->getTypoScriptFrontendController();
|
||||
// If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead:
|
||||
$moduleName = BackendUtility::getPagesTSconfig($tsfe->page['uid'])['mod.']['newContentElementWizard.']['override'] ?? 'new_content_element';
|
||||
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
|
||||
$perms = $this->getBackendUser()->calcPerms($tsfe->page);
|
||||
$langAllowed = $this->getBackendUser()->checkLanguageAccess($languageAspect->getId());
|
||||
$id = $tsfe->id;
|
||||
$returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI');
|
||||
$classes = 'typo3-adminPanel-btn typo3-adminPanel-btn-default';
|
||||
$output = [];
|
||||
$output[] = '<div class="typo3-adminPanel-form-group">';
|
||||
$output[] = ' <div class="typo3-adminPanel-btn-group" role="group">';
|
||||
|
||||
// History
|
||||
$link = (string)$uriBuilder->buildUriFromRoute(
|
||||
'record_history',
|
||||
[
|
||||
'element' => 'pages:' . $id,
|
||||
'returnUrl' => $returnUrl,
|
||||
]
|
||||
);
|
||||
$title = $this->getLabel('edit_recordHistory');
|
||||
$output[] = '<a class="' .
|
||||
$classes .
|
||||
'" href="' .
|
||||
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
|
||||
'#latest" title="' .
|
||||
$title .
|
||||
'">';
|
||||
$output[] = ' ' . $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render();
|
||||
$output[] = '</a>';
|
||||
|
||||
// New Content
|
||||
if ($perms & Permission::CONTENT_EDIT && $langAllowed) {
|
||||
$linkParameters = [
|
||||
'id' => $id,
|
||||
'returnUrl' => $returnUrl,
|
||||
];
|
||||
if (!empty($languageAspect->getId())) {
|
||||
$linkParameters['sys_language_uid'] = $languageAspect->getId();
|
||||
}
|
||||
$link = (string)$uriBuilder->buildUriFromRoute($moduleName, $linkParameters);
|
||||
$icon = $iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render();
|
||||
$title = $this->getLabel('edit_newContentElement');
|
||||
$output[] = '<a class="' .
|
||||
$classes .
|
||||
'" href="' .
|
||||
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
|
||||
'" title="' .
|
||||
$title .
|
||||
'">';
|
||||
$output[] = ' ' . $icon;
|
||||
$output[] = '</a>';
|
||||
}
|
||||
|
||||
// Move Page
|
||||
if ($perms & Permission::PAGE_EDIT) {
|
||||
$link = (string)$uriBuilder->buildUriFromRoute(
|
||||
'move_element',
|
||||
[
|
||||
'table' => 'pages',
|
||||
'uid' => $id,
|
||||
'returnUrl' => $returnUrl,
|
||||
]
|
||||
);
|
||||
$icon = $iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL)->render();
|
||||
$title = $this->getLabel('edit_move_page');
|
||||
$output[] = '<a class="' .
|
||||
$classes .
|
||||
'" href="' .
|
||||
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
|
||||
'" title="' .
|
||||
$title .
|
||||
'">';
|
||||
$output[] = ' ' . $icon;
|
||||
$output[] = '</a>';
|
||||
}
|
||||
|
||||
// New Page
|
||||
if ($perms & Permission::PAGE_NEW) {
|
||||
$link = (string)$uriBuilder->buildUriFromRoute(
|
||||
'db_new',
|
||||
[
|
||||
'id' => $id,
|
||||
'pagesOnly' => 1,
|
||||
'returnUrl' => $returnUrl,
|
||||
]
|
||||
);
|
||||
$icon = $iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render();
|
||||
$title = $this->getLabel('edit_newPage');
|
||||
$output[] = '<a class="' .
|
||||
$classes .
|
||||
'" href="' .
|
||||
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
|
||||
'" title="' .
|
||||
$title .
|
||||
'">';
|
||||
$output[] = ' ' . $icon;
|
||||
$output[] = '</a>';
|
||||
}
|
||||
|
||||
// Edit Page
|
||||
if ($perms & Permission::PAGE_EDIT) {
|
||||
$link = (string)$uriBuilder->buildUriFromRoute(
|
||||
'record_edit',
|
||||
[
|
||||
'edit[pages][' . $id . ']' => 'edit',
|
||||
'noView' => 1,
|
||||
'returnUrl' => $returnUrl,
|
||||
]
|
||||
);
|
||||
$icon = $iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render();
|
||||
$title = $this->getLabel('edit_editPageProperties');
|
||||
$output[] = '<a class="' .
|
||||
$classes .
|
||||
'" href="' .
|
||||
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
|
||||
'" title="' .
|
||||
$title .
|
||||
'">';
|
||||
$output[] = ' ' . $icon;
|
||||
$output[] = '</a>';
|
||||
}
|
||||
|
||||
// Edit Page Overlay
|
||||
if ($perms & Permission::PAGE_EDIT && $languageAspect->getId() > 0 && $langAllowed) {
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('pages');
|
||||
$queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
|
||||
$row = $queryBuilder
|
||||
->select('uid', 'pid', 't3ver_state')
|
||||
->from('pages')
|
||||
->where(
|
||||
$queryBuilder->expr()->eq(
|
||||
$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
|
||||
$queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
|
||||
),
|
||||
$queryBuilder->expr()->eq(
|
||||
$GLOBALS['TCA']['pages']['ctrl']['languageField'],
|
||||
$queryBuilder->createNamedParameter($languageAspect->getId(), \PDO::PARAM_INT)
|
||||
)
|
||||
)
|
||||
->setMaxResults(1)
|
||||
->execute()
|
||||
->fetch();
|
||||
$tsfe->sys_page->versionOL('pages', $row);
|
||||
if (is_array($row)) {
|
||||
$link = (string)$uriBuilder->buildUriFromRoute(
|
||||
'record_edit',
|
||||
[
|
||||
'edit[pages][' . $row['uid'] . ']' => 'edit',
|
||||
'noView' => 1,
|
||||
'returnUrl' => $returnUrl,
|
||||
]
|
||||
);
|
||||
$icon = $iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)
|
||||
->render();
|
||||
$title = $this->getLabel('edit_editPageOverlay');
|
||||
$output[] = '<a class="' .
|
||||
$classes .
|
||||
'" href="' .
|
||||
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
|
||||
'" title="' .
|
||||
$title .
|
||||
'">';
|
||||
$output[] = ' ' . $icon;
|
||||
$output[] = '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
// Open list view
|
||||
if ($this->getBackendUser()->check('modules', 'web_list')) {
|
||||
$link = (string)$uriBuilder->buildUriFromRoute(
|
||||
'web_list',
|
||||
[
|
||||
'id' => $id,
|
||||
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'),
|
||||
]
|
||||
);
|
||||
$icon = $iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render();
|
||||
$title = $this->getLabel('edit_db_list');
|
||||
$output[] = '<a class="' .
|
||||
$classes .
|
||||
'" href="' .
|
||||
htmlspecialchars($link, ENT_QUOTES | ENT_HTML5) .
|
||||
'" title="' .
|
||||
$title .
|
||||
'">';
|
||||
$output[] = ' ' . $icon;
|
||||
$output[] = '</a>';
|
||||
}
|
||||
|
||||
$output[] = ' </div>';
|
||||
$output[] = '</div>';
|
||||
return implode('', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate given key
|
||||
*
|
||||
* @param string $key Key for a label in the $LOCAL_LANG array of "sysext/core/Resources/Private/Language/locallang_tsfe.xlf
|
||||
* @return string The value for the $key
|
||||
*/
|
||||
protected function getLabel($key): ?string
|
||||
{
|
||||
return htmlspecialchars($this->getLanguageService()->getLL($key), ENT_QUOTES | ENT_HTML5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FrontendBackendUserAuthentication
|
||||
*/
|
||||
protected function getBackendUser(): FrontendBackendUserAuthentication
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LanguageService
|
||||
*/
|
||||
protected function getLanguageService(): LanguageService
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TypoScriptFrontendController
|
||||
*/
|
||||
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
|
||||
{
|
||||
return $GLOBALS['TSFE'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace TYPO3\CMS\Adminpanel\Service;
|
||||
|
||||
/*
|
||||
* 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\Adminpanel\Exceptions\InvalidConfigurationException;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface;
|
||||
use TYPO3\CMS\Core\Service\DependencyOrderingService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Admin Panel Module Loader
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ModuleLoader
|
||||
{
|
||||
|
||||
/**
|
||||
* Validates, sorts and initiates the registered modules
|
||||
*
|
||||
* @param array $modules
|
||||
* @return \TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface[]
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function validateSortAndInitializeModules(array $modules): array
|
||||
{
|
||||
if (empty($modules)) {
|
||||
return [];
|
||||
}
|
||||
foreach ($modules as $identifier => $configuration) {
|
||||
if (empty($configuration) || !is_array($configuration)) {
|
||||
throw new InvalidConfigurationException(
|
||||
'Missing configuration for module "' . $identifier . '".',
|
||||
1519490105
|
||||
);
|
||||
}
|
||||
if (!is_string($configuration['module']) ||
|
||||
empty($configuration['module']) ||
|
||||
!class_exists($configuration['module']) ||
|
||||
!is_subclass_of(
|
||||
$configuration['module'],
|
||||
ModuleInterface::class,
|
||||
true
|
||||
)
|
||||
) {
|
||||
throw new InvalidConfigurationException(
|
||||
'The module "' .
|
||||
$identifier .
|
||||
'" defines an invalid module class. Ensure the class exists and implements the "' .
|
||||
ModuleInterface::class .
|
||||
'".',
|
||||
1519490112
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$orderedModules = GeneralUtility::makeInstance(DependencyOrderingService::class)->orderByDependencies(
|
||||
$modules
|
||||
);
|
||||
|
||||
$moduleInstances = [];
|
||||
foreach ($orderedModules as $moduleConfiguration) {
|
||||
$module = GeneralUtility::makeInstance($moduleConfiguration['module']);
|
||||
if (
|
||||
$module instanceof ModuleInterface
|
||||
&& (
|
||||
($module instanceof ConfigurableInterface && $module->isEnabled())
|
||||
|| !($module instanceof ConfigurableInterface)
|
||||
)
|
||||
) {
|
||||
$moduleInstances[$module->getIdentifier()] = $module;
|
||||
}
|
||||
if ($module instanceof SubmoduleProviderInterface) {
|
||||
$subModuleInstances = $this->validateSortAndInitializeModules($moduleConfiguration['submodules'] ?? []);
|
||||
$module->setSubModules($subModuleInstances);
|
||||
}
|
||||
}
|
||||
return $moduleInstances;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user