[BUGFIX] Resolve workspace records for template module overview
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate / Classes / Controller / TypoScriptTemplateModuleController.php
1 <?php
2 namespace TYPO3\CMS\Tstemplate\Controller;
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
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\BaseScriptClass;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Database\Connection;
24 use TYPO3\CMS\Core\Database\ConnectionPool;
25 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
26 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
27 use TYPO3\CMS\Core\DataHandling\DataHandler;
28 use TYPO3\CMS\Core\Http\HtmlResponse;
29 use TYPO3\CMS\Core\Imaging\Icon;
30 use TYPO3\CMS\Core\Type\Bitmask\Permission;
31 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33 use TYPO3\CMS\Core\Utility\MathUtility;
34 use TYPO3\CMS\Core\Versioning\VersionState;
35 use TYPO3\CMS\Fluid\View\StandaloneView;
36 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
37
38 /**
39 * Module: TypoScript Tools
40 */
41 class TypoScriptTemplateModuleController extends BaseScriptClass
42 {
43 /**
44 * @var string
45 */
46 public $perms_clause;
47
48 /**
49 * @var string
50 */
51 public $sObj;
52
53 /**
54 * @var string
55 */
56 public $edit;
57
58 /**
59 * @var string
60 */
61 public $textExtensions = 'html,htm,txt,css,tmpl,inc,js';
62
63 /**
64 * @var string
65 */
66 public $modMenu_type = '';
67
68 /**
69 * @var string
70 */
71 public $modMenu_dontValidateList = '';
72
73 /**
74 * @var string
75 */
76 public $modMenu_setDefaultList = '';
77
78 /**
79 * @var array
80 */
81 public $pageinfo = [];
82
83 /**
84 * @var bool
85 */
86 public $access = false;
87
88 /**
89 * The name of the module
90 *
91 * @var string
92 */
93 protected $moduleName = 'web_ts';
94
95 /**
96 * ModuleTemplate Container
97 *
98 * @var ModuleTemplate
99 */
100 protected $moduleTemplate;
101
102 /**
103 * @var ExtendedTemplateService
104 */
105 protected $templateService;
106
107 /**
108 * Constructor
109 */
110 public function __construct()
111 {
112 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
113 $this->getLanguageService()->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang.xlf');
114
115 $this->MCONF = [
116 'name' => $this->moduleName
117 ];
118 $this->moduleTemplate->addJavaScriptCode(
119 'jumpToUrl',
120 '
121 function jumpToUrl(URL) {
122 window.location.href = URL;
123 return false;
124 }
125 '
126 );
127 }
128
129 /**
130 * Init
131 */
132 public function init()
133 {
134 parent::init();
135 $this->id = (int)GeneralUtility::_GP('id');
136 $this->sObj = GeneralUtility::_GP('sObj');
137 $this->edit = GeneralUtility::_GP('edit');
138 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
139 }
140
141 /**
142 * Clear cache
143 */
144 public function clearCache()
145 {
146 if (GeneralUtility::_GP('clear_all_cache')) {
147 /** @var DataHandler $tce */
148 $tce = GeneralUtility::makeInstance(DataHandler::class);
149 $tce->start([], []);
150 $tce->clear_cacheCmd('all');
151 }
152 }
153
154 /**
155 * Main
156 */
157 public function main()
158 {
159 // Access check...
160 // The page will show only if there is a valid page and if this page may be viewed by the user
161 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
162 $this->access = is_array($this->pageinfo);
163 $view = $this->getFluidTemplateObject('tstemplate');
164 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
165 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
166 if ($this->id && $this->access) {
167 $urlParameters = [
168 'id' => $this->id,
169 'template' => 'all'
170 ];
171 $aHref = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
172
173 // JavaScript
174 $this->moduleTemplate->addJavaScriptCode(
175 'TSTemplateInlineJS',
176 'function uFormUrl(aname) {
177 document.forms[0].action = ' . GeneralUtility::quoteJSvalue($aHref . '#') . '+aname;
178 }
179 function brPoint(lnumber,t) {
180 window.location.href = '
181 . GeneralUtility::quoteJSvalue(
182 $aHref . '&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\'
183 . 'TypoScriptTemplateObjectBrowserModuleFunctionController&SET[ts_browser_type]='
184 ) . '+(t?"setup":"const")+"&breakPointLN="+lnumber;
185 return false;
186 }
187 if (top.fsMod) top.fsMod.recentIds["web"] = ' . $this->id . ';'
188 );
189 $this->moduleTemplate->getPageRenderer()->addCssInlineBlock(
190 'TSTemplateInlineStyle',
191 'TABLE#typo3-objectBrowser { width: 100%; margin-bottom: 24px; }
192 TABLE#typo3-objectBrowser A { text-decoration: none; }
193 TABLE#typo3-objectBrowser .comment { color: maroon; font-weight: bold; }
194 .ts-typoscript { width: 100%; }
195 .tsob-search-submit {margin-left: 3px; margin-right: 3px;}
196 .tst-analyzer-options { margin:5px 0; }'
197 );
198 // Setting up the context sensitive menu:
199 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
200 // Build the module content
201 $view->assign('actionName', $aHref);
202 $view->assign('typoscriptTemplateModuleContent', $this->getExtObjContent());
203 // Setting up the buttons and markers for docheader
204 $this->getButtons();
205 $this->generateMenu();
206 } else {
207 $workspaceId = $this->getBackendUser()->workspace;
208 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
209 ->getQueryBuilderForTable('sys_template');
210 $queryBuilder->getRestrictions()
211 ->removeAll()
212 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
213 $this->applyWorkspaceConstraint(
214 $queryBuilder,
215 'sys_template',
216 $workspaceId
217 );
218 $result = $queryBuilder
219 ->select(
220 'uid',
221 'pid',
222 'title',
223 'sitetitle',
224 'root',
225 'hidden',
226 'starttime',
227 'endtime',
228 't3ver_oid',
229 't3ver_wsid',
230 't3ver_state',
231 't3ver_move_id'
232 )
233 ->from('sys_template')
234 ->orderBy('sys_template.pid')
235 ->addOrderBy('sys_template.sorting')
236 ->execute();
237 $pArray = [];
238 while ($record = $result->fetch()) {
239 BackendUtility::workspaceOL('sys_template', $record, $workspaceId, true);
240 if (empty($record) || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
241 continue;
242 }
243 $additionalFieldsForRootline = ['sorting', 'hidden', 'fe_group', 'starttime', 'endtime', 'shortcut', 'nav_hide', 'module', 'content_from_pid'];
244 $rootline = BackendUtility::BEgetRootLine($record['pid'], '', true, $additionalFieldsForRootline);
245 $this->setInPageArray($pArray, $rootline, $record);
246 }
247
248 $view->getRenderingContext()->setControllerAction('PageZero');
249 $view->assign('pageTree', $pArray);
250
251 // RENDER LIST of pages with templates, END
252 // Setting up the buttons and markers for docheader
253 $this->getButtons();
254 }
255 $this->content = $view->render();
256 }
257
258 /**
259 * Generates the menu based on $this->MOD_MENU
260 *
261 * @throws \InvalidArgumentException
262 */
263 protected function generateMenu()
264 {
265 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
266 $menu->setIdentifier('WebFuncJumpMenu');
267 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
268 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
269 foreach ($this->MOD_MENU['function'] as $controller => $title) {
270 $item = $menu
271 ->makeMenuItem()
272 ->setHref(
273 (string)$uriBuilder->buildUriFromRoute(
274 $this->moduleName,
275 [
276 'id' => $this->id,
277 'SET' => [
278 'function' => $controller
279 ]
280 ]
281 )
282 )
283 ->setTitle($title);
284 if ($controller === $this->MOD_SETTINGS['function']) {
285 $item->setActive(true);
286 }
287 $menu->addMenuItem($item);
288 }
289 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
290 }
291
292 /**
293 * Injects the request object for the current request or subrequest
294 * Then checks for module functions that have hooked in, and renders menu etc.
295 *
296 * @param ServerRequestInterface $request the current request
297 * @return ResponseInterface the response with the content
298 */
299 public function mainAction(ServerRequestInterface $request): ResponseInterface
300 {
301 $GLOBALS['SOBE'] = $this;
302 $this->init();
303
304 // Checking for first level external objects
305 $this->checkExtObj();
306
307 $this->clearCache();
308 $this->main();
309
310 $this->moduleTemplate->setContent($this->content);
311 return new HtmlResponse($this->moduleTemplate->renderContent());
312 }
313
314 /**
315 * Create the panel of buttons for submitting the form or otherwise perform operations.
316 */
317 protected function getButtons()
318 {
319 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
320 $lang = $this->getLanguageService();
321
322 if ($this->id && $this->access) {
323 // View page
324 $viewButton = $buttonBar->makeLinkButton()
325 ->setHref('#')
326 ->setOnClick(BackendUtility::viewOnClick(
327 $this->pageinfo['uid'],
328 '',
329 BackendUtility::BEgetRootLine($this->pageinfo['uid'])
330 ))
331 ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
332 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-page', Icon::SIZE_SMALL));
333 $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 99);
334
335 if ($this->extClassConf['name'] === TypoScriptTemplateInformationModuleFunctionController::class) {
336 // NEW button
337 $urlParameters = [
338 'id' => $this->id,
339 'template' => 'all',
340 'createExtension' => 'new'
341 ];
342 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
343 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
344 $newButton = $buttonBar->makeLinkButton()
345 ->setHref((string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters))
346 ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:db_new.php.pagetitle'))
347 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
348 'actions-add',
349 Icon::SIZE_SMALL
350 ));
351 $buttonBar->addButton($newButton);
352 } elseif ($this->extClassConf['name'] === TypoScriptTemplateConstantEditorModuleFunctionController::class
353 && !empty($this->MOD_MENU['constant_editor_cat'])) {
354 // SAVE button
355 $saveButton = $buttonBar->makeInputButton()
356 ->setName('_savedok')
357 ->setValue('1')
358 ->setForm('TypoScriptTemplateModuleController')
359 ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:rm.saveDoc'))
360 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
361 'actions-document-save',
362 Icon::SIZE_SMALL
363 ))
364 ->setShowLabelText(true);
365 $buttonBar->addButton($saveButton);
366 } elseif ($this->extClassConf['name'] === TypoScriptTemplateObjectBrowserModuleFunctionController::class) {
367 if (!empty($this->sObj)) {
368 // BACK
369 $urlParameters = [
370 'id' => $this->id
371 ];
372 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
373 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
374 $backButton = $buttonBar->makeLinkButton()
375 ->setHref((string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters))
376 ->setClasses('typo3-goBack')
377 ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
378 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
379 'actions-view-go-back',
380 Icon::SIZE_SMALL
381 ));
382 $buttonBar->addButton($backButton);
383 }
384 }
385 }
386 // Shortcut
387 $shortcutButton = $buttonBar->makeShortcutButton()
388 ->setModuleName($this->MCONF['name'])
389 ->setGetVariables(['id', 'route']);
390 $buttonBar->addButton($shortcutButton);
391 }
392
393 // OTHER FUNCTIONS:
394 /**
395 * Wrap title for link in template
396 *
397 * @param string $title
398 * @param string $onlyKey
399 * @return string
400 */
401 public function linkWrapTemplateTitle($title, $onlyKey = '')
402 {
403 $urlParameters = [
404 'id' => $this->id
405 ];
406 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
407 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
408 $aHref = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
409 if ($onlyKey) {
410 $title = '<a href="' . htmlspecialchars($aHref . '&e[' . $onlyKey . ']=1&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateInformationModuleFunctionController') . '">' . htmlspecialchars($title) . '</a>';
411 } else {
412 $title = '<a href="' . htmlspecialchars($aHref . '&e[constants]=1&e[config]=1&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateInformationModuleFunctionController') . '">' . htmlspecialchars($title) . '</a>';
413 }
414 return $title;
415 }
416
417 /**
418 * No template
419 *
420 * @param int $newStandardTemplate
421 * @return string
422 */
423 public function noTemplate($newStandardTemplate = 0)
424 {
425 $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
426
427 $moduleContent['state'] = InfoboxViewHelper::STATE_INFO;
428
429 // New standard?
430 if ($newStandardTemplate) {
431 $selector = '';
432 $staticsText = '';
433 // Hook to change output, implemented for statictemplates
434 $hookObject = $this->getHookObjectForAction('newStandardTemplateView');
435 if (!empty($hookObject)) {
436 $reference = [
437 'selectorHtml' => &$selector,
438 'staticsText' => &$staticsText
439 ];
440 GeneralUtility::callUserFunction(
441 $hookObject,
442 $reference,
443 $this
444 );
445 $selector = $reference['selectorHtml'];
446 $staticsText = $reference['staticsText'];
447 }
448 // Extension?
449 $moduleContent['staticsText'] = $staticsText;
450 $moduleContent['selector'] = $selector;
451 }
452 // Go to previous Page with Template...
453 $previousPage = $this->templateService->ext_prevPageWithTemplate($this->id, $this->perms_clause);
454 if ($previousPage) {
455 $urlParameters = [
456 'id' => $previousPage['uid']
457 ];
458 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
459 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
460 $previousPage['aHref'] = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
461 $moduleContent['previousPage'] = $previousPage;
462 }
463 $view = $this->getFluidTemplateObject('tstemplate', 'NoTemplate');
464 $view->assign('content', $moduleContent);
465 return $view->render();
466 }
467
468 /**
469 * Render template menu
470 *
471 * @return string
472 */
473 public function templateMenu()
474 {
475 $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
476
477 $all = $this->templateService->ext_getAllTemplates($this->id);
478 if (count($all) > 1) {
479 $this->MOD_MENU['templatesOnPage'] = [];
480 foreach ($all as $d) {
481 $this->MOD_MENU['templatesOnPage'][$d['uid']] = $d['title'];
482 }
483 }
484 $this->MOD_SETTINGS = BackendUtility::getModuleData(
485 $this->MOD_MENU,
486 GeneralUtility::_GP('SET'),
487 $this->MCONF['name'],
488 $this->modMenu_type,
489 $this->modMenu_dontValidateList,
490 $this->modMenu_setDefaultList
491 );
492 return BackendUtility::getFuncMenu(
493 $this->id,
494 'SET[templatesOnPage]',
495 $this->MOD_SETTINGS['templatesOnPage'],
496 $this->MOD_MENU['templatesOnPage']
497 );
498 }
499
500 /**
501 * Create template
502 *
503 * @param int $id
504 * @param int $actTemplateId
505 * @return string
506 */
507 public function createTemplate($id, $actTemplateId = 0)
508 {
509 $recData = [];
510 /** @var DataHandler $tce */
511 $tce = GeneralUtility::makeInstance(DataHandler::class);
512
513 if (GeneralUtility::_GP('createExtension')) {
514 $recData['sys_template']['NEW'] = [
515 'pid' => $actTemplateId ? -1 * $actTemplateId : $id,
516 'title' => '+ext'
517 ];
518 $tce->start($recData, []);
519 $tce->process_datamap();
520 } elseif (GeneralUtility::_GP('newWebsite')) {
521 // Hook to handle row data, implemented for statictemplates
522 $hookObject = $this->getHookObjectForAction('newStandardTemplateHandler');
523 if (!empty($hookObject)) {
524 $reference = [
525 'recData' => &$recData,
526 'id' => $id,
527 ];
528 GeneralUtility::callUserFunction(
529 $hookObject,
530 $reference,
531 $this
532 );
533 $recData = $reference['recData'];
534 } else {
535 $recData['sys_template']['NEW'] = [
536 'pid' => $id,
537 'title' => $this->getLanguageService()->getLL('titleNewSite'),
538 'sorting' => 0,
539 'root' => 1,
540 'clear' => 3,
541 'config' => '
542 # Default PAGE object:
543 page = PAGE
544 page.10 = TEXT
545 page.10.value = HELLO WORLD!
546 '
547 ];
548 }
549 $tce->start($recData, []);
550 $tce->process_datamap();
551 $tce->clear_cacheCmd('all');
552 }
553 return $tce->substNEWwithIDs['NEW'];
554 }
555
556 /**
557 * Set page in array
558 * To render list of page tree with templates
559 *
560 * @param array $pArray Multidimensional array of page tree with template records
561 * @param array $rlArr Rootline array
562 * @param array $row Record of sys_template
563 */
564 public function setInPageArray(&$pArray, $rlArr, $row)
565 {
566 ksort($rlArr);
567 reset($rlArr);
568 if (!$rlArr[0]['uid']) {
569 array_shift($rlArr);
570 }
571 $cEl = current($rlArr);
572 if (empty($pArray[$cEl['uid']])) {
573 $pArray[$cEl['uid']] = $cEl;
574 }
575 array_shift($rlArr);
576 if (!empty($rlArr)) {
577 if (empty($pArray[$cEl['uid']]['_nodes'])) {
578 $pArray[$cEl['uid']]['_nodes'] = [];
579 }
580 $this->setInPageArray($pArray[$cEl['uid']]['_nodes'], $rlArr, $row);
581 } else {
582 $pArray[$cEl['uid']]['_templates'][] = $row;
583 }
584 uasort($pArray, function ($a, $b) {
585 return $a['sorting'] - $b['sorting'];
586 });
587 }
588
589 /**
590 * Get the list
591 *
592 * @param array $pArray
593 * @param array $lines
594 * @param int $c
595 * @return array
596 * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0
597 */
598 public function renderList($pArray, $lines = [], $c = 0)
599 {
600 trigger_error(
601 'The method `TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController::renderList` has been deprecated and should not be used any longer, this method will be removed in TYPO3 v10.0',
602 E_USER_DEPRECATED
603 );
604
605 if (!is_array($pArray)) {
606 return $lines;
607 }
608
609 $statusCheckedIcon = $this->moduleTemplate->getIconFactory()
610 ->getIcon('status-status-checked', Icon::SIZE_SMALL)->render();
611 foreach ($pArray as $k => $v) {
612 if (MathUtility::canBeInterpretedAsInteger($k)) {
613 $line = [];
614 $key = $k . '_';
615 $line['marginLeft'] = $c * 20;
616 $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pArray[$k], 30);
617 $line['icon'] = $this->moduleTemplate->getIconFactory()
618 ->getIconForRecord(
619 'pages',
620 BackendUtility::getRecordWSOL('pages', $k),
621 Icon::SIZE_SMALL
622 )->render();
623 if (!empty($pArray[$key])) {
624 $line['href'] = GeneralUtility::linkThisScript(['id' => (int)$k]);
625 $line['title'] = 'ID: ' . (int)$k;
626 $line['count'] = $pArray[$k . '_']['count'];
627 $line['root_max_val'] = ($pArray[$key]['root_max_val'] > 0 ? $statusCheckedIcon : '&nbsp;');
628 $line['root_min_val'] = ($pArray[$key]['root_min_val'] === 0 ? $statusCheckedIcon : '&nbsp;');
629 } else {
630 $line['href'] = '';
631 $line['title'] = '';
632 $line['count'] = '';
633 $line['root_max_val'] = '';
634 $line['root_min_val'] = '';
635 }
636 $lines[] = $line;
637 $lines = $this->renderList($pArray[$k . '.'], $lines, $c + 1);
638 }
639 }
640 return $lines;
641 }
642
643 /**
644 * Returns a new standalone view, shorthand function
645 *
646 * @param string $extensionName
647 * @param string $templateName
648 * @return StandaloneView
649 */
650 protected function getFluidTemplateObject($extensionName, $templateName = 'Main')
651 {
652 /** @var StandaloneView $view */
653 $view = GeneralUtility::makeInstance(StandaloneView::class);
654 $view->getRenderingContext()->getTemplatePaths()->fillDefaultsByPackageName($extensionName);
655 $view->getRenderingContext()->setControllerAction($templateName);
656 $view->getRequest()->setControllerExtensionName('tstemplate');
657 return $view;
658 }
659
660 /**
661 * @param QueryBuilder $queryBuilder
662 * @param string $tableName
663 * @param int $workspaceId
664 */
665 protected function applyWorkspaceConstraint(
666 QueryBuilder $queryBuilder,
667 string $tableName,
668 int $workspaceId
669 ) {
670 if (empty($GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'])) {
671 return;
672 }
673
674 $workspaceIds = [0];
675 if ($workspaceId > 0) {
676 $workspaceIds[] = $workspaceId;
677 }
678 $queryBuilder->andWhere(
679 $queryBuilder->expr()->in(
680 't3ver_wsid',
681 $queryBuilder->createNamedParameter($workspaceIds, Connection::PARAM_INT_ARRAY)
682 ),
683 $queryBuilder->expr()->neq(
684 'pid',
685 $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
686 )
687 );
688 }
689
690 /**
691 * @param string $action
692 * @return string
693 */
694 protected function getHookObjectForAction($action)
695 {
696 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::class][$action])) {
697 return $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::class][$action];
698 }
699 return null;
700 }
701 }