‪TYPO3CMS  10.4
TypoScriptTemplateInformationModuleFunctionController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ServerRequestInterface;
25 
31 {
32 
36  protected ‪$pObj;
37 
42  protected ‪$templateRow;
43 
47  protected ‪$templateService;
48 
52  protected ‪$id;
53 
57  protected ‪$request;
58 
65  public function ‪init(‪$pObj, ServerRequestInterface ‪$request)
66  {
67  $this->pObj = ‪$pObj;
68  $this->request = ‪$request;
69  $this->id = (int)(‪$request->getParsedBody()['id'] ?? ‪$request->getQueryParams()['id'] ?? 0);
70  }
71 
81  protected function ‪tableRowData($label, $data, $field, ‪$id)
82  {
83  $urlParameters = [
84  'id' => ‪$this->id,
85  'edit' => [
86  'sys_template' => [
87  ‪$id => 'edit'
88  ]
89  ],
90  'columnsOnly' => $field,
91  'createExtension' => 0,
92  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
93  ];
95  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
96  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
97 
98  return [
99  'url' => $url,
100  'data' => $data,
101  'label' => $label
102  ];
103  }
104 
116  protected function ‪initialize_editor($pageId, $template_uid = 0)
117  {
118  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
119 
120  // Get the row of the first VISIBLE template of the page. where clause like the frontend.
121  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
122  if (is_array($this->templateRow)) {
123  return true;
124  }
125  return false;
126  }
127 
133  public function ‪main()
134  {
135  // Checking for more than one template an if, set a menu...
136  $manyTemplatesMenu = $this->pObj->templateMenu($this->request);
137  $template_uid = 0;
138  if ($manyTemplatesMenu) {
139  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
140  }
141  // Initialize
142  $existTemplate = $this->‪initialize_editor($this->id, $template_uid);
143  $saveId = 0;
144  if ($existTemplate) {
145  $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
146  }
148  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
149  // Create extension template
150  $newId = $this->pObj->createTemplate($this->id, (int)$saveId);
151  if ($newId) {
152  // Switch to new template
153  $urlParameters = [
154  'id' => ‪$this->id,
155  'SET[templatesOnPage]' => $newId
156  ];
157  $url = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
159  }
160  $tce = null;
161  if ($existTemplate) {
162  $lang = $this->‪getLanguageService();
163  $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_info.xlf');
164  $assigns = [];
165  $assigns['LLPrefix'] = 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_info.xlf:';
166 
167  $assigns['title'] = trim($this->templateRow['title']);
168  $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
169  $assigns['templateRecord'] = ‪$this->templateRow;
170  if ($manyTemplatesMenu) {
171  $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
172  }
173 
174  // Processing:
175  $tableRows = [];
176  $tableRows[] = $this->‪tableRowData($lang->getLL('title'), $this->templateRow['title'], 'title', $this->templateRow['uid']);
177  $tableRows[] = $this->‪tableRowData($lang->getLL('sitetitle'), $this->templateRow['sitetitle'], 'sitetitle', $this->templateRow['uid']);
178  $tableRows[] = $this->‪tableRowData($lang->getLL('description'), $this->templateRow['description'], 'description', $this->templateRow['uid']);
179  $tableRows[] = $this->‪tableRowData($lang->getLL('constants'), sprintf($lang->getLL('editToView'), trim($this->templateRow['constants']) ? count(explode(LF, $this->templateRow['constants'])) : 0), 'constants', $this->templateRow['uid']);
180  $tableRows[] = $this->‪tableRowData($lang->getLL('setup'), sprintf($lang->getLL('editToView'), trim($this->templateRow['config']) ? count(explode(LF, $this->templateRow['config'])) : 0), 'config', $this->templateRow['uid']);
181  $assigns['tableRows'] = $tableRows;
182 
183  // Edit all icon:
184  $urlParameters = [
185  'edit' => [
186  'sys_template' => [
187  $this->templateRow['uid'] => 'edit'
188  ]
189  ],
190  'createExtension' => 0,
191  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
192  ];
193  $assigns['editAllUrl'] = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
194 
195  // Rendering of the output via fluid
196  $view = GeneralUtility::makeInstance(StandaloneView::class);
197  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
198  'EXT:tstemplate/Resources/Private/Templates/InformationModule.html'
199  ));
200  $view->assignMultiple($assigns);
201  $theOutput = $view->render();
202  } else {
203  $theOutput = $this->pObj->noTemplate(1);
204  }
205  return $theOutput;
206  }
207 
211  protected function ‪getLanguageService(): ‪LanguageService
212  {
213  return ‪$GLOBALS['LANG'];
214  }
215 }
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\getLanguageService
‪LanguageService getLanguageService()
Definition: TypoScriptTemplateInformationModuleFunctionController.php:207
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\init
‪init($pObj, ServerRequestInterface $request)
Definition: TypoScriptTemplateInformationModuleFunctionController.php:61
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$templateRow
‪array $templateRow
Definition: TypoScriptTemplateInformationModuleFunctionController.php:40
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\tableRowData
‪array tableRowData($label, $data, $field, $id)
Definition: TypoScriptTemplateInformationModuleFunctionController.php:77
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$pObj
‪TypoScriptTemplateModuleController $pObj
Definition: TypoScriptTemplateInformationModuleFunctionController.php:35
‪TYPO3\CMS\Tstemplate\Controller
Definition: TemplateAnalyzerModuleFunctionController.php:16
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\initialize_editor
‪bool initialize_editor($pageId, $template_uid=0)
Definition: TypoScriptTemplateInformationModuleFunctionController.php:112
‪TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
Definition: ExtendedTemplateService.php:43
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$request
‪ServerRequestInterface $request
Definition: TypoScriptTemplateInformationModuleFunctionController.php:53
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController
Definition: TypoScriptTemplateModuleController.php:48
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$id
‪$id
Definition: TypoScriptTemplateInformationModuleFunctionController.php:49
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\main
‪string main()
Definition: TypoScriptTemplateInformationModuleFunctionController.php:129
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\HttpUtility
Definition: HttpUtility.php:24
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController
Definition: TypoScriptTemplateInformationModuleFunctionController.php:31
‪TYPO3\CMS\Core\Utility\HttpUtility\redirect
‪static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:106
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$templateService
‪ExtendedTemplateService $templateService
Definition: TypoScriptTemplateInformationModuleFunctionController.php:44