‪TYPO3CMS  10.4
DatabaseBrowser.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 
26 
32 {
40  protected ‪$expandPage;
41 
42  protected function ‪initialize()
43  {
44  parent::initialize();
45  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/BrowseDatabase');
46  }
47 
48  protected function ‪initVariables()
49  {
50  parent::initVariables();
51  $this->expandPage = GeneralUtility::_GP('expandPage');
52  }
53 
60  public function ‪processSessionData($data)
61  {
62  if ($this->expandPage !== null) {
63  $data['expandPage'] = ‪$this->expandPage;
64  $store = true;
65  } else {
66  $this->expandPage = (int)$data['expandPage'];
67  $store = false;
68  }
69  return [$data, $store];
70  }
71 
75  public function ‪render()
76  {
77  $userTsConfig = $this->‪getBackendUser()->‪getTSConfig();
78 
79  $this->‪setTemporaryDbMounts();
80  [, , , $allowedTables] = explode('|', $this->bparams);
81 
82  $pageTree = GeneralUtility::makeInstance(ElementBrowserPageTreeView::class);
83  $pageTree->setLinkParameterProvider($this);
84  $pageTree->ext_pArrPages = $allowedTables === 'pages';
85  $pageTree->ext_showNavTitle = (bool)($userTsConfig['options.']['pageTree.']['showNavTitle'] ?? false);
86  $pageTree->ext_showPageId = (bool)($userTsConfig['options.']['pageTree.']['showPageIdWithTitle'] ?? false);
87  $pageTree->ext_showPathAboveMounts = (bool)($userTsConfig['options.']['pageTree.']['showPathAboveMounts'] ?? false);
88  $pageTree->addField('nav_title');
89  $tree = $pageTree->getBrowsableTree();
90 
91  $withTree = true;
92  if ($allowedTables !== '' && $allowedTables !== '*') {
93  $tablesArr = ‪GeneralUtility::trimExplode(',', $allowedTables, true);
94  $onlyRootLevel = true;
95  foreach ($tablesArr as $currentTable) {
96  if (isset(‪$GLOBALS['TCA'][$currentTable])) {
97  if (!isset(‪$GLOBALS['TCA'][$currentTable]['ctrl']['rootLevel']) || (int)‪$GLOBALS['TCA'][$currentTable]['ctrl']['rootLevel'] !== 1) {
98  $onlyRootLevel = false;
99  }
100  }
101  }
102  if ($onlyRootLevel) {
103  $withTree = false;
104  // page to work on is root
105  $this->expandPage = 0;
106  }
107  }
108 
109  $renderedRecordList = $this->‪renderTableRecords($allowedTables);
110 
111  $this->‪setBodyTagParameters();
112 
113  $this->moduleTemplate->setTitle($this->‪getLanguageService()->getLL('recordSelector'));
114  $view = $this->moduleTemplate->getView();
115  $view->assignMultiple([
116  'treeEnabled' => $withTree,
117  'temporaryTreeMountCancelUrl' => $this->‪getTemporaryTreeMountCancelNotice(),
118  'tree' => $tree,
119  'content' => $renderedRecordList
120  ]);
121  return $this->moduleTemplate->renderContent();
122  }
123 
129  protected function ‪getTemporaryTreeMountCancelNotice()
130  {
131  if ((int)$this->‪getBackendUser()->getSessionData('pageTree_temporaryMountPoint') === 0) {
132  return '';
133  }
134  return GeneralUtility::linkThisScript(['setTempDBmount' => 0]);
135  }
136 
140  protected function ‪setTemporaryDbMounts()
141  {
142  $backendUser = $this->‪getBackendUser();
143 
144  // Clear temporary DB mounts
145  $tmpMount = GeneralUtility::_GET('setTempDBmount');
146  if (isset($tmpMount)) {
147  $backendUser->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
148  }
149 
150  $backendUser->initializeWebmountsForElementBrowser();
151  }
152 
159  protected function ‪renderTableRecords($tables)
160  {
161  $backendUser = $this->‪getBackendUser();
162  if ($this->expandPage === null || $this->expandPage < 0 || !$backendUser->isInWebMount($this->expandPage)) {
163  return '';
164  }
165  // Set array with table names to list:
166  if (trim($tables) === '*') {
167  $tablesArr = array_keys(‪$GLOBALS['TCA']);
168  } else {
169  $tablesArr = ‪GeneralUtility::trimExplode(',', $tables, true);
170  }
171 
172  $out = '';
173  // Create the header, showing the current page for which the listing is.
174  // Includes link to the page itself, if pages are amount allowed tables.
175  $titleLen = (int)$backendUser->uc['titleLen'];
176  $mainPageRecord = ‪BackendUtility::getRecordWSOL('pages', $this->expandPage);
177  if (is_array($mainPageRecord)) {
178  $pText = htmlspecialchars(GeneralUtility::fixed_lgd_cs($mainPageRecord['title'], $titleLen));
179 
180  $out .= '<p>' . $this->iconFactory->getIconForRecord('pages', $mainPageRecord, ‪Icon::SIZE_SMALL)->render() . '&nbsp;';
181  if (in_array('pages', $tablesArr, true)) {
182  $out .= '<span data-uid="' . htmlspecialchars($mainPageRecord['uid']) . '" data-table="pages" data-title="' . htmlspecialchars($mainPageRecord['title']) . '" data-icon="">';
183  $out .= '<a href="#" data-close="0">'
184  . $this->iconFactory->getIcon('actions-add', ‪Icon::SIZE_SMALL)->render()
185  . '</a>'
186  . '<a href="#" data-close="1">'
187  . $pText
188  . '</a>';
189  $out .= '</span>';
190  } else {
191  $out .= $pText;
192  }
193  $out .= '</p>';
194  }
195 
196  $permsClause = $backendUser->getPagePermsClause(‪Permission::PAGE_SHOW);
197  $pageInfo = ‪BackendUtility::readPageAccess($this->expandPage, $permsClause);
198 
200  $dbList = GeneralUtility::makeInstance(ElementBrowserRecordList::class);
201  $dbList->setOverrideUrlParameters($this->‪getUrlParameters([]));
202  $dbList->thisScript = ‪$this->thisScript;
203  $dbList->thumbs = false;
204  $dbList->setIsEditable(false);
205  $dbList->calcPerms = $backendUser->calcPerms($pageInfo);
206  $dbList->noControlPanels = true;
207  $dbList->clickMenuEnabled = false;
208  $dbList->tableList = implode(',', $tablesArr);
209 
210  // a string like "data[pages][79][storage_pid]"
211  [$fieldPointerString] = explode('|', $this->bparams);
212  // parts like: data, pages], 79], storage_pid]
213  $fieldPointerParts = explode('[', $fieldPointerString);
214  $relatingTableName = substr($fieldPointerParts[1], 0, -1);
215  $relatingFieldName = substr($fieldPointerParts[3], 0, -1);
216  if ($relatingTableName && $relatingFieldName) {
217  $dbList->setRelatingTableAndField($relatingTableName, $relatingFieldName);
218  }
219 
220  $dbList->start(
221  $this->expandPage,
222  GeneralUtility::_GP('table'),
223  ‪MathUtility::forceIntegerInRange(GeneralUtility::_GP('pointer'), 0, 100000),
224  GeneralUtility::_GP('search_field'),
225  GeneralUtility::_GP('search_levels'),
226  GeneralUtility::_GP('showLimit')
227  );
228 
229  $dbList->setDispFields();
230  $dbList->generateList();
231 
232  $out .= $dbList->getSearchBox();
233 
234  // Add the HTML for the record list to output variable:
235  $out .= $dbList->HTMLcode;
236 
237  // Add support for fieldselectbox in singleTableMode
238  if ($dbList->table) {
239  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/FieldSelectBox');
240  $out .= $dbList->fieldSelectBox($dbList->table);
241  }
242 
243  return $out;
244  }
245 
249  protected function ‪getBodyTagAttributes()
250  {
251  return [
252  'data-mode' => 'db'
253  ];
254  }
255 
260  public function ‪getUrlParameters(array $values)
261  {
262  $pid = $values['pid'] ?? ‪$this->expandPage;
263  return [
264  'mode' => 'db',
265  'expandPage' => $pid,
266  'bparams' => ‪$this->bparams
267  ];
268  }
269 
274  public function ‪isCurrentlySelectedItem(array $values)
275  {
276  return false;
277  }
278 
284  public function ‪getScriptUrl()
285  {
286  return ‪$this->thisScript;
287  }
288 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\getUrlParameters
‪string[] getUrlParameters(array $values)
Definition: DatabaseBrowser.php:259
‪TYPO3\CMS\Backend\Tree\View\ElementBrowserPageTreeView
Definition: ElementBrowserPageTreeView.php:30
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\initVariables
‪initVariables()
Definition: DatabaseBrowser.php:47
‪TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList
Definition: ElementBrowserRecordList.php:27
‪TYPO3\CMS\Recordlist\Browser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:19
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\render
‪string render()
Definition: DatabaseBrowser.php:74
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\$thisScript
‪string $thisScript
Definition: AbstractElementBrowser.php:46
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\getScriptUrl
‪string getScriptUrl()
Definition: DatabaseBrowser.php:283
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1217
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: AbstractElementBrowser.php:165
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\initialize
‪initialize()
Definition: DatabaseBrowser.php:41
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\setTemporaryDbMounts
‪setTemporaryDbMounts()
Definition: DatabaseBrowser.php:139
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\getLanguageService
‪array< string, getBodyTagAttributes();protected array< string, function getBParamDataAttributes() {[ $fieldRef, $rteParams, $rteConfig,, $irreObjectId]=explode('|', $this->bparams);return['data-this-script-url'=> strpos( $this->thisScript, '?')===false ? $this-> LanguageService function getLanguageService()
Definition: AbstractElementBrowser.php:157
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\renderTableRecords
‪string renderTableRecords($tables)
Definition: DatabaseBrowser.php:158
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\$expandPage
‪int null $expandPage
Definition: DatabaseBrowser.php:39
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\isCurrentlySelectedItem
‪bool isCurrentlySelectedItem(array $values)
Definition: DatabaseBrowser.php:273
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\getTemporaryTreeMountCancelNotice
‪string getTemporaryTreeMountCancelNotice()
Definition: DatabaseBrowser.php:128
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser
Definition: AbstractElementBrowser.php:33
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\getBodyTagAttributes
‪string[] getBodyTagAttributes()
Definition: DatabaseBrowser.php:248
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array false readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:597
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser
Definition: DatabaseBrowser.php:32
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\processSessionData
‪array[] processSessionData($data)
Definition: DatabaseBrowser.php:59
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\$bparams
‪string $bparams
Definition: AbstractElementBrowser.php:69
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\setBodyTagParameters
‪setBodyTagParameters()
Definition: AbstractElementBrowser.php:118
‪TYPO3\CMS\Recordlist\Browser
Definition: AbstractElementBrowser.php:16