[TASK] Deprecate BaseScriptClass and AbstractFunctionModule
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Module / AbstractFunctionModule.php
1 <?php
2 namespace TYPO3\CMS\Backend\Module;
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\Template\DocumentTemplate;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Localization\LanguageService;
21 use TYPO3\CMS\Core\Page\PageRenderer;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Parent class for 'Extension Objects' in backend modules.
26 *
27 * Used for 'submodules' to other modules. Also called 'Function menu modules'
28 * in \TYPO3\CMS\Core\Utility\ExtensionManagementUtility. And now its even called
29 * 'Extension Objects'. Or 'Module functions'. Wish we had just one name. Or a
30 * name at all...(?) Thank God its not so advanced when it works...
31 *
32 * In other words this class is used for backend modules which is not true
33 * backend modules appearing in the menu but rather adds themselves as a new
34 * entry in the function menu which typically exists for a backend
35 * module (like Web>Info or Tools etc...)
36 * The magic that binds this together is stored in the global variable
37 * $TBE_MODULES_EXT where extensions wanting to connect a module based on
38 * this class to an existing backend module store configuration which consists
39 * of the classname, script-path and a label (title/name).
40 *
41 * For more information about this, please see the large example comment for the
42 * class \TYPO3\CMS\Backend\Module\BaseScriptClass. This will show the principle of a
43 * 'level-1' connection. The more advanced example - having two layers as it is done
44 * with the 'web_info' module - can be seen in the comment above.
45 *
46 * EXAMPLE: One level.
47 * This can be seen in the extension 'frontend' where the info module have a
48 * function added. In 'ext_tables.php' this is done by this function call:
49 *
50 * \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::insertModuleFunction(
51 * 'web_info',
52 * \TYPO3\CMS\Frontend\Controller\PageInformationController::class,
53 * NULL,
54 * 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:mod_tx_cms_webinfo_page'
55 * );
56 *
57 * For this two-level thing to work it also requires that the parent
58 * module (the real backend module) supports it.
59 * This is the case for the modules web_info since it has two
60 * times inclusion sections in their index.php scripts.
61 *
62 * @see \TYPO3\CMS\Backend\Module\BaseScriptClass
63 * @deprecated since v9, will be removed in v10
64 */
65 abstract class AbstractFunctionModule
66 {
67 /**
68 * Contains a reference to the parent (calling) object (which is probably an instance of
69 * an extension class to \TYPO3\CMS\Backend\Module\BaseScriptClass
70 *
71 * @var BaseScriptClass
72 * @see init()
73 */
74 public $pObj;
75
76 /**
77 * @var BaseScriptClass
78 */
79 public $extObj;
80
81 /**
82 * Can be hardcoded to the name of a locallang.xlf file (from the same directory as the class file) to use/load
83 * and is included / added to $GLOBALS['LOCAL_LANG']
84 *
85 * @see init()
86 * @var string
87 */
88 public $localLangFile = '';
89
90 /**
91 * Contains module configuration parts from TBE_MODULES_EXT if found
92 *
93 * @see handleExternalFunctionValue()
94 * @var array
95 */
96 public $extClassConf;
97
98 /**
99 * If this value is set it points to a key in the TBE_MODULES_EXT array (not on the top level..) where another classname/filepath/title can be defined for sub-subfunctions.
100 * This is a little hard to explain, so see it in action; it used in the extension 'func_wizards' in order to provide yet a layer of interfacing with the backend module.
101 * The extension 'func_wizards' has this description: 'Adds the 'Wizards' item to the function menu in Web>Func. This is just a framework for wizard extensions.' - so as you can see it is designed to allow further connectivity - 'level 2'
102 *
103 * @see handleExternalFunctionValue(), \TYPO3\CMS\FuncWizards\Controller\WebFunctionWizardsBaseController
104 * @var string
105 */
106 public $function_key = '';
107
108 /**
109 * @var PageRenderer
110 */
111 protected $pageRenderer;
112
113 /**
114 * Constructor deprecates the class
115 */
116 public function __construct()
117 {
118 trigger_error(
119 'Class AbstractFunctionModule is deprecated and will be removed in TYPO3 v10',
120 E_USER_DEPRECATED
121 );
122 }
123
124 /**
125 * Initialize the object
126 *
127 * @param \object $pObj A reference to the parent (calling) object
128 * @throws \RuntimeException
129 * @see \TYPO3\CMS\Backend\Module\BaseScriptClass::checkExtObj()
130 */
131 public function init($pObj)
132 {
133 $this->pObj = $pObj;
134 // Local lang:
135 if (!empty($this->localLangFile)) {
136 $this->getLanguageService()->includeLLFile($this->localLangFile);
137 }
138 // Setting MOD_MENU items as we need them for logging:
139 $this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->modMenu());
140 }
141
142 /**
143 * If $this->function_key is set (which means there are two levels of object connectivity) then
144 * $this->extClassConf is loaded with the TBE_MODULES_EXT configuration for that sub-sub-module
145 *
146 * @see $function_key, \TYPO3\CMS\FuncWizards\Controller\WebFunctionWizardsBaseController::init()
147 */
148 public function handleExternalFunctionValue()
149 {
150 // Must clean first to make sure the correct key is set...
151 $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
152 if ($this->function_key) {
153 $this->extClassConf = $this->pObj->getExternalItemConfig($this->pObj->MCONF['name'], $this->function_key, $this->pObj->MOD_SETTINGS[$this->function_key]);
154 }
155 }
156
157 /**
158 * Same as \TYPO3\CMS\Backend\Module\BaseScriptClass::checkExtObj()
159 *
160 * @see \TYPO3\CMS\Backend\Module\BaseScriptClass::checkExtObj()
161 */
162 public function checkExtObj()
163 {
164 if (is_array($this->extClassConf) && $this->extClassConf['name']) {
165 $this->extObj = GeneralUtility::makeInstance($this->extClassConf['name']);
166 $this->extObj->init($this->pObj, $this->extClassConf);
167 // Re-write:
168 $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
169 }
170 }
171
172 /**
173 * Calls the main function inside ANOTHER sub-submodule which might exist.
174 */
175 public function extObjContent()
176 {
177 if (is_object($this->extObj)) {
178 return $this->extObj->main();
179 }
180 }
181
182 /**
183 * Dummy function - but is used to set up additional menu items for this submodule.
184 *
185 * @return array A MOD_MENU array which will be merged together with the one from the parent object
186 * @see init(), \TYPO3\CMS\Frontend\Controller\PageInformationController::modMenu()
187 */
188 public function modMenu()
189 {
190 return [];
191 }
192
193 /**
194 * @return LanguageService
195 */
196 protected function getLanguageService()
197 {
198 return $GLOBALS['LANG'];
199 }
200
201 /**
202 * @return BackendUserAuthentication
203 */
204 protected function getBackendUserAuthentication()
205 {
206 return $GLOBALS['BE_USER'];
207 }
208
209 /**
210 * @return DocumentTemplate
211 */
212 protected function getDocumentTemplate()
213 {
214 return $GLOBALS['TBE_TEMPLATE'];
215 }
216
217 /**
218 * @return PageRenderer
219 */
220 protected function getPageRenderer()
221 {
222 if ($this->pageRenderer === null) {
223 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
224 }
225
226 return $this->pageRenderer;
227 }
228 }