[TASK] The Number of The Workspace
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Controller / AbstractController.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\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 TYPO3\CMS\Backend\View\BackendTemplateView;
18 use TYPO3\CMS\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Page\PageRenderer;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
23 use TYPO3\CMS\Workspaces\Service\AdditionalColumnService;
24 use TYPO3\CMS\Workspaces\Service\AdditionalResourceService;
25
26 /**
27 * Abstract action controller.
28 */
29 class AbstractController extends ActionController
30 {
31 /**
32 * @var string
33 */
34 protected $defaultViewObjectName = BackendTemplateView::class;
35
36 /**
37 * @var BackendTemplateView
38 */
39 protected $view;
40
41 /**
42 * @var string Key of the extension this controller belongs to
43 */
44 protected $extensionName = 'Workspaces';
45
46 /**
47 * @var PageRenderer
48 */
49 protected $pageRenderer;
50
51 /**
52 * @var int
53 */
54 protected $pageId;
55
56 /**
57 * Initializes the controller before invoking an action method.
58 *
59 * @return void
60 */
61 protected function initializeAction()
62 {
63 $this->pageRenderer = $this->getPageRenderer();
64 // @todo Evaluate how the intval() call can be used with Extbase validators/filters
65 $this->pageId = (int)GeneralUtility::_GP('id');
66 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
67 $lang = $this->getLanguageService();
68 $icons = array(
69 'language' => $iconFactory->getIcon('flags-multiple', Icon::SIZE_SMALL)->render(),
70 'integrity' => $iconFactory->getIcon('status-dialog-information', Icon::SIZE_SMALL)->render(),
71 'success' => $iconFactory->getIcon('status-dialog-ok', Icon::SIZE_SMALL)->render(),
72 'info' => $iconFactory->getIcon('status-dialog-information', Icon::SIZE_SMALL)->render(),
73 'warning' => $iconFactory->getIcon('status-dialog-warning', Icon::SIZE_SMALL)->render(),
74 'error' => $iconFactory->getIcon('status-dialog-error', Icon::SIZE_SMALL)->render()
75 );
76 $this->pageRenderer->addInlineSetting('Workspaces', 'icons', $icons);
77 $this->pageRenderer->addInlineSetting('Workspaces', 'id', $this->pageId);
78 $this->pageRenderer->addInlineSetting('Workspaces', 'depth', $this->pageId === 0 ? 999 : 1);
79 $this->pageRenderer->addInlineSetting('Workspaces', 'language', $this->getLanguageSelection());
80 $this->pageRenderer->addInlineLanguageLabelArray([
81 'title' => $lang->getLL('title'),
82 'path' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.path'),
83 'table' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.table'),
84 'depth' => $lang->sL('LLL:EXT:lang/locallang_mod_web_perm.xlf:Depth'),
85 'depth_0' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'),
86 'depth_1' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'),
87 'depth_2' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'),
88 'depth_3' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'),
89 'depth_4' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_4'),
90 'depth_infi' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
91 ]);
92 $this->pageRenderer->addInlineLanguageLabelFile('EXT:workspaces/Resources/Private/Language/locallang.xlf');
93 $this->assignExtensionSettings();
94 }
95
96 /**
97 * Assigns additional Workspace settings to TYPO3.settings.Workspaces.extension
98 *
99 * @return void
100 */
101 protected function assignExtensionSettings()
102 {
103 $extension = array(
104 'AdditionalColumn' => array(
105 'Definition' => array(),
106 'Handler' => array(),
107 ),
108 );
109
110 $extension['AdditionalColumn']['Definition'] = $this->getAdditionalColumnService()->getDefinition();
111 $extension['AdditionalColumn']['Handler'] = $this->getAdditionalColumnService()->getHandler();
112 $this->pageRenderer->addInlineSetting('Workspaces', 'extension', $extension);
113 }
114
115 /**
116 * Gets the selected language.
117 *
118 * @return string
119 */
120 protected function getLanguageSelection()
121 {
122 $language = 'all';
123 $backendUser = $this->getBackendUser();
124 if (isset($backendUser->uc['moduleData']['Workspaces'][$backendUser->workspace]['language'])) {
125 $language = $backendUser->uc['moduleData']['Workspaces'][$backendUser->workspace]['language'];
126 }
127 return $language;
128 }
129
130 /**
131 * @return AdditionalColumnService
132 */
133 protected function getAdditionalColumnService()
134 {
135 return $this->objectManager->get(AdditionalColumnService::class);
136 }
137
138 /**
139 * @return AdditionalResourceService
140 */
141 protected function getAdditionalResourceService()
142 {
143 return $this->objectManager->get(AdditionalResourceService::class);
144 }
145
146 /**
147 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
148 */
149 protected function getBackendUser()
150 {
151 return $GLOBALS['BE_USER'];
152 }
153
154 /**
155 * @return \TYPO3\CMS\Lang\LanguageService
156 */
157 protected function getLanguageService()
158 {
159 return $GLOBALS['LANG'];
160 }
161
162 /**
163 * @return PageRenderer
164 */
165 protected function getPageRenderer()
166 {
167 return GeneralUtility::makeInstance(PageRenderer::class);
168 }
169 }