‪TYPO3CMS  9.5
AdminPanelView.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
27 
34 {
40  protected ‪$ext_forcePreview = false;
41 
47  protected ‪$modules = [];
48 
52  protected ‪$configuration;
53 
61  public function ‪setModules(array ‪$modules): void
62  {
63  $this->modules = ‪$modules;
64  }
65 
71  protected function ‪getLanguageService()
72  {
73  return ‪$GLOBALS['LANG'];
74  }
75 
81  protected function ‪getBackendUser()
82  {
83  return ‪$GLOBALS['BE_USER'];
84  }
85 
86  /*****************************************************
87  * Admin Panel: Deprecated API
88  ****************************************************/
89 
98  public function ‪callDeprecatedHookObject(): string
99  {
100  $moduleContent = '';
101  if (‪StateUtility::isOpen()) {
102  foreach ($this->modules as $module) {
103  $moduleContent .= $this->‪getModule($module);
104  }
105 
106  foreach (
107  ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel']
108  ??
109  [] as $className
110  ) {
111  trigger_error(
112  'The hook $GLOBALS[TYPO3_CONF_VARS][SC_OPTIONS][tslib/class.tslib_adminpanel.php][extendAdminPanel] will be removed in TYPO3 v10.0, register an AdminPanelModule instead.',
113  E_USER_DEPRECATED
114  );
115  $hookObject = GeneralUtility::makeInstance($className);
116  if (!$hookObject instanceof ‪AdminPanelViewHookInterface) {
117  throw new \UnexpectedValueException(
118  $className . ' must implement interface ' . AdminPanelViewHookInterface::class,
119  1311942539
120  );
121  }
122  $content = $hookObject->extendAdminPanel($moduleContent, $this);
123  if ($content) {
124  $moduleContent .= '<div class="typo3-adminPanel-section typo3-adminPanel-section-open">';
125  $moduleContent .= ' <div class="typo3-adminPanel-section-body">';
126  $moduleContent .= ' ' . $content;
127  $moduleContent .= ' </div>';
128  $moduleContent .= '</div>';
129  }
130  }
131  }
132  return $moduleContent;
133  }
134 
142  protected function ‪getModule(‪ModuleInterface $module): string
143  {
144  ‪$output = [];
145 
146  if ($module instanceof ‪ConfigurableInterface && $module->isEnabled()) {
147  ‪$output[] = '<div class="typo3-adminPanel-section typo3-adminPanel-section-open">';
148  ‪$output[] = ' <div class="typo3-adminPanel-section-title">';
149  ‪$output[] = ' ' . $this->‪getSectionOpenerLink($module);
150  ‪$output[] = ' </div>';
151  ‪$output[] = '<div class="typo3-adminPanel-section-body">';
152  ‪$output[] = ' ' . $module->getContent();
153  ‪$output[] = '</div>';
154  ‪$output[] = '</div>';
155  }
156 
157  if ($module instanceof ‪DataProviderInterface) {
158  foreach ($module->getJavaScriptFiles() as $javaScriptFile) {
159  ‪$output[] =
160  '<script src="' .
161  ‪PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName($javaScriptFile)) .
162  '"></script>';
163  }
164  }
165 
166  return implode('', ‪$output);
167  }
168 
169  /*****************************************************
170  * Admin Panel Layout Helper functions
171  ****************************************************/
172 
180  protected function ‪getSectionOpenerLink(‪ModuleInterface $module): string
181  {
182  $identifier = $module->‪getIdentifier();
183  $onclick = 'document.TSFE_ADMIN_PANEL_FORM[' .
184  GeneralUtility::quoteJSvalue('TSFE_ADMIN_PANEL[display_' . $identifier . ']') .
185  '].value=' .
186  ($this->‪getBackendUser()->uc['AdminPanel']['display_' . $identifier] ? '0' : '1') .
187  ';document.TSFE_ADMIN_PANEL_FORM.submit();return false;';
188 
189  ‪$output = [];
190  ‪$output[] = '<span class="typo3-adminPanel-section-title-identifier"></span>';
191  ‪$output[] = '<a href="javascript:void(0)" onclick="' . htmlspecialchars($onclick) . '">';
192  ‪$output[] = ' ' . htmlspecialchars($module->‪getLabel());
193  ‪$output[] = '</a>';
194  ‪$output[] = '<input type="hidden" name="TSFE_ADMIN_PANEL[display_' .
195  $identifier .
196  ']" value="' .
197  1 .
198  '" />';
199 
200  return implode('', ‪$output);
201  }
202 
209  public function ‪ext_makeToolBar(): string
210  {
211  trigger_error(
212  'AdminPanelView::ext_makeToolBar() will be removed in TYPO3 v10.0, use fluid and backend uri builder to create a toolbar.',
213  E_USER_DEPRECATED
214  );
215  $editToolbarService = GeneralUtility::makeInstance(EditToolbarService::class);
216  return $editToolbarService->createToolbar();
217  }
218 
227  protected function ‪extGetLL($key, $convertWithHtmlspecialchars = true)
228  {
229  $labelStr = $this->‪getLanguageService()->getLL($key);
230  if ($convertWithHtmlspecialchars) {
231  $labelStr = htmlspecialchars($labelStr);
232  }
233  return $labelStr;
234  }
235 
242  public function ‪getAdminPanelHeaderData()
243  {
244  trigger_error(
245  'AdminPanelView->getAdminPanelHeaderData() will be removed in TYPO3 v10.0. Implement AdminPanelModules via the new API (see AdminPanelModuleInterface).',
246  E_USER_DEPRECATED
247  );
248  $result = '';
249  if (!empty(‪$GLOBALS['TBE_STYLES']['stylesheets']['admPanel'])) {
250  $stylesheet = GeneralUtility::locationHeaderUrl(‪$GLOBALS['TBE_STYLES']['stylesheets']['admPanel']);
251  $result = '<link rel="stylesheet" type="text/css" href="' .
252  htmlspecialchars($stylesheet, ENT_QUOTES | ENT_HTML5) . '" />';
253  }
254  return $result;
255  }
256 
264  public function ‪isAdminModuleEnabled($key)
265  {
266  trigger_error(
267  'AdminPanelView->isAdminModuleEnabled() will be removed in TYPO3 v10.0. Implement AdminPanelModules via the new API (see AdminPanelModuleInterface).',
268  E_USER_DEPRECATED
269  );
270  $result = false;
271  // Returns TRUE if the module checked is "preview" and the forcePreview flag is set.
272  if ($key === 'preview' && $this->ext_forcePreview) {
273  $result = true;
274  } elseif (!empty($this->configuration['enable.']['all'])) {
275  $result = true;
276  } elseif (!empty($this->configuration['enable.'][$key])) {
277  $result = true;
278  }
279  return $result;
280  }
281 
287  public function ‪saveConfigOptions()
288  {
289  trigger_error(
290  'AdminPanelView->saveConfigOptions() will be removed in TYPO3 v10.0. Implement AdminPanelModules via the new API (see AdminPanelModuleInterface).',
291  E_USER_DEPRECATED
292  );
293  $input = GeneralUtility::_GP('TSFE_ADMIN_PANEL');
294  $beUser = $this->‪getBackendUser();
295  if (is_array($input)) {
296  // Setting
297  $beUser->uc['AdminPanel'] = array_merge(
298  !is_array($beUser->uc['AdminPanel']) ? [] : $beUser->uc['AdminPanel'],
299  $input
300  );
301  unset($beUser->uc['AdminPanel']['action']);
302 
303  foreach ($this->modules as $module) {
304  if ($module->isEnabled()) {
305  // We use TYPO3_REQUEST for compatibility reasons. The object and this method are deprecated anyway, this should be fine.
306  $module->onSubmit($input, ‪$GLOBALS['TYPO3_REQUEST']);
307  }
308  }
309  // Saving
310  $beUser->writeUC();
311  // Flush fluid template cache
312  $cacheManager = new ‪CacheManager();
313  $cacheManager->setCacheConfigurations(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
314  $cacheManager->getCache('fluid_template')->flush();
315  }
316  }
317 
326  public function ‪extGetFeAdminValue($sectionName, $val = '')
327  {
328  trigger_error(
329  'AdminPanelView->extGetFeAdminValue() will be removed in TYPO3 v10.0. Implement AdminPanelModules via the new API (see AdminPanelModuleInterface).',
330  E_USER_DEPRECATED
331  );
332  if (!$this->‪isAdminModuleEnabled($sectionName)) {
333  return null;
334  }
335 
336  $beUser = $this->‪getBackendUser();
337  // Exceptions where the values can be overridden (forced) from backend:
338  // deprecated
339  if (
340  $sectionName === 'edit' && (
341  $val === 'displayIcons' && $this->configuration['module.']['edit.']['forceDisplayIcons'] ||
342  $val === 'displayFieldIcons' && $this->configuration['module.']['edit.']['forceDisplayFieldIcons'] ||
343  $val === 'editNoPopup' && $this->configuration['module.']['edit.']['forceNoPopup']
344  )
345  ) {
346  return true;
347  }
348 
349  // Override all settings with user TSconfig
350  if ($val && isset($this->configuration['override.'][$sectionName . '.'][$val])) {
351  return $this->configuration['override.'][$sectionName . '.'][$val];
352  }
353  if (!$val && isset($this->configuration['override.'][$sectionName])) {
354  return $this->configuration['override.'][$sectionName];
355  }
356 
357  $returnValue = $val ? $beUser->uc['AdminPanel'][$sectionName . '_' . $val] : 1;
358 
359  // Exception for preview
360  if ($sectionName === 'preview' && $this->ext_forcePreview) {
361  return !$val ? true : $returnValue;
362  }
363 
364  // See if the menu is expanded!
365  return $this->‪isAdminModuleOpen($sectionName) ? $returnValue : null;
366  }
367 
373  public function ‪forcePreview()
374  {
375  trigger_error(
376  'AdminPanelView->forcePreview() will be removed in TYPO3 v10.0. Use new AdminPanel Preview Module instead.',
377  E_USER_DEPRECATED
378  );
379  $this->ext_forcePreview = true;
380  }
381 
389  public function ‪isAdminModuleOpen($key)
390  {
391  trigger_error(
392  'AdminPanelView->isAdminModuleOpen() will be removed in TYPO3 v10.0. Use new AdminPanel API instead.',
393  E_USER_DEPRECATED
394  );
395  return $this->‪getBackendUser()->uc['AdminPanel']['display_top'] &&
396  $this->‪getBackendUser()->uc['AdminPanel']['display_' . $key];
397  }
398 
412  public function ‪extGetItem($title, $content = '', $checkbox = '', $outerDivClass = null, $innerDivClass = null)
413  {
414  trigger_error(
415  'AdminPanelView->extGetItem() will be removed in TYPO3 v10.0. Use new AdminPanel API instead.',
416  E_USER_DEPRECATED
417  );
418  $title = $title ? '<label for="' . htmlspecialchars($title) . '">' . $this->‪extGetLL($title) . '</label>' : '';
419  $out = '';
420  $out .= (string)$outerDivClass ? '<div class="' . htmlspecialchars($outerDivClass) . '">' : '<div>';
421  $out .= (string)$innerDivClass ? '<div class="' . htmlspecialchars($innerDivClass) . '">' : '<div>';
422  $out .= $checkbox . $title . $content . '</div></div>';
423  return $out;
424  }
425 
436  public function ‪extGetHead($sectionSuffix)
437  {
438  trigger_error(
439  'AdminPanelView->extGetHead() will be removed in TYPO3 v10.0. Use new AdminPanel API instead.',
440  E_USER_DEPRECATED
441  );
442  return $this->‪linkSectionHeader($sectionSuffix, $this->‪extGetLL($sectionSuffix));
443  }
444 
455  public function ‪linkSectionHeader($sectionSuffix, $sectionTitle, $className = '')
456  {
457  trigger_error(
458  'AdminPanelView->linkSectionHeader() will be removed in TYPO3 v10.0. Use new AdminPanel API instead.',
459  E_USER_DEPRECATED
460  );
461  $onclick = 'document.TSFE_ADMIN_PANEL_FORM[' .
462  GeneralUtility::quoteJSvalue('TSFE_ADMIN_PANEL[display_' . $sectionSuffix . ']') .
463  '].value=' .
464  ($this->‪getBackendUser()->uc['AdminPanel']['display_' . $sectionSuffix] ? '0' : '1') .
465  ';document.TSFE_ADMIN_PANEL_FORM.submit();return false;';
466 
467  ‪$output = [];
468  ‪$output[] = '<span class="typo3-adminPanel-section-title-identifier"></span>';
469  ‪$output[] = '<a href="javascript:void(0)" onclick="' . htmlspecialchars($onclick) . '">';
470  ‪$output[] = ' ' . $sectionTitle;
471  ‪$output[] = '</a>';
472  ‪$output[] = '<input type="hidden" name="TSFE_ADMIN_PANEL[display_' .
473  $sectionSuffix .
474  ']" value="' .
475  (int)$this->‪isAdminModuleOpen($sectionSuffix) .
476  '" />';
477 
478  return implode('', ‪$output);
479  }
480 }
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\getBackendUser
‪FrontendBackendUserAuthentication getBackendUser()
Definition: AdminPanelView.php:78
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\isAdminModuleEnabled
‪bool isAdminModuleEnabled($key)
Definition: AdminPanelView.php:261
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:23
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\extGetItem
‪string extGetItem($title, $content='', $checkbox='', $outerDivClass=null, $innerDivClass=null)
Definition: AdminPanelView.php:409
‪TYPO3\CMS\Adminpanel\Service\EditToolbarService
Definition: EditToolbarService.php:39
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:35
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\getAdminPanelHeaderData
‪string getAdminPanelHeaderData()
Definition: AdminPanelView.php:239
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\setModules
‪setModules(array $modules)
Definition: AdminPanelView.php:58
‪TYPO3\CMS\Adminpanel\View\AdminPanelView
Definition: AdminPanelView.php:34
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\callDeprecatedHookObject
‪string callDeprecatedHookObject()
Definition: AdminPanelView.php:95
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\isAdminModuleOpen
‪bool isAdminModuleOpen($key)
Definition: AdminPanelView.php:386
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: AdminPanelView.php:68
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface
Definition: ConfigurableInterface.php:28
‪TYPO3\CMS\Adminpanel\ModuleApi\DataProviderInterface
Definition: DataProviderInterface.php:29
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\getModule
‪string getModule(ModuleInterface $module)
Definition: AdminPanelView.php:139
‪TYPO3\CMS\Adminpanel\Utility\StateUtility
Definition: StateUtility.php:27
‪TYPO3\CMS\Adminpanel\View\AdminPanelViewHookInterface
Definition: AdminPanelViewHookInterface.php:23
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\extGetLL
‪string extGetLL($key, $convertWithHtmlspecialchars=true)
Definition: AdminPanelView.php:224
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\forcePreview
‪forcePreview()
Definition: AdminPanelView.php:370
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\getSectionOpenerLink
‪string getSectionOpenerLink(ModuleInterface $module)
Definition: AdminPanelView.php:177
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\$configuration
‪array $configuration
Definition: AdminPanelView.php:49
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface
Definition: ModuleInterface.php:25
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\ext_makeToolBar
‪string ext_makeToolBar()
Definition: AdminPanelView.php:206
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\saveConfigOptions
‪saveConfigOptions()
Definition: AdminPanelView.php:284
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\$ext_forcePreview
‪bool $ext_forcePreview
Definition: AdminPanelView.php:39
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\$modules
‪TYPO3 CMS Adminpanel ModuleApi ModuleInterface[] $modules
Definition: AdminPanelView.php:45
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface\getLabel
‪string getLabel()
‪TYPO3\CMS\Adminpanel\Utility\StateUtility\isOpen
‪static bool isOpen()
Definition: StateUtility.php:54
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\extGetFeAdminValue
‪mixed extGetFeAdminValue($sectionName, $val='')
Definition: AdminPanelView.php:323
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:42
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface\getIdentifier
‪string getIdentifier()
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\linkSectionHeader
‪string linkSectionHeader($sectionSuffix, $sectionTitle, $className='')
Definition: AdminPanelView.php:452
‪TYPO3\CMS\Adminpanel\View\AdminPanelView\extGetHead
‪string extGetHead($sectionSuffix)
Definition: AdminPanelView.php:433
‪TYPO3\CMS\Adminpanel\View
Definition: AdminPanelView.php:3