‪TYPO3CMS  11.5
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;
23 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
26 
32 {
36  protected ‪$pObj;
37 
42  protected ‪$templateRow;
43 
47  protected ‪$templateService;
48 
52  protected ‪$id;
53 
57  protected ‪$request;
58 
59  protected ‪UriBuilder ‪$uriBuilder;
60 
62  {
63  $this->uriBuilder = ‪$uriBuilder;
64  }
71  public function ‪init(‪$pObj, ServerRequestInterface ‪$request)
72  {
73  $this->pObj = ‪$pObj;
74  $this->request = ‪$request;
75  $this->id = (int)(‪$request->getParsedBody()['id'] ?? ‪$request->getQueryParams()['id'] ?? 0);
76  }
77 
87  protected function ‪tableRowData($label, $data, $field, ‪$id)
88  {
89  $urlParameters = [
90  'id' => ‪$this->id,
91  'edit' => [
92  'sys_template' => [
93  ‪$id => 'edit',
94  ],
95  ],
96  'columnsOnly' => $field,
97  'createExtension' => 0,
98  'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(),
99  ];
100  $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
101 
102  return [
103  'url' => $url,
104  'data' => $data,
105  'label' => $label,
106  ];
107  }
108 
120  protected function ‪initialize_editor($pageId, $template_uid = 0)
121  {
122  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
123 
124  // Get the row of the first VISIBLE template of the page. where clause like the frontend.
125  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
126  if (is_array($this->templateRow)) {
127  return true;
128  }
129  return false;
130  }
131 
137  public function ‪main()
138  {
139  // Checking for more than one template an if, set a menu...
140  $manyTemplatesMenu = $this->pObj->templateMenu($this->request);
141  $template_uid = 0;
142  if ($manyTemplatesMenu) {
143  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
144  }
145  // Initialize
146  $existTemplate = $this->‪initialize_editor($this->id, $template_uid);
147  $saveId = 0;
148  if ($existTemplate) {
149  $saveId = empty($this->templateRow['_ORIG_uid']) ? $this->templateRow['uid'] : $this->templateRow['_ORIG_uid'];
150  }
151  // Create extension template
152  $newId = $this->pObj->createTemplate($this->id, (int)$saveId);
153  if ($newId) {
154  // Switch to new template
155  $urlParameters = [
156  'id' => ‪$this->id,
157  'SET[templatesOnPage]' => $newId,
158  ];
159  $url = $this->uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
160  throw new PropagateResponseException(new RedirectResponse($url, 303), 1607271781);
161  }
162  if ($existTemplate) {
163  $lang = $this->‪getLanguageService();
164  $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_info.xlf');
165  $assigns = [];
166  $assigns['templateRecord'] = ‪$this->templateRow;
167  $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
168 
169  // Processing:
170  $tableRows = [];
171  $tableRows[] = $this->‪tableRowData($lang->getLL('title'), $this->templateRow['title'], 'title', $this->templateRow['uid']);
172  $tableRows[] = $this->‪tableRowData($lang->getLL('description'), $this->templateRow['description'], 'description', $this->templateRow['uid']);
173  $tableRows[] = $this->‪tableRowData($lang->getLL('constants'), sprintf($lang->getLL('editToView'), trim((string)$this->templateRow['constants']) ? count(explode(LF, (string)$this->templateRow['constants'])) : 0), 'constants', $this->templateRow['uid']);
174  $tableRows[] = $this->‪tableRowData($lang->getLL('setup'), sprintf($lang->getLL('editToView'), trim((string)$this->templateRow['config']) ? count(explode(LF, (string)$this->templateRow['config'])) : 0), 'config', $this->templateRow['uid']);
175  $assigns['tableRows'] = $tableRows;
176 
177  // Edit all icon:
178  $urlParameters = [
179  'edit' => [
180  'sys_template' => [
181  $this->templateRow['uid'] => 'edit',
182  ],
183  ],
184  'createExtension' => 0,
185  'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri(),
186  ];
187  $assigns['editAllUrl'] = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
188 
189  // Rendering of the output via fluid
190  $view = GeneralUtility::makeInstance(StandaloneView::class);
191  $view->setTemplatePathAndFilename('EXT:tstemplate/Resources/Private/Templates/InformationModule.html');
192  $view->assignMultiple($assigns);
193  $theOutput = $view->render();
194  } else {
195  $theOutput = $this->pObj->noTemplate(1);
196  }
197  return $theOutput;
198  }
199 
203  protected function ‪getLanguageService(): ‪LanguageService
204  {
205  return ‪$GLOBALS['LANG'];
206  }
207 }
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\getLanguageService
‪LanguageService getLanguageService()
Definition: TypoScriptTemplateInformationModuleFunctionController.php:199
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\init
‪init($pObj, ServerRequestInterface $request)
Definition: TypoScriptTemplateInformationModuleFunctionController.php:67
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\tableRowData
‪array tableRowData($label, $data, $field, $id)
Definition: TypoScriptTemplateInformationModuleFunctionController.php:83
‪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:116
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$request
‪ServerRequestInterface $request
Definition: TypoScriptTemplateInformationModuleFunctionController.php:53
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$uriBuilder
‪UriBuilder $uriBuilder
Definition: TypoScriptTemplateInformationModuleFunctionController.php:55
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController
Definition: TypoScriptTemplateModuleController.php:51
‪TYPO3\CMS\Core\Http\PropagateResponseException
Definition: PropagateResponseException.php:47
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$id
‪$id
Definition: TypoScriptTemplateInformationModuleFunctionController.php:49
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\main
‪string main()
Definition: TypoScriptTemplateInformationModuleFunctionController.php:133
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController
Definition: TypoScriptTemplateInformationModuleFunctionController.php:32
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$templateService
‪ExtendedTemplateService $templateService
Definition: TypoScriptTemplateInformationModuleFunctionController.php:44
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\$templateRow
‪array null $templateRow
Definition: TypoScriptTemplateInformationModuleFunctionController.php:40
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController\__construct
‪__construct(UriBuilder $uriBuilder)
Definition: TypoScriptTemplateInformationModuleFunctionController.php:57