Commit 5074e96f authored by Christian Kuhn's avatar Christian Kuhn Committed by Benni Mack
Browse files

[TASK] Use PageRenderer hooks in t3editor and rte_ckeditor

Instead of instantiating PageRenderer early in
ext_localconf, the additional require js for
t3editor and rte_ckeditor is now injected by a
PageRenderer hook when needed.

Releases: master
Resolves: #92848
Change-Id: I070d75482deb0b4c7a301719440ae18d28f0a57a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66641


Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent af9181d0
<?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\RteCKEditor\Hook;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
/**
* PageRenderer hook to add require js configuration for backend calls
*
* @internal This is a specific hook implementation and is not considered part of the Public TYPO3 API.
*/
final class PageRendererRenderPreProcess
{
public function addRequireJsConfiguration(array $params, PageRenderer $pageRenderer): void
{
if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
$pageRenderer->addRequireJsConfiguration([
'shim' => [
'ckeditor' => ['exports' => 'CKEDITOR']
],
'paths' => [
'ckeditor' => PathUtility::getAbsoluteWebPath(
ExtensionManagementUtility::extPath('rte_ckeditor', 'Resources/Public/JavaScript/Contrib/')
) . 'ckeditor'
]
]);
}
}
}
......@@ -9,20 +9,9 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'][1480314091] = [
'class' => \TYPO3\CMS\RteCKEditor\Form\Resolver\RichTextNodeResolver::class,
];
if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Page\PageRenderer::class
)->addRequireJsConfiguration([
'shim' => [
'ckeditor' => ['exports' => 'CKEDITOR']
],
'paths' => [
'ckeditor' => \TYPO3\CMS\Core\Utility\PathUtility::getAbsoluteWebPath(
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('rte_ckeditor', 'Resources/Public/JavaScript/Contrib/')
) . 'ckeditor'
]
]);
}
// Hook to add rte_ckeditor requirejs config to PageRenderer in backend
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'][] =
\TYPO3\CMS\RteCKEditor\Hook\PageRendererRenderPreProcess::class . '->addRequireJsConfiguration';
// Register the presets
if (empty($GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['default'])) {
......
<?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\T3editor\Hook;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
/**
* PageRenderer hook to add require js configuration for backend calls
*
* @internal This is a specific hook implementation and is not considered part of the Public TYPO3 API.
*/
final class PageRendererRenderPreProcess
{
public function addRequireJsConfiguration(array $params, PageRenderer $pageRenderer): void
{
if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
$pageRenderer->addRequireJsConfiguration([
'packages' => [
[
'name' => 'cm',
'location' => PathUtility::getAbsoluteWebPath(
GeneralUtility::getFileAbsFileName('EXT:t3editor/Resources/Public/JavaScript/Contrib/cm')
),
'main' => 'lib/codemirror',
]
]
]);
}
}
}
......@@ -2,25 +2,14 @@
defined('TYPO3_MODE') or die();
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'][] = \TYPO3\CMS\T3editor\Hook\FileEditHook::class . '->preOutputProcessingHook';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'][] =
\TYPO3\CMS\T3editor\Hook\FileEditHook::class . '->preOutputProcessingHook';
if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
// We need this at a central place because CodeMirror uses relative paths in its module definitions and using PageRenderer is prohibited in FormEngine
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Page\PageRenderer::class
)->addRequireJsConfiguration([
'packages' => [
[
'name' => 'cm',
'location' => \TYPO3\CMS\Core\Utility\PathUtility::getAbsoluteWebPath(
\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:t3editor/Resources/Public/JavaScript/Contrib/cm')
),
'main' => 'lib/codemirror',
],
],
]);
}
// Hook to add t3editor requirejs config to PageRenderer in backend
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'][] =
\TYPO3\CMS\T3editor\Hook\PageRendererRenderPreProcess::class . '->addRequireJsConfiguration';
// Register backend FormEngine node
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1433089350] = [
'nodeName' => 't3editor',
'priority' => 40,
......
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