TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
RecordList.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Recordlist;
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;
37 
42 {
48  public $id;
49 
55  public $pointer;
56 
62  public $imagemode;
63 
69  public $table;
70 
76  public $search_field;
77 
84 
90  public $showLimit;
91 
97  public $returnUrl;
98 
104  public $clear_cache;
105 
111  public $cmd;
112 
118  public $cmd_table;
119 
126 
132  public $modTSconfig;
133 
139  public $pageinfo;
140 
146  public $doc;
147 
153  public $MOD_MENU = [];
154 
160  public $MOD_SETTINGS = [];
161 
167  public $content;
168 
174  protected $moduleName = 'web_list';
175 
179  public $body = '';
180 
184  protected $pageRenderer = null;
185 
189  protected $iconFactory;
190 
194  public function __construct()
195  {
196  parent::__construct();
197  $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf');
198  $this->moduleTemplate->getPageRenderer()->loadJquery();
199  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/FieldSelectBox');
200  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/Recordlist');
201  }
202 
208  public function init()
209  {
210  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
211  $backendUser = $this->getBackendUserAuthentication();
212  $this->perms_clause = $backendUser->getPagePermsClause(1);
213  // Get session data
214  $sessionData = $backendUser->getSessionData(__CLASS__);
215  $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
216  // GPvars:
217  $this->id = (int)GeneralUtility::_GP('id');
218  $this->pointer = GeneralUtility::_GP('pointer');
219  $this->imagemode = GeneralUtility::_GP('imagemode');
220  $this->table = GeneralUtility::_GP('table');
221  $this->search_field = GeneralUtility::_GP('search_field');
222  $this->search_levels = (int)GeneralUtility::_GP('search_levels');
223  $this->showLimit = GeneralUtility::_GP('showLimit');
224  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
225  $this->clear_cache = GeneralUtility::_GP('clear_cache');
226  $this->cmd = GeneralUtility::_GP('cmd');
227  $this->cmd_table = GeneralUtility::_GP('cmd_table');
228  $sessionData['search_field'] = $this->search_field;
229  // Initialize menu
230  $this->menuConfig();
231  // Store session data
232  $backendUser->setAndSaveSessionData(self::class, $sessionData);
233  $this->getPageRenderer()->addInlineLanguageLabelFile('EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf');
234  }
235 
241  public function menuConfig()
242  {
243  // MENU-ITEMS:
244  $this->MOD_MENU = [
245  'bigControlPanel' => '',
246  'clipBoard' => '',
247  'localization' => ''
248  ];
249  // Loading module configuration:
250  $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
251  // Clean up settings:
252  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
253  }
254 
260  public function clearCache()
261  {
262  if ($this->clear_cache) {
263  $tce = GeneralUtility::makeInstance(DataHandler::class);
264  $tce->start([], []);
265  $tce->clear_cacheCmd($this->id);
266  }
267  }
268 
274  public function main()
275  {
276  $backendUser = $this->getBackendUserAuthentication();
277  $lang = $this->getLanguageService();
278  // Loading current page record and checking access:
279  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
280  $access = is_array($this->pageinfo) ? 1 : 0;
281  // Start document template object:
282  // We need to keep this due to deeply nested dependencies
283  $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
284 
285  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/AjaxDataHandler');
286  $calcPerms = $backendUser->calcPerms($this->pageinfo);
287  $userCanEditPage = $calcPerms & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
288  if ($userCanEditPage) {
289  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', 'function(PageActions) {
290  PageActions.setPageId(' . (int)$this->id . ');
291  PageActions.initializePageTitleRenaming();
292  }');
293  }
294  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/Tooltip');
295  // Apply predefined values for hidden checkboxes
296  // Set predefined value for DisplayBigControlPanel:
297  if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'activated') {
298  $this->MOD_SETTINGS['bigControlPanel'] = true;
299  } elseif ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'deactivated') {
300  $this->MOD_SETTINGS['bigControlPanel'] = false;
301  }
302  // Set predefined value for Clipboard:
303  if ($this->modTSconfig['properties']['enableClipBoard'] === 'activated') {
304  $this->MOD_SETTINGS['clipBoard'] = true;
305  } elseif ($this->modTSconfig['properties']['enableClipBoard'] === 'deactivated') {
306  $this->MOD_SETTINGS['clipBoard'] = false;
307  } else {
308  if ($this->MOD_SETTINGS['clipBoard'] === null) {
309  $this->MOD_SETTINGS['clipBoard'] = true;
310  }
311  }
312  // Set predefined value for LocalizationView:
313  if ($this->modTSconfig['properties']['enableLocalizationView'] === 'activated') {
314  $this->MOD_SETTINGS['localization'] = true;
315  } elseif ($this->modTSconfig['properties']['enableLocalizationView'] === 'deactivated') {
316  $this->MOD_SETTINGS['localization'] = false;
317  }
318 
319  // Initialize the dblist object:
321  $dblist = GeneralUtility::makeInstance(RecordList\DatabaseRecordList::class);
322  $dblist->script = BackendUtility::getModuleUrl('web_list');
323  $dblist->calcPerms = $calcPerms;
324  $dblist->thumbs = $backendUser->uc['thumbnailsByDefault'];
325  $dblist->returnUrl = $this->returnUrl;
326  $dblist->allFields = $this->MOD_SETTINGS['bigControlPanel'] || $this->table ? 1 : 0;
327  $dblist->localizationView = $this->MOD_SETTINGS['localization'];
328  $dblist->showClipboard = 1;
329  $dblist->disableSingleTableView = $this->modTSconfig['properties']['disableSingleTableView'];
330  $dblist->listOnlyInSingleTableMode = $this->modTSconfig['properties']['listOnlyInSingleTableView'];
331  $dblist->hideTables = $this->modTSconfig['properties']['hideTables'];
332  $dblist->hideTranslations = $this->modTSconfig['properties']['hideTranslations'];
333  $dblist->tableTSconfigOverTCA = $this->modTSconfig['properties']['table.'];
334  $dblist->allowedNewTables = GeneralUtility::trimExplode(',', $this->modTSconfig['properties']['allowedNewTables'], true);
335  $dblist->deniedNewTables = GeneralUtility::trimExplode(',', $this->modTSconfig['properties']['deniedNewTables'], true);
336  $dblist->newWizards = $this->modTSconfig['properties']['newWizards'] ? 1 : 0;
337  $dblist->pageRow = $this->pageinfo;
338  $dblist->counter++;
339  $dblist->MOD_MENU = ['bigControlPanel' => '', 'clipBoard' => '', 'localization' => ''];
340  $dblist->modTSconfig = $this->modTSconfig;
341  $clickTitleMode = trim($this->modTSconfig['properties']['clickTitleMode']);
342  $dblist->clickTitleMode = $clickTitleMode === '' ? 'edit' : $clickTitleMode;
343  if (isset($this->modTSconfig['properties']['tableDisplayOrder.'])) {
344  $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
345  $dblist->setTableDisplayOrder($typoScriptService->convertTypoScriptArrayToPlainArray($this->modTSconfig['properties']['tableDisplayOrder.']));
346  }
347  // Clipboard is initialized:
348  // Start clipboard
349  $dblist->clipObj = GeneralUtility::makeInstance(Clipboard::class);
350  // Initialize - reads the clipboard content from the user session
351  $dblist->clipObj->initializeClipboard();
352  // Clipboard actions are handled:
353  // CB is the clipboard command array
354  $CB = GeneralUtility::_GET('CB');
355  if ($this->cmd == 'setCB') {
356  // CBH is all the fields selected for the clipboard, CBC is the checkbox fields which were checked.
357  // By merging we get a full array of checked/unchecked elements
358  // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
359  $CB['el'] = $dblist->clipObj->cleanUpCBC(array_merge(GeneralUtility::_POST('CBH'), (array)GeneralUtility::_POST('CBC')), $this->cmd_table);
360  }
361  if (!$this->MOD_SETTINGS['clipBoard']) {
362  // If the clipboard is NOT shown, set the pad to 'normal'.
363  $CB['setP'] = 'normal';
364  }
365  // Execute commands.
366  $dblist->clipObj->setCmd($CB);
367  // Clean up pad
368  $dblist->clipObj->cleanCurrent();
369  // Save the clipboard content
370  $dblist->clipObj->endClipboard();
371  // This flag will prevent the clipboard panel in being shown.
372  // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
373  $dblist->dontShowClipControlPanels = ($dblist->clipObj->current == 'normal' && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers']);
374  // If there is access to the page or root page is used for searching, then render the list contents and set up the document template object:
375  if ($access || ($this->id === 0 && $this->search_levels !== 0 && $this->search_field !== '')) {
376  // Deleting records...:
377  // Has not to do with the clipboard but is simply the delete action. The clipboard object is used to clean up the submitted entries to only the selected table.
378  if ($this->cmd == 'delete') {
379  $items = $dblist->clipObj->cleanUpCBC(GeneralUtility::_POST('CBC'), $this->cmd_table, 1);
380  if (!empty($items)) {
381  $cmd = [];
382  foreach ($items as $iK => $value) {
383  $iKParts = explode('|', $iK);
384  $cmd[$iKParts[0]][$iKParts[1]]['delete'] = 1;
385  }
386  $tce = GeneralUtility::makeInstance(DataHandler::class);
387  $tce->start([], $cmd);
388  $tce->process_cmdmap();
389  if (isset($cmd['pages'])) {
390  BackendUtility::setUpdateSignal('updatePageTree');
391  }
392  $tce->printLogErrorMessages(GeneralUtility::getIndpEnv('REQUEST_URI'));
393  }
394  }
395  // Initialize the listing object, dblist, for rendering the list:
396  $this->pointer = max(0, (int)$this->pointer);
397  $dblist->start($this->id, $this->table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
398  $dblist->setDispFields();
399  // Render versioning selector:
400  if (ExtensionManagementUtility::isLoaded('version')) {
401  $dblist->HTMLcode .= $this->moduleTemplate->getVersionSelector($this->id);
402  }
403  // Render the list of tables:
404  $dblist->generateList();
405  $listUrl = $dblist->listURL();
406  // Add JavaScript functions to the page:
407 
408  $this->moduleTemplate->addJavaScriptCode(
409  'RecordListInlineJS',
410  '
411  function jumpExt(URL,anchor) { //
412  var anc = anchor?anchor:"";
413  window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
414  return false;
415  }
416  function jumpSelf(URL) { //
417  window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
418  return false;
419  }
420  function jumpToUrl(URL) {
421  window.location.href = URL;
422  return false;
423  }
424 
425  function setHighlight(id) { //
426  top.fsMod.recentIds["web"]=id;
427  top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank; // For highlighting
428 
429  if (top.nav_frame && top.nav_frame.refresh_nav) {
430  top.nav_frame.refresh_nav();
431  }
432  }
433  ' . $this->moduleTemplate->redirectUrls($listUrl) . '
434  ' . $dblist->CBfunctions() . '
435  function editRecords(table,idList,addParams,CBflag) { //
436  window.location.href="' . BackendUtility::getModuleUrl('record_edit', ['returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]) . '&edit["+table+"]["+idList+"]=edit"+addParams;
437  }
438  function editList(table,idList) { //
439  var list="";
440 
441  // Checking how many is checked, how many is not
442  var pointer=0;
443  var pos = idList.indexOf(",");
444  while (pos!=-1) {
445  if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
446  list+=idList.substr(pointer,pos-pointer)+",";
447  }
448  pointer=pos+1;
449  pos = idList.indexOf(",",pointer);
450  }
451  if (cbValue(table+"|"+idList.substr(pointer))) {
452  list+=idList.substr(pointer)+",";
453  }
454 
455  return list ? list : idList;
456  }
457 
458  if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
459  '
460  );
461 
462  // Setting up the context sensitive menu:
463  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
464  }
465  // access
466  // Begin to compile the whole page, starting out with page header:
467  if (!$this->id) {
468  $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
469  } else {
470  $title = $this->pageinfo['title'];
471  }
472  $this->body = $this->moduleTemplate->header($title);
473  $this->moduleTemplate->setTitle($title);
474 
475  if (!empty($dblist->HTMLcode)) {
476  $output = $dblist->HTMLcode;
477  } else {
478  $output = '';
479  $flashMessage = GeneralUtility::makeInstance(
480  FlashMessage::class,
481  $lang->getLL('noRecordsOnThisPage'),
482  '',
484  );
486  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
488  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
489  $defaultFlashMessageQueue->enqueue($flashMessage);
490  }
491 
492  $this->body .= '<form action="' . htmlspecialchars($dblist->listURL()) . '" method="post" name="dblistForm">';
493  $this->body .= $output;
494  $this->body .= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
495  // If a listing was produced, create the page footer with search form etc:
496  if ($dblist->HTMLcode) {
497  // Making field select box (when extended view for a single table is enabled):
498  if ($dblist->table) {
499  $this->body .= $dblist->fieldSelectBox($dblist->table);
500  }
501  // Adding checkbox options for extended listing and clipboard display:
502  $this->body .= '
503 
504  <!--
505  Listing options for extended view, clipboard and localization view
506  -->
507  <div class="typo3-listOptions">
508  <form action="" method="post">';
509 
510  // Add "display bigControlPanel" checkbox:
511  if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'selectable') {
512  $this->body .= '<div class="checkbox">' .
513  '<label for="checkLargeControl">' .
514  BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLargeControl"') .
515  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', htmlspecialchars($lang->getLL('largeControl'))) .
516  '</label>' .
517  '</div>';
518  }
519 
520  // Add "clipboard" checkbox:
521  if ($this->modTSconfig['properties']['enableClipBoard'] === 'selectable') {
522  if ($dblist->showClipboard) {
523  $this->body .= '<div class="checkbox">' .
524  '<label for="checkShowClipBoard">' .
525  BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]', $this->MOD_SETTINGS['clipBoard'], '', $this->table ? '&table=' . $this->table : '', 'id="checkShowClipBoard"') .
526  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', htmlspecialchars($lang->getLL('showClipBoard'))) .
527  '</label>' .
528  '</div>';
529  }
530  }
531 
532  // Add "localization view" checkbox:
533  if ($this->modTSconfig['properties']['enableLocalizationView'] === 'selectable') {
534  $this->body .= '<div class="checkbox">' .
535  '<label for="checkLocalization">' .
536  BackendUtility::getFuncCheck($this->id, 'SET[localization]', $this->MOD_SETTINGS['localization'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLocalization"') .
537  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', htmlspecialchars($lang->getLL('localization'))) .
538  '</label>' .
539  '</div>';
540  }
541 
542  $this->body .= '
543  </form>
544  </div>';
545  }
546  // Printing clipboard if enabled
547  if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard && ($dblist->HTMLcode || $dblist->clipObj->hasElements())) {
548  $this->body .= '<div class="db_list-dashboard">' . $dblist->clipObj->printClipboard() . '</div>';
549  }
550  // Additional footer content
551  $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/Modules/Recordlist/index.php']['drawFooterHook'];
552  if (is_array($footerContentHook)) {
553  foreach ($footerContentHook as $hook) {
554  $params = [];
555  $this->body .= GeneralUtility::callUserFunction($hook, $params, $this);
556  }
557  }
558  // Setting up the buttons for docheader
559  $dblist->getDocHeaderButtons($this->moduleTemplate);
560  // searchbox toolbar
561  if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dblist->HTMLcode || !empty($dblist->searchString))) {
562  $this->content = $dblist->getSearchBox();
563  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
564 
565  $searchButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeLinkButton();
566  $searchButton
567  ->setHref('#')
568  ->setClasses('t3js-toggle-search-toolbox')
569  ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.title.searchIcon'))
570  ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL));
571  $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($searchButton,
573  }
574 
575  if ($this->pageinfo) {
576  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
577  }
578 
579  // Build the <body> for the module
580  $this->content .= $this->body;
581  }
582 
591  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
592  {
594  $GLOBALS['SOBE'] = $this;
595  $this->init();
596  $this->clearCache();
597  $this->main();
598  $this->moduleTemplate->setContent($this->content);
599  $response->getBody()->write($this->moduleTemplate->renderContent());
600  return $response;
601  }
602 
606  public function getModuleTemplate()
607  {
608  return $this->moduleTemplate;
609  }
610 
614  protected function getBackendUserAuthentication()
615  {
616  return $GLOBALS['BE_USER'];
617  }
618 
622  protected function getLanguageService()
623  {
624  return $GLOBALS['LANG'];
625  }
626 
630  protected function getPageRenderer()
631  {
632  if ($this->pageRenderer === null) {
633  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
634  }
635 
636  return $this->pageRenderer;
637  }
638 }
mainAction(ServerRequestInterface $request, ResponseInterface $response)
Definition: RecordList.php:591
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type= '', $dontValidateList= '', $setDefaultList= '')
static getFuncCheck($mainParams, $elementName, $currentValue, $script= '', $addParams= '', $tagParams= '')
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static callUserFunction($funcName, &$params, &$ref, $_= '', $errorMode=0)