[!!!][TASK] Do not handle 'uploadsfolder' in ext_emconf anymore
[Packages/TYPO3.CMS.git] / typo3 / sysext / t3editor / Classes / Hook / FileEditHook.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\T3editor\Hook;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Backend\Controller\File\EditFileController;
19 use TYPO3\CMS\Core\Resource\ResourceFactory;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\T3editor\Exception\InvalidModeException;
22 use TYPO3\CMS\T3editor\Registry\ModeRegistry;
23 use TYPO3\CMS\T3editor\T3editor;
24
25 /**
26 * File edit hook for t3editor
27 * @internal This is a specific hook implementation and is not considered part of the Public TYPO3 API.
28 */
29 class FileEditHook
30 {
31 /**
32 * Hook-function: inject t3editor JavaScript code before the page is compiled
33 * called in file_edit module
34 *
35 * @param array $parameters
36 * @param EditFileController $pObj
37 *
38 * @throws \InvalidArgumentException
39 */
40 public function preOutputProcessingHook(array $parameters, EditFileController $pObj)
41 {
42 // Compile and register t3editor configuration
43 GeneralUtility::makeInstance(T3editor::class)->registerConfiguration();
44
45 $target = '';
46 if (isset($parameters['target']) && is_string($parameters['target'])) {
47 $target = $parameters['target'];
48 }
49
50 $fileExtension = ResourceFactory::getInstance()->retrieveFileOrFolderObject($target)->getExtension();
51 $modeRegistry = GeneralUtility::makeInstance(ModeRegistry::class);
52 try {
53 $mode = $modeRegistry->getByFileExtension($fileExtension);
54 } catch (InvalidModeException $e) {
55 $mode = $modeRegistry->getDefaultMode();
56 }
57
58 $parameters['dataColumnDefinition']['config']['renderType'] = 't3editor';
59 $parameters['dataColumnDefinition']['config']['format'] = $mode->getFormatCode();
60 }
61 }