TYPO3 CMS  TYPO3_8-7
FrontendEditAssetLoader.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Feedit;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
29  public function attachAssets(EditDocumentController $controller)
30  {
31  if ((int)GeneralUtility::_GP('feEdit') === 1) {
32  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
33  // We have to load some locallang strings and push them into TYPO3.LLL if this request was
34  // triggered by feedit. Originally, this object is fed by BackendController which is not
35  // called here. This block of code is intended to be removed at a later point again.
36  $lang = $this->getLanguageService();
37  $coreLabels = [
38  'csh_tooltip_loading' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:csh_tooltip_loading')
39  ];
40  $generatedLabels = [];
41  $generatedLabels['core'] = $coreLabels;
42  $code = 'TYPO3.LLL = ' . json_encode($generatedLabels) . ';';
43  $filePath = 'typo3temp/assets/js/backend-' . sha1($code) . '.js';
44  if (!file_exists(PATH_site . $filePath)) {
45  // writeFileToTypo3tempDir() returns NULL on success (please double-read!)
46  $error = GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filePath, $code);
47  if ($error !== null) {
48  throw new \RuntimeException('Locallang JS file could not be written to ' . $filePath . '. Reason: ' . $error, 1446118286);
49  }
50  }
51  $pageRenderer->addJsFile('../' . $filePath);
52  }
53  }
54 
60  protected function getLanguageService()
61  {
62  return $GLOBALS['LANG'];
63  }
64 }
attachAssets(EditDocumentController $controller)
static writeFileToTypo3tempDir($filepath, $content)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']