[TASK] Correct directory names for Resources
[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\Core\Page\PageRenderer;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Abstract action controller.
22 */
23 class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
24
25 /**
26 * @var string Key of the extension this controller belongs to
27 */
28 protected $extensionName = 'Workspaces';
29
30 /**
31 * @var PageRenderer
32 */
33 protected $pageRenderer;
34
35 /**
36 * @var int
37 */
38 protected $pageId;
39
40 /**
41 * Initializes the controller before invoking an action method.
42 *
43 * @return void
44 */
45 protected function initializeAction() {
46 // @todo Evaluate how the intval() call can be used with Extbase validators/filters
47 $this->pageId = (int)GeneralUtility::_GP('id');
48 $icons = array(
49 'language' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('flags-multiple'),
50 'integrity' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('status-dialog-information'),
51 'success' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('status-dialog-ok'),
52 'info' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('status-dialog-information'),
53 'warning' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('status-dialog-warning'),
54 'error' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('status-dialog-error')
55 );
56 $this->pageRenderer->addInlineSetting('Workspaces', 'icons', $icons);
57 $this->pageRenderer->addInlineSetting('Workspaces', 'id', $this->pageId);
58 $this->pageRenderer->addInlineSetting('Workspaces', 'depth', $this->pageId === 0 ? 999 : 1);
59 $this->pageRenderer->addInlineSetting('Workspaces', 'language', $this->getLanguageSelection());
60 $this->pageRenderer->addCssFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/Css/module.css');
61 $this->pageRenderer->addInlineLanguageLabelArray(array(
62 'title' => $GLOBALS['LANG']->getLL('title'),
63 'path' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.path'),
64 'table' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.table'),
65 'depth' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_perm.xlf:Depth'),
66 'depth_0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'),
67 'depth_1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'),
68 'depth_2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'),
69 'depth_3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'),
70 'depth_4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_4'),
71 'depth_infi' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
72 ));
73 $this->pageRenderer->addInlineLanguageLabelFile('EXT:workspaces/Resources/Private/Language/locallang.xlf');
74 $this->assignExtensionSettings();
75 }
76
77 /**
78 * Assigns additional Workspace settings to TYPO3.settings.Workspaces.extension
79 *
80 * @return void
81 */
82 protected function assignExtensionSettings() {
83 $extension = array(
84 'AdditionalColumn' => array(
85 'Definition' => array(),
86 'Handler' => array(),
87 ),
88 );
89
90 $extension['AdditionalColumn']['Definition'] = $this->getAdditionalColumnService()->getDefinition();
91 $extension['AdditionalColumn']['Handler'] = $this->getAdditionalColumnService()->getHandler();
92 $this->pageRenderer->addInlineSetting('Workspaces', 'extension', $extension);
93 }
94
95 /**
96 * Processes a general request. The result can be returned by altering the given response.
97 *
98 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request object
99 * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response The response, modified by this handler
100 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException if the controller doesn't support the current request type
101 * @return void
102 */
103 public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) {
104 $this->template = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
105 $this->pageRenderer = $this->getPageRenderer();
106 $GLOBALS['SOBE'] = new \stdClass();
107 $GLOBALS['SOBE']->doc = $this->template;
108 parent::processRequest($request, $response);
109 $pageHeader = $this->template->startpage($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:module.title'));
110 $pageEnd = $this->template->endPage();
111 $response->setContent($pageHeader . $response->getContent() . $pageEnd);
112 }
113
114 /**
115 * Gets the selected language.
116 *
117 * @return string
118 */
119 protected function getLanguageSelection() {
120 $language = 'all';
121 $backendUser = $this->getBackendUser();
122 if (isset($backendUser->uc['moduleData']['Workspaces'][$backendUser->workspace]['language'])) {
123 $language = $backendUser->uc['moduleData']['Workspaces'][$backendUser->workspace]['language'];
124 }
125 return $language;
126 }
127
128 /**
129 * @return \TYPO3\CMS\Workspaces\Service\AdditionalColumnService
130 */
131 protected function getAdditionalColumnService() {
132 return $this->objectManager->get(\TYPO3\CMS\Workspaces\Service\AdditionalColumnService::class);
133 }
134
135 /**
136 * @return \TYPO3\CMS\Workspaces\Service\AdditionalResourceService
137 */
138 protected function getAdditionalResourceService() {
139 return $this->objectManager->get(\TYPO3\CMS\Workspaces\Service\AdditionalResourceService::class);
140 }
141
142 /**
143 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
144 */
145 protected function getBackendUser() {
146 return $GLOBALS['BE_USER'];
147 }
148
149 /**
150 * @return PageRenderer
151 */
152 protected function getPageRenderer() {
153 return GeneralUtility::makeInstance(PageRenderer::class);
154 }
155
156 }