TYPO3 CMS  TYPO3_8-7
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 
25 
30 {
42  protected $mode;
43 
49  public $doc;
50 
54  public function __construct()
55  {
56  $GLOBALS['SOBE'] = $this;
57 
58  // Creating backend template object:
59  // this might not be needed but some classes refer to $GLOBALS['SOBE']->doc, so ...
60  $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
61 
62  $this->init();
63  }
64 
68  protected function init()
69  {
70  $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_browse_links.xlf');
71 
72  $this->mode = GeneralUtility::_GP('mode');
73  }
74 
83  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
84  {
85  // Fallback for old calls, which use mode "wizard" or "rte" for link selection
86  if ($this->mode === 'wizard' || $this->mode === 'rte') {
87  return $response->withStatus(303)->withHeader('Location', BackendUtility::getModuleUrl('wizard_link', $_GET));
88  }
89 
90  $response->getBody()->write($this->main());
91  return $response;
92  }
93 
99  public function main()
100  {
101  $content = '';
102 
103  // Render type by user func
104  $browserRendered = false;
105  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
106  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
107  $browserRenderObj = GeneralUtility::getUserObj($classRef);
108  if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
109  if ($browserRenderObj->isValid($this->mode, $this)) {
110  $content = $browserRenderObj->render($this->mode, $this);
111  $browserRendered = true;
112  break;
113  }
114  }
115  }
116  }
117 
118  // if type was not rendered use default rendering functions
119  if (!$browserRendered) {
120  $browser = $this->getElementBrowserInstance();
121 
122  $backendUser = $this->getBackendUser();
123  $modData = $backendUser->getModuleData('browse_links.php', 'ses');
124  list($modData) = $browser->processSessionData($modData);
125  $backendUser->pushModuleData('browse_links.php', $modData);
126 
127  $content = $browser->render();
128  }
129 
130  return $content;
131  }
132 
141  protected function getElementBrowserInstance()
142  {
143  $className = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ElementBrowsers'][$this->mode];
144  $browser = GeneralUtility::makeInstance($className);
145  if (!$browser instanceof ElementBrowserInterface) {
146  throw new \UnexpectedValueException('The specified element browser "' . $className . '" does not implement the required ElementBrowserInterface', 1442763890);
147  }
148  return $browser;
149  }
150 
154  protected function getLanguageService()
155  {
156  return $GLOBALS['LANG'];
157  }
158 
162  protected function getBackendUser()
163  {
164  return $GLOBALS['BE_USER'];
165  }
166 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
mainAction(ServerRequestInterface $request, ResponseInterface $response)