TYPO3 CMS  TYPO3_8-7
AbstractElementBrowser.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 
26 
32 abstract class AbstractElementBrowser
33 {
37  protected $doc;
38 
42  protected $pageRenderer = null;
43 
49  protected $thisScript = '';
50 
54  protected $iconFactory;
55 
77  protected $bparams;
78 
82  public function __construct()
83  {
84  $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
85  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
86  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
87  $this->pageRenderer->loadJquery();
88  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/ElementBrowser');
89 
90  $this->initialize();
91  }
92 
96  protected function initialize()
97  {
98  $this->determineScriptUrl();
99  $this->initVariables();
100  }
101 
105  protected function determineScriptUrl()
106  {
107  if ($routePath = GeneralUtility::_GP('route')) {
108  $router = GeneralUtility::makeInstance(Router::class);
109  $route = $router->match($routePath);
110  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
111  $this->thisScript = (string)$uriBuilder->buildUriFromRoute($route->getOption('_identifier'));
112  } elseif ($moduleName = GeneralUtility::_GP('M')) {
113  $this->thisScript = BackendUtility::getModuleUrl($moduleName);
114  } else {
115  $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
116  }
117  }
118 
121  protected function initVariables()
122  {
123  $this->bparams = GeneralUtility::_GP('bparams');
124  if ($this->bparams === null) {
125  $this->bparams = '';
126  }
127  }
128 
132  protected function initDocumentTemplate()
133  {
134  $bodyDataAttributes = array_merge(
135  $this->getBParamDataAttributes(),
136  $this->getBodyTagAttributes()
137  );
138  foreach ($bodyDataAttributes as $attributeName => $value) {
139  $this->doc->bodyTagAdditions .= ' ' . $attributeName . '="' . htmlspecialchars($value) . '"';
140  }
141 
142  // unset the default jumpToUrl() function as we ship our own
143  unset($this->doc->JScodeArray['jumpToUrl']);
144  }
145 
149  abstract protected function getBodyTagAttributes();
150 
156  protected function getBParamDataAttributes()
157  {
158  list($fieldRef, $rteParams, $rteConfig, , $irreObjectId, $irreCheckUniqueAction, $irreAddAction, $irreInsertAction) = explode('|', $this->bparams);
159 
160  return [
161  'data-this-script-url' => strpos($this->thisScript, '?') === false ? $this->thisScript . '?' : $this->thisScript . '&',
162  'data-form-field-name' => 'data[' . $fieldRef . '][' . $rteParams . '][' . $rteConfig . ']',
163  'data-field-reference' => $fieldRef,
164  'data-field-reference-slashed' => addslashes($fieldRef),
165  'data-rte-parameters' => $rteParams,
166  'data-rte-configuration' => $rteConfig,
167  'data-irre-object-id' => $irreObjectId,
168  'data-irre-check-unique-action' => $irreCheckUniqueAction,
169  'data-irre-add-action' => $irreAddAction,
170  'data-irre-insert-action' => $irreInsertAction,
171  ];
172  }
173 
177  protected function getLanguageService()
178  {
179  return $GLOBALS['LANG'];
180  }
181 
185  protected function getBackendUser()
186  {
187  return $GLOBALS['BE_USER'];
188  }
189 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']