‪TYPO3CMS  11.5
ElementBrowserController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
27 
33 {
45  protected string ‪$mode = '';
46 
54  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
55  {
56  $this->‪getLanguageService()->‪includeLLFile('EXT:recordlist/Resources/Private/Language/locallang_browse_links.xlf');
57  $this->mode = $request->getQueryParams()['mode'] ?? $request->getQueryParams()['mode'] ?? '';
58  // Fallback for old calls, which use mode "wizard" or "rte" for link selection
59  if ($this->mode === 'wizard' || $this->mode === 'rte') {
60  trigger_error('Calling ElementBrowserController::mainAction with "wizard" or "mode" as values will be removed in TYPO3 v12.0. Link to the "wizard_link" instead.', E_USER_DEPRECATED);
61  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
62  return new ‪RedirectResponse((string)$uriBuilder->buildUriFromRoute('wizard_link', $_GET), 303);
63  }
64  return new ‪HtmlResponse($this->‪main($request));
65  }
66 
72  protected function ‪main(ServerRequestInterface $request)
73  {
74  $content = '';
75 
76  // Render type by user func
77  $browserRendered = false;
78 
79  // @deprecated will be removed in TYPO3 v12.0.
80  if (!empty(‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] ?? [])) {
81  trigger_error('$TYPO3_CONF_VARS[SC_OPTIONS][typo3/browse_links.php][browserRendering] will be removed in TYPO3 v12.0. Use a custom ElementBrowser, as introduced in TYPO3 7.6, instead.', E_USER_DEPRECATED);
82  }
83  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] ?? [] as $className) {
84  $browserRenderObj = GeneralUtility::makeInstance($className);
85  if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
86  if ($browserRenderObj->isValid($this->mode, $this)) {
87  $content = $browserRenderObj->render($this->mode, $this);
88  $browserRendered = true;
89  break;
90  }
91  }
92  }
93 
94  // if type was not rendered use default rendering functions
95  if (!$browserRendered) {
96  $browser = $this->‪getElementBrowserInstance();
97  if (is_callable([$browser, 'setRequest'])) {
98  $browser->setRequest($request);
99  }
100 
101  $backendUser = $this->‪getBackendUser();
102  $modData = $backendUser->getModuleData('browse_links.php', 'ses');
103  [$modData] = $browser->processSessionData($modData);
104  $backendUser->pushModuleData('browse_links.php', $modData);
105 
106  $content = $browser->render();
107  }
108 
109  return $content;
110  }
111 
118  protected function ‪getElementBrowserInstance()
119  {
120  $className = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ElementBrowsers'][‪$this->mode];
121  $browser = GeneralUtility::makeInstance($className);
122  if (!$browser instanceof ‪ElementBrowserInterface) {
123  throw new \UnexpectedValueException('The specified element browser "' . $className . '" does not implement the required ElementBrowserInterface', 1442763890);
124  }
125  return $browser;
126  }
127 
131  protected function ‪getLanguageService()
132  {
133  return ‪$GLOBALS['LANG'];
134  }
135 
139  protected function ‪getBackendUser()
140  {
141  return ‪$GLOBALS['BE_USER'];
142  }
143 }
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\main
‪string main(ServerRequestInterface $request)
Definition: ElementBrowserController.php:72
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\getLanguageService
‪LanguageService getLanguageService()
Definition: ElementBrowserController.php:131
‪TYPO3\CMS\Recordlist\Browser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:19
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController
Definition: ElementBrowserController.php:33
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\getElementBrowserInstance
‪ElementBrowserInterface getElementBrowserInstance()
Definition: ElementBrowserController.php:118
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ElementBrowserController.php:139
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Recordlist\Controller
Definition: AbstractLinkBrowserController.php:16
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef)
Definition: LanguageService.php:271
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: ElementBrowserController.php:54
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\$mode
‪string $mode
Definition: ElementBrowserController.php:45