‪TYPO3CMS  9.5
ElementBrowserController.php
Go to the documentation of this file.
1 <?php
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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
28 
34 {
36 
40  private ‪$deprecatedPublicMethods = [
41  'main' => 'Using ElementBrowserController::main() is deprecated and will not be possible anymore in TYPO3 v10.0.',
42  ];
43 
55  protected ‪$mode;
56 
62  public ‪$doc;
63 
67  public function ‪__construct()
68  {
69  ‪$GLOBALS['SOBE'] = $this;
70 
71  // Creating backend template object:
72  // this might not be needed but some classes refer to $GLOBALS['SOBE']->doc, so ...
73  $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
74 
75  $this->‪init();
76  }
77 
81  protected function ‪init()
82  {
83  $this->‪getLanguageService()->‪includeLLFile('EXT:recordlist/Resources/Private/Language/locallang_browse_links.xlf');
84 
85  $this->mode = GeneralUtility::_GP('mode');
86  }
87 
95  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
96  {
97  // Fallback for old calls, which use mode "wizard" or "rte" for link selection
98  if ($this->mode === 'wizard' || $this->mode === 'rte') {
99  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
100  return new ‪RedirectResponse((string)$uriBuilder->buildUriFromRoute('wizard_link', $_GET), 303);
101  }
102  return new HtmlResponse($this->‪main());
103  }
104 
110  protected function ‪main()
111  {
112  $content = '';
113 
114  // Render type by user func
115  $browserRendered = false;
116  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] ?? [] as $className) {
117  $browserRenderObj = GeneralUtility::makeInstance($className);
118  if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
119  if ($browserRenderObj->isValid($this->mode, $this)) {
120  $content = $browserRenderObj->render($this->mode, $this);
121  $browserRendered = true;
122  break;
123  }
124  }
125  }
126 
127  // if type was not rendered use default rendering functions
128  if (!$browserRendered) {
129  $browser = $this->‪getElementBrowserInstance();
130 
131  $backendUser = $this->‪getBackendUser();
132  $modData = $backendUser->getModuleData('browse_links.php', 'ses');
133  list($modData) = $browser->processSessionData($modData);
134  $backendUser->pushModuleData('browse_links.php', $modData);
135 
136  $content = $browser->render();
137  }
138 
139  return $content;
140  }
141 
150  protected function ‪getElementBrowserInstance()
151  {
152  $className = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ElementBrowsers'][‪$this->mode];
153  $browser = GeneralUtility::makeInstance($className);
154  if (!$browser instanceof ElementBrowserInterface) {
155  throw new \UnexpectedValueException('The specified element browser "' . $className . '" does not implement the required ElementBrowserInterface', 1442763890);
156  }
157  return $browser;
158  }
159 
163  protected function ‪getLanguageService()
164  {
165  return ‪$GLOBALS['LANG'];
166  }
167 
171  protected function ‪getBackendUser()
172  {
173  return ‪$GLOBALS['BE_USER'];
174  }
175 }
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\$doc
‪DocumentTemplate $doc
Definition: ElementBrowserController.php:58
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\getLanguageService
‪LanguageService getLanguageService()
Definition: ElementBrowserController.php:159
‪TYPO3\CMS\Recordlist\Browser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:18
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController
Definition: ElementBrowserController.php:34
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\getElementBrowserInstance
‪ElementBrowserInterface getElementBrowserInstance()
Definition: ElementBrowserController.php:146
‪TYPO3\CMS\Backend\Template\DocumentTemplate
Definition: DocumentTemplate.php:48
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ElementBrowserController.php:167
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Recordlist\Controller
Definition: AbstractLinkBrowserController.php:2
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\main
‪string main()
Definition: ElementBrowserController.php:106
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\__construct
‪__construct()
Definition: ElementBrowserController.php:63
‪TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait
Definition: PublicMethodDeprecationTrait.php:68
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\$deprecatedPublicMethods
‪array $deprecatedPublicMethods
Definition: ElementBrowserController.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\init
‪init()
Definition: ElementBrowserController.php:77
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: ElementBrowserController.php:91
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25
‪TYPO3\CMS\Recordlist\Controller\ElementBrowserController\$mode
‪string $mode
Definition: ElementBrowserController.php:52