TYPO3  7.6
PageLayoutController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
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 
19 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedException;
46 
51 {
52 
58  public $id;
59 
65  public $pointer;
66 
72  public $imagemode;
73 
79  public $search_field;
80 
87 
93  public $showLimit;
94 
100  public $returnUrl;
101 
107  public $clear_cache;
108 
114  public $popView;
115 
122  public $edit_record;
123 
131 
138 
144  public $modTSconfig;
145 
152 
158  public $pageinfo;
159 
166  public $descrTable;
167 
173  public $colPosList;
174 
181 
187  public $CALC_PERMS;
188 
195 
201  public $MCONF = array();
202 
208  public $MOD_MENU = array();
209 
215  public $MOD_SETTINGS = array();
216 
222  public $externalTables = array();
223 
229  public $content;
230 
238 
242  protected $eRParts = array();
243 
247  protected $editSelect;
248 
252  protected $deleteButton;
253 
257  protected $undoButton;
258 
262  protected $undoButtonR;
263 
267  protected $R_URI;
268 
272  protected $closeUrl;
273 
279  protected $languagesInColumnCache = array();
280 
287  public $contentElementCache = array();
288 
292  protected $iconFactory;
293 
299  protected $moduleName = 'web_layout';
300 
304  protected $moduleTemplate;
305 
309  protected $buttonBar;
310 
314  protected $searchContent;
315 
321  public function init()
322  {
323  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
324  $this->iconFactory = $this->moduleTemplate->getIconFactory();
325  $this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
326  $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
327  // Setting module configuration / page select clause
328  $this->MCONF['name'] = $this->moduleName;
329  $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
330  // Get session data
331  $sessionData = $this->getBackendUser()->getSessionData(RecordList::class);
332  $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
333  // GPvars:
334  $this->id = (int)GeneralUtility::_GP('id');
335  $this->pointer = GeneralUtility::_GP('pointer');
336  $this->imagemode = GeneralUtility::_GP('imagemode');
337  $this->clear_cache = GeneralUtility::_GP('clear_cache');
338  $this->popView = GeneralUtility::_GP('popView');
339  $this->edit_record = GeneralUtility::_GP('edit_record');
340  $this->new_unique_uid = GeneralUtility::_GP('new_unique_uid');
341  $this->search_field = GeneralUtility::_GP('search_field');
342  $this->search_levels = GeneralUtility::_GP('search_levels');
343  $this->showLimit = GeneralUtility::_GP('showLimit');
344  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
345  $this->externalTables = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables'];
346  $sessionData['search_field'] = $this->search_field;
347  // Store session data
348  $this->getBackendUser()->setAndSaveSessionData(RecordList::class, $sessionData);
349  // Load page info array:
350  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
351  // Initialize menu
352  $this->menuConfig();
353  // Setting sys language from session var:
354  $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
355  // CSH / Descriptions:
356  $this->descrTable = '_MOD_' . $this->moduleName;
357  }
358 
364  public function menuConfig()
365  {
366  $lang = $this->getLanguageService();
367  // MENU-ITEMS:
368  $this->MOD_MENU = array(
369  'tt_content_showHidden' => '',
370  'function' => array(
371  0 => $lang->getLL('m_function_0'),
372  1 => $lang->getLL('m_function_1'),
373  2 => $lang->getLL('m_function_2')
374  ),
375  'language' => array(
376  0 => $lang->getLL('m_default')
377  )
378  );
379  // example settings:
380  // $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables']['tx_myext'] =
381  // array ('default' => array(
382  // 'MENU' => 'LLL:EXT:tx_myext/locallang_db.xlf:menuDefault',
383  // 'fList' => 'title,description,image',
384  // 'icon' => TRUE));
385  if (is_array($this->externalTables)) {
386  foreach ($this->externalTables as $table => $tableSettings) {
387  // delete the default settings from above
388  if (is_array($this->MOD_MENU[$table])) {
389  unset($this->MOD_MENU[$table]);
390  }
391  if (is_array($tableSettings) && count($tableSettings) > 1) {
392  foreach ($tableSettings as $key => $settings) {
393  $this->MOD_MENU[$table][$key] = $lang->sL($settings['MENU']);
394  }
395  }
396  }
397  }
398  // First, select all pages_language_overlay records on the current page. Each represents a possibility for a language on the page. Add these to language selector.
399  $res = $this->exec_languageQuery($this->id);
400  while ($lRow = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
401  if ($this->getBackendUser()->checkLanguageAccess($lRow['uid'])) {
402  $this->MOD_MENU['language'][$lRow['uid']] = $lRow['hidden'] ? '(' . $lRow['title'] . ')' : $lRow['title'];
403  }
404  }
405  // Setting alternative default label:
406  if (($this->modSharedTSconfig['properties']['defaultLanguageLabel'] || $this->modTSconfig['properties']['defaultLanguageLabel']) && isset($this->MOD_MENU['language'][0])) {
407  $this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
408  }
409  // Clean up settings
410  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
411  // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
412  if ($this->getBackendUser()->workspace != 0 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0') {
413  $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
414  }
415  $this->makeActionMenu();
416  }
417 
424  protected function makeActionMenu()
425  {
426  $availableActionArray = array(
427  0 => $this->getLanguageService()->getLL('m_function_0'),
428  1 => $this->getLanguageService()->getLL('m_function_1'),
429  2 => $this->getLanguageService()->getLL('m_function_2')
430  );
431  // Find if there are ANY languages at all (and if not, remove the language option from function menu).
432  $count = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', $this->getBackendUser()->isAdmin() ? '' : 'hidden=0');
433  if (!$count) {
434  unset($availableActionArray['2']);
435  }
436  // page/be_user TSconfig settings and blinding of menu-items
437  $this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
438  $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
439  if ($this->modTSconfig['properties']['QEisDefault']) {
440  ksort($availableActionArray);
441  }
442  $availableActionArray = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $availableActionArray, 'menu.function');
443  // Remove QuickEdit as option if page type is not...
444  if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ',6', $this->pageinfo['doktype'])) {
445  unset($availableActionArray[0]);
446  }
447  $actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
448  $actionMenu->setIdentifier('actionMenu');
449  $actionMenu->setLabel('');
450 
451  $defaultKey = null;
452  $foundDefaultKey = false;
453  foreach ($availableActionArray as $key => $action) {
454  $menuItem = $actionMenu
455  ->makeMenuItem()
456  ->setTitle($action)
457  ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key);
458 
459  if (!$foundDefaultKey) {
460  $defaultKey = $key;
461  $foundDefaultKey = true;
462  }
463  if ((int)$this->MOD_SETTINGS['function'] === $key) {
464  $menuItem->setActive(true);
465  $defaultKey = null;
466  }
467  $actionMenu->addMenuItem($menuItem);
468  }
469  if (isset($defaultKey)) {
470  $this->MOD_SETTINGS['function'] = $defaultKey;
471  }
472  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
473  }
474 
480  public function clearCache()
481  {
482  if ($this->clear_cache) {
483  $tce = GeneralUtility::makeInstance(DataHandler::class);
484  $tce->stripslashes_values = false;
485  $tce->start(array(), array());
486  $tce->clear_cacheCmd($this->id);
487  }
488  }
489 
496  {
497  $content = '';
498  $lang = $this->getLanguageService();
499 
500  // If page is a folder
501  if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
502  $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
503  $moduleLoader->load($GLOBALS['TBE_MODULES']);
504  $modules = $moduleLoader->modules;
505  if (is_array($modules['web']['sub']['list'])) {
506  $title = $lang->getLL('goToListModule');
507  $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
508  $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
509  $view = GeneralUtility::makeInstance(StandaloneView::class);
510  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
511  $view->assignMultiple(array(
512  'title' => $title,
513  'message' => $message,
515  ));
516  $content .= $view->render();
517  }
518  }
519  // If content from different pid is displayed
520  if ($this->pageinfo['content_from_pid']) {
521  $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
522  $linkToPid = $this->local_linkThisScript(array('id' => $this->pageinfo['content_from_pid']));
523  $title = BackendUtility::getRecordTitle('pages', $contentPage);
524  $link = '<a href="' . $linkToPid . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
525  $message = sprintf($lang->getLL('content_from_pid_title'), $link);
526  $view = GeneralUtility::makeInstance(StandaloneView::class);
527  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
528  $view->assignMultiple(array(
529  'title' => $title,
530  'message' => $message,
532  ));
533  $content .= $view->render();
534  }
535  return $content;
536  }
537 
542  protected function getLocalizedPageTitle()
543  {
544  if ($this->current_sys_language > 0) {
545  $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
546  'title',
547  'pages_language_overlay',
548  'pid = ' . (int)$this->id .
549  ' AND sys_language_uid = ' . (int)$this->current_sys_language .
550  BackendUtility::deleteClause('pages_language_overlay') .
551  BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
552  '',
553  '',
554  ''
555  );
556  return $overlayRecord['title'];
557  } else {
558  return $this->pageinfo['title'];
559  }
560  }
561 
571  {
572  $GLOBALS['SOBE'] = $this;
573  $this->init();
574  $this->clearCache();
575  $this->main();
576  $response->getBody()->write($this->moduleTemplate->renderContent());
577  return $response;
578  }
579 
586  public function main()
587  {
588  $lang = $this->getLanguageService();
589  // Access check...
590  // The page will show only if there is a valid page and if this page may be viewed by the user
591  $access = is_array($this->pageinfo) ? 1 : 0;
592  // Content
593  $content = '';
594  if ($this->id && $access) {
595  // Initialize permission settings:
596  $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
597  $this->EDIT_CONTENT = $this->pageIsNotLockedForEditors();
598 
599  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
600 
601  // override the default jumpToUrl
602  $this->moduleTemplate->addJavaScriptCode('jumpToUrl', '
603  function jumpToUrl(URL,formEl) {
604  if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
605  if (!TBE_EDITOR.isFormChanged()) {
606  window.location.href = URL;
607  } else if (formEl) {
608  if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
609  }
610  } else {
611  window.location.href = URL;
612  }
613  }
614  ');
615  $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
616  if (top.fsMod) {
617  top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
618  top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
619  }
620  ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
621  function deleteRecord(table,id,url) { //
622  if (confirm(' . GeneralUtility::quoteJSvalue($lang->getLL('deleteWarning')) . ')) {
623  window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&cmd[') . '+table+"]["+id+"][delete]=1&redirect="+escape(url)+"&vC=' . $this->getBackendUser()->veriCode() . '&prErr=1&uPT=1";
624  }
625  return false;
626  }
627  ');
628 
629  // Find backend layout / columns
630  $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
631  if (!empty($backendLayout['__colPosList'])) {
632  $this->colPosList = implode(',', $backendLayout['__colPosList']);
633  }
634  // Removing duplicates, if any
635  $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
636  // Accessible columns
637  if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
638  $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
639  // Match with the list which is present in the colPosList for the current page
640  if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
641  $this->activeColPosList = array_unique(array_intersect(
642  $this->activeColPosList,
643  $this->colPosList
644  ));
645  }
646  } else {
647  $this->activeColPosList = $this->colPosList;
648  }
649  $this->activeColPosList = implode(',', $this->activeColPosList);
650  $this->colPosList = implode(',', $this->colPosList);
651 
653 
654 
655  // Render the primary module content:
656  if ($this->MOD_SETTINGS['function'] == 0) {
657  // QuickEdit
658  $content .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db', ['prErr' => 1, 'uPT' => 1])) . '" method="post" enctype="multipart/form-data" name="editform" id="PageLayoutController" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
659  $content .= $this->renderQuickEdit();
660  } else {
661  $content .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl($this->moduleName, array('id' => $this->id, 'imagemode' => $this->imagemode))) . '" id="PageLayoutController" method="post">';
662  // Page title
663  $content .= '<h1 class="t3js-title-inlineedit">' . htmlspecialchars($this->getLocalizedPageTitle()) . '</h1>';
664  // All other listings
665  $content .= $this->renderListContent();
666  }
667  $content .= '</form>';
669  // Setting up the buttons for the docheader
670  $this->makeButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
671  // Create LanguageMenu
672  $this->makeLanguageMenu();
673 
674  } else {
675  $this->moduleTemplate->addJavaScriptCode(
676  'mainJsFunctions',
677  'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
678  );
679  $content .= '<h1>' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '</h1>';
680  $view = GeneralUtility::makeInstance(StandaloneView::class);
681  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
682  $view->assignMultiple(array(
683  'title' => $lang->getLL('clickAPage_header'),
684  'message' => $lang->getLL('clickAPage_content'),
686  ));
687  $content .= $view->render();
688  }
689  // Set content
690  $this->moduleTemplate->setContent($content);
691  }
692 
698  public function renderQuickEdit()
699  {
700  $databaseConnection = $this->getDatabaseConnection();
701  $beUser = $this->getBackendUser();
702  $lang = $this->getLanguageService();
703  // Set the edit_record value for internal use in this function:
705  // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
706  if (substr($edit_record, 0, 9) == '_EDIT_COL') {
707  $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', 'pid=' . (int)$this->id . ' AND colPos=' . (int)substr($edit_record, 10) . ' AND sys_language_uid=' . (int)$this->current_sys_language . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting');
708  $idListA = array();
709  while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
710  $idListA[] = $cRow['uid'];
711  }
712  $url = BackendUtility::getModuleUrl('record_edit', array(
713  'edit[tt_content][' . implode(',', $idListA) . ']' => 'edit',
714  'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))
715  ));
717  }
718  // If the former record edited was the creation of a NEW record, this will look up the created records uid:
719  if ($this->new_unique_uid) {
720  $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int)$beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
721  $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
722  if (is_array($sys_log_row)) {
723  $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
724  }
725  }
727  // Splitting the edit-record cmd value into table/uid:
728  $this->eRParts = explode(':', $edit_record);
729  $tableName = $this->eRParts[0];
730  // Delete-button flag?
731  $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($tableName !== 'pages' && $this->EDIT_CONTENT || $tableName === 'pages' && $this->CALC_PERMS & Permission::PAGE_DELETE);
732  // If undo-button should be rendered (depends on available items in sys_history)
733  $this->undoButton = false;
734  $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($tableName, 'sys_history') . ' AND recuid=' . (int)$this->eRParts[1], '', 'tstamp DESC', '1');
735  if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
736  $this->undoButton = true;
737  }
738  // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
739  $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
740  $R_URL_getvars = GeneralUtility::_GET();
741  unset($R_URL_getvars['popView']);
742  unset($R_URL_getvars['new_unique_uid']);
743  $R_URL_getvars['edit_record'] = $edit_record;
744  $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
745 
746  // Creating editing form:
747  if ($edit_record) {
748  // Splitting uid parts for special features, if new:
749  list($uidVal, $neighborRecordUid, $ex_colPos) = explode('/', $this->eRParts[1]);
750 
751  if ($uidVal === 'new') {
752  $command = 'new';
753  // Page id of this new record
754  $theUid = $this->id;
755  if ($neighborRecordUid) {
756  $theUid = $neighborRecordUid;
757  }
758  } else {
759  $command = 'edit';
760  $theUid = $uidVal;
761  // Convert $uidVal to workspace version if any:
762  $draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $tableName, $theUid, 'uid');
763  if ($draftRecord) {
764  $theUid = $draftRecord['uid'];
765  }
766  }
767 
768  // @todo: Hack because DatabaseInitializeNewRow reads from _GP directly
769  $GLOBALS['_GET']['defVals'][$tableName] = array(
770  'colPos' => (int)$ex_colPos,
771  'sys_language_uid' => (int)$this->current_sys_language
772  );
773 
775  $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
777  $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
779  $nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
780 
781  try {
782  $formDataCompilerInput = [
783  'tableName' => $tableName,
784  'vanillaUid' => (int)$theUid,
785  'command' => $command,
786  ];
787  $formData = $formDataCompiler->compile($formDataCompilerInput);
788 
789  if ($command !== 'new') {
790  BackendUtility::lockRecords($tableName, $formData['databaseRow']['uid'], $tableName === 'tt_content' ? $formData['databaseRow']['pid'] : 0);
791  }
792 
793  $formData['renderType'] = 'outerWrapContainer';
794  $formResult = $nodeFactory->create($formData)->render();
795 
796  $panel = $formResult['html'];
797  $formResult['html'] = '';
798 
800  $formResultCompiler = GeneralUtility::makeInstance(FormResultCompiler::class);
801  $formResultCompiler->mergeResult($formResult);
802 
803  $row = $formData['databaseRow'];
804  $new_unique_uid = '';
805  if ($command === 'new') {
806  $new_unique_uid = $row['uid'];
807  }
808 
809  // Add hidden fields:
810  if ($uidVal == 'new') {
811  $panel .= '<input type="hidden" name="data[' . $tableName . '][' . $row['uid'] . '][pid]" value="' . $row['pid'] . '" />';
812  }
813  $redirect = ($uidVal == 'new' ? BackendUtility::getModuleUrl(
814  $this->moduleName,
815  ['id' => $this->id,'new_unique_uid' => $new_unique_uid,'returnUrl' => $this->returnUrl]
816  ) : $this->R_URI);
817  $panel .= '
818  <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
819  <input type="hidden" name="edit_record" value="' . $edit_record . '" />
820  <input type="hidden" name="redirect" value="' . htmlspecialchars($redirect) . '" />
821  ';
822  // Add JavaScript as needed around the form:
823  $content = $formResultCompiler->JStop() . $panel . $formResultCompiler->printNeededJSFunctions();
824 
825  // Display "is-locked" message:
826  if ($command === 'edit') {
827  $lockInfo = BackendUtility::isRecordLocked($tableName, $formData['databaseRow']['uid']);
828  if ($lockInfo) {
830  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
832  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
834  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
835  $defaultFlashMessageQueue->enqueue($flashMessage);
836  }
837  }
838  } catch (AccessDeniedException $e) {
839  // If no edit access, print error message:
840  $content = '<h2>' . $lang->getLL('noAccess', true) . '</h2>';
841  $conten .= '<div>' . $lang->getLL('noAccess_msg') . '<br /><br />' . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : '') . '</div>';
842  }
843  } else {
844  // If no edit access, print error message:
845  $content = '<h2>' . $lang->getLL('noAccess') . '</h2>';
846  $content .= '<div>' . $lang->getLL('noAccess_msg') . '</div>';
847  }
848 
849  // Element selection matrix:
850  if ($tableName === 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
851  $content .= '<h2>' . $lang->getLL('CEonThisPage') . '</h2>';
852  // PositionMap
853  $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
854  $posMap->cur_sys_language = $this->current_sys_language;
855  $content .= $posMap->printContentElementColumns(
856  $this->id,
857  $this->eRParts[1],
858  $this->colPosList,
859  $this->MOD_SETTINGS['tt_content_showHidden'],
860  $this->R_URI
861  );
862  // Toggle hidden ContentElements
863  $numberOfHiddenElements = $this->getNumberOfHiddenElements();
864  if ($numberOfHiddenElements) {
865  $content .= '<div class="checkbox">';
866  $content .= '<label for="checkTt_content_showHidden">';
867  $content .= BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"');
868  $content .= (!$numberOfHiddenElements ? ('<span class="text-muted">' . $lang->getLL('hiddenCE', true) . '</span>') : $lang->getLL('hiddenCE', true) . ' (' . $numberOfHiddenElements . ')');
869  $content .= '</label>';
870  $content .= '</div>';
871  }
872  // CSH
873  $content .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement');
874  }
875 
876  return $content;
877  }
878 
884  public function renderListContent()
885  {
886  $this->moduleTemplate->getPageRenderer()->loadJquery();
887  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
889  $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
890  $dbList->thumbs = $this->imagemode;
891  $dbList->no_noWrap = 1;
892  $dbList->descrTable = $this->descrTable;
893  $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
894  $dbList->script = BackendUtility::getModuleUrl($this->moduleName);
895  $dbList->showIcon = 0;
896  $dbList->setLMargin = 0;
897  $dbList->doEdit = $this->EDIT_CONTENT;
898  $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
899  $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
900  $dbList->id = $this->id;
901  $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
902  $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
903  $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
904  if (!$dbList->nextThree) {
905  $dbList->nextThree = 1;
906  }
907  $dbList->externalTables = $this->externalTables;
908  // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
909  // also fills $dbList->activeTables
910  $dbList->getTableMenu($this->id);
911  // Initialize other variables:
912  $tableOutput = array();
913  $tableJSOutput = array();
914  $CMcounter = 0;
915  // Traverse the list of table names which has records on this page (that array is populated
916  // by the $dblist object during the function getTableMenu()):
917  foreach ($dbList->activeTables as $table => $value) {
918  $h_func = '';
919  $h_func_b = '';
920  if (!isset($dbList->externalTables[$table])) {
921  // Toggle hidden ContentElements
922  $numberOfHiddenElements = $this->getNumberOfHiddenElements();
923  if ($numberOfHiddenElements > 0) {
924  $h_func_b = '
925  <div class="checkbox">
926  <label for="checkTt_content_showHidden">
927  <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
928  ' . $this->getLanguageService()->getLL('hiddenCE', true) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
929  </label>
930  </div>';
931  }
932 
933  // Boolean: Display up/down arrows and edit icons for tt_content records
934  $dbList->tt_contentConfig['showCommands'] = 1;
935  // Boolean: Display info-marks or not
936  $dbList->tt_contentConfig['showInfo'] = 1;
937  // Setting up the tt_content columns to show:
938  if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
939  $colList = array();
940  $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
941  foreach ($tcaItems as $temp) {
942  $colList[] = $temp[1];
943  }
944  } else {
945  // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
946  $colList = array('1', '0', '2', '3');
947  }
948  if ($this->colPosList !== '') {
949  $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
950  }
951  // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
952  $dbList->tt_contentConfig['cols'] = implode(',', $colList);
953  $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
954  $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
955  $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
956  // If the function menu is set to "Language":
957  if ($this->MOD_SETTINGS['function'] == 2) {
958  $dbList->tt_contentConfig['languageMode'] = 1;
959  $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
960  $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
961  }
962  } else {
963  if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
964  $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
965  }
966  }
967  // Start the dblist object:
968  $dbList->itemsLimitSingleTable = 1000;
969  $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
970  $dbList->counter = $CMcounter;
971  $dbList->ext_function = $this->MOD_SETTINGS['function'];
972  // Render versioning selector:
973  $dbList->HTMLcode .= $this->moduleTemplate->getVersionSelector($this->id);
974  // Generate the list of elements here:
975  $dbList->generateList();
976  // Adding the list content to the tableOutput variable:
977  $tableOutput[$table] = $h_func . $dbList->HTMLcode . $h_func_b;
978  // ... and any accumulated JavaScript goes the same way!
979  $tableJSOutput[$table] = $dbList->JScode;
980  // Increase global counter:
981  $CMcounter += $dbList->counter;
982  // Reset variables after operation:
983  $dbList->HTMLcode = '';
984  $dbList->JScode = '';
985  }
986  // END: traverse tables
987  // For Context Sensitive Menus:
988  // Init the content
989  $content = '';
990  // Additional header content
991  $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
992  if (is_array($headerContentHook)) {
993  foreach ($headerContentHook as $hook) {
994  $params = array();
995  $content .= GeneralUtility::callUserFunction($hook, $params, $this);
996  }
997  }
998  // Add the content for each table we have rendered (traversing $tableOutput variable)
999  foreach ($tableOutput as $table => $output) {
1000  $content .= $output;
1001  }
1002  // Making search form:
1003  if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
1004  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
1005  $toggleSearchFormButton = $this->buttonBar->makeLinkButton()
1006  ->setClasses('t3js-toggle-search-toolbox')
1007  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', true))
1008  ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL))
1009  ->setHref('#');
1010  $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
1011  $this->searchContent = $dbList->getSearchBox();
1012  }
1013  // Additional footer content
1014  $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1015  if (is_array($footerContentHook)) {
1016  foreach ($footerContentHook as $hook) {
1017  $params = array();
1018  $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1019  }
1020  }
1021  return $content;
1022  }
1023 
1027  public function getModuleTemplate()
1028  {
1029  return $this->moduleTemplate;
1030  }
1031 
1037  public function printContent()
1038  {
1039  echo $this->moduleTemplate->renderContent();
1040  }
1041 
1042  /***************************
1043  *
1044  * Sub-content functions, rendering specific parts of the module content.
1045  *
1046  ***************************/
1053  protected function makeButtons($function = '')
1054  {
1055  $lang = $this->getLanguageService();
1056  // View page
1057  if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1058  $viewButton = $this->buttonBar->makeLinkButton()
1059  ->setOnClick(htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid']))))
1060  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
1061  ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL))
1062  ->setHref('#');
1063 
1064  $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1065  }
1066  // Shortcut
1067  $shortcutButton = $this->buttonBar->makeShortcutButton()
1068  ->setModuleName($this->moduleName)
1069  ->setGetVariables([
1070  'id',
1071  'M',
1072  'edit_record',
1073  'pointer',
1074  'new_unique_uid',
1075  'search_field',
1076  'search_levels',
1077  'showLimit'
1078  ])
1079  ->setSetVariables(array_keys($this->MOD_MENU));
1080  $this->buttonBar->addButton($shortcutButton);
1081 
1082  // Cache
1083  if (!$this->modTSconfig['properties']['disableAdvanced']) {
1084  $clearCacheButton = $this->buttonBar->makeLinkButton()
1085  ->setHref(BackendUtility::getModuleUrl($this->moduleName, ['id' => $this->pageinfo['uid'], 'clear_cache' => '1']))
1086  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.clear_cache', true))
1087  ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
1088  $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
1089  }
1090  if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1091  // Move record
1092  if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1093  $urlParameters = [
1094  'table' => $this->eRParts[0],
1095  'uid' => $this->eRParts[1],
1096  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1097  ];
1098  $moveButton = $this->buttonBar->makeLinkButton()
1099  ->setHref(BackendUtility::getModuleUrl('move_element', $urlParameters))
1100  ->setTitle($lang->getLL('move_' . ($this->eRParts[0] == 'tt_content' ? 'record' : 'page'), true))
1101  ->setIcon($this->iconFactory->getIcon('actions-' . ($this->eRParts[0] == 'tt_content' ? 'document' : 'page') . '-move', Icon::SIZE_SMALL));
1102  $this->buttonBar->addButton($moveButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
1103  }
1104 
1105  // Edit page properties and page language overlay icons
1106  if ($this->pageIsNotLockedForEditors()) {
1107  // Edit localized page_language_overlay only when one specific language is selected
1108  if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1109  $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
1110  'uid',
1111  'pages_language_overlay',
1112  'pid = ' . (int)$this->id . ' ' .
1113  'AND sys_language_uid = ' . (int)$this->current_sys_language .
1114  BackendUtility::deleteClause('pages_language_overlay') .
1115  BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1116  '',
1117  '',
1118  ''
1119  );
1120  $editLanguageButton = $this->buttonBar->makeLinkButton()
1121  ->setHref('#')
1122  ->setTitle($lang->getLL('editPageLanguageOverlayProperties', true))
1123  ->setOnClick(htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit')))
1124  ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
1125  $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1126  }
1127  $editPageButton = $this->buttonBar->makeLinkButton()
1128  ->setHref('#')
1129  ->setTitle($lang->getLL('editPageProperties', true))
1130  ->setOnClick(htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit')))
1131  ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
1132  $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1133  }
1134 
1135  // Add CSH (Context Sensitive Help) icon to tool bar
1136  $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
1137  ->setModuleName($this->descrTable)
1138  ->setFieldName(($function === 'quickEdit' ? 'quickEdit' : 'columns_' . $this->MOD_SETTINGS['function']));
1139  $this->buttonBar->addButton($contextSensitiveHelpButton);
1140 
1141  // QuickEdit
1142  if ($function == 'quickEdit') {
1143  // Close Record
1144  $closeButton = $this->buttonBar->makeLinkButton()
1145  ->setHref('#')
1146  ->setOnClick(htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue($this->closeUrl) . '); return false;'))
1147  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', true))
1148  ->setIcon($this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL));
1149  $this->buttonBar->addButton($closeButton, ButtonBar::BUTTON_POSITION_LEFT, 0);
1150 
1151  // Save Record
1152  $saveButtonDropdown = $this->buttonBar->makeSplitButton();
1153  $saveButton = $this->buttonBar->makeInputButton()
1154  ->setName('_savedok')
1155  ->setValue('1')
1156  ->setForm('PageLayoutController')
1157  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', true))
1158  ->setIcon($this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL));
1159  $saveButtonDropdown->addItem($saveButton);
1160  $saveAndCloseButton = $this->buttonBar->makeInputButton()
1161  ->setName('_saveandclosedok')
1162  ->setValue('1')
1163  ->setForm('PageLayoutController')
1164  ->setOnClick('document.editform.redirect.value=\'' . $this->closeUrl . '\';')
1165  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', true))
1166  ->setIcon($this->iconFactory->getIcon('actions-document-save-close', Icon::SIZE_SMALL));
1167  $saveButtonDropdown->addItem($saveAndCloseButton);
1168  $saveAndShowPageButton = $this->buttonBar->makeInputButton()
1169  ->setName('_savedokview')
1170  ->setValue('1')
1171  ->setForm('PageLayoutController')
1172  ->setOnClick('document.editform.redirect.value+=\'&popView=1\';')
1173  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', true))
1174  ->setIcon($this->iconFactory->getIcon('actions-document-save-view', Icon::SIZE_SMALL));
1175  $saveButtonDropdown->addItem($saveAndShowPageButton);
1176  $this->buttonBar->addButton($saveButtonDropdown, ButtonBar::BUTTON_POSITION_LEFT, 1);
1177 
1178  // Delete record
1179  if ($this->deleteButton) {
1180  $deleteButton = $this->buttonBar->makeLinkButton()
1181  ->setHref('#')
1182  ->setOnClick(htmlspecialchars('return deleteRecord(' . GeneralUtility::quoteJSvalue($this->eRParts[0]) . ',' . GeneralUtility::quoteJSvalue($this->eRParts[1]) . ',' . GeneralUtility::quoteJSvalue(GeneralUtility::getIndpEnv('SCRIPT_NAME') . '?id=' . $this->id) . ');'))
1183  ->setTitle($lang->getLL('deleteItem', true))
1184  ->setIcon($this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL));
1185  $this->buttonBar->addButton($deleteButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
1186  }
1187 
1188  // History
1189  if ($this->undoButton) {
1190  $undoButton = $this->buttonBar->makeLinkButton()
1191  ->setHref('#')
1192  ->setOnClick(htmlspecialchars('window.location.href=' .
1194  BackendUtility::getModuleUrl(
1195  'record_history',
1196  array(
1197  'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1198  'revert' => 'ALL_FIELDS',
1199  'sumUp' => -1,
1200  'returnUrl' => $this->R_URI,
1201  )
1202  )
1203  ) . '; return false;'))
1204  ->setTitle(htmlspecialchars(sprintf($lang->getLL('undoLastChange'), BackendUtility::calcAge($GLOBALS['EXEC_TIME'] - $this->undoButtonR['tstamp'], $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))))
1205  ->setIcon($this->iconFactory->getIcon('actions-edit-undo', Icon::SIZE_SMALL));
1206  $this->buttonBar->addButton($undoButton, ButtonBar::BUTTON_POSITION_LEFT, 5);
1207  $historyButton = $this->buttonBar->makeLinkButton()
1208  ->setHref('#')
1209  ->setOnClick(htmlspecialchars('jumpToUrl(' .
1211  BackendUtility::getModuleUrl(
1212  'record_history',
1213  array(
1214  'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1215  'returnUrl' => $this->R_URI,
1216  )
1217  ) . '#latest'
1218  ) . ');return false;'))
1219  ->setTitle($lang->getLL('recordHistory', true))
1220  ->setIcon($this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL));
1221  $this->buttonBar->addButton($historyButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1222  }
1223 
1224  }
1225  }
1226  }
1227 
1228  /*******************************
1229  *
1230  * Other functions
1231  *
1232  ******************************/
1239  public function getNumberOfHiddenElements()
1240  {
1241  return $this->getDatabaseConnection()->exec_SELECTcountRows(
1242  'uid',
1243  'tt_content',
1244  'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . BackendUtility::BEenableFields('tt_content', 1) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content')
1245  );
1246  }
1247 
1255  public function local_linkThisScript($params)
1256  {
1257  $params['popView'] = '';
1258  $params['new_unique_uid'] = '';
1259  return GeneralUtility::linkThisScript($params);
1260  }
1261 
1268  public function exec_languageQuery($id)
1269  {
1270  if ($id) {
1271  $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1272  ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1273  return $this->getDatabaseConnection()->exec_SELECTquery(
1274  'sys_language.*',
1275  'pages_language_overlay,sys_language',
1276  'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1277  BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1278  'pages_language_overlay.sys_language_uid,sys_language.uid,sys_language.pid,sys_language.tstamp,sys_language.hidden,sys_language.title,sys_language.language_isocode,sys_language.static_lang_isocode,sys_language.flag',
1279  'sys_language.title'
1280  );
1281  } else {
1282  return $this->getDatabaseConnection()->exec_SELECTquery(
1283  'sys_language.*',
1284  'sys_language',
1285  'sys_language.hidden=0',
1286  '',
1287  'sys_language.title'
1288  );
1289  }
1290  }
1291 
1299  public function isColumnEmpty($colPos, $languageId)
1300  {
1301  foreach ($this->contentElementCache[$languageId][$colPos] as $uid => $row) {
1302  if ((int)$row['l18n_parent'] === 0) {
1303  return false;
1304  }
1305  }
1306  return true;
1307  }
1308 
1317  public function getElementsFromColumnAndLanguage($pageId, $colPos, $languageId)
1318  {
1319  if (!isset($this->contentElementCache[$languageId][$colPos])) {
1320  $languageId = (int)$languageId;
1321  $whereClause = 'tt_content.pid=' . (int)$pageId . ' AND tt_content.colPos=' . (int)$colPos . ' AND tt_content.sys_language_uid=' . $languageId . BackendUtility::deleteClause('tt_content');
1322  if ($languageId > 0) {
1323  $whereClause .= ' AND tt_content.l18n_parent=0 AND sys_language.uid=' . $languageId . ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1324  }
1325 
1326  $databaseConnection = $this->getDatabaseConnection();
1327  $res = $databaseConnection->exec_SELECTquery(
1328  'tt_content.uid',
1329  'tt_content,sys_language',
1330  $whereClause
1331  );
1332  while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1333  $this->contentElementCache[$languageId][$colPos][$row['uid']] = $row;
1334  }
1335  $databaseConnection->sql_free_result($res);
1336  }
1337  if (is_array($this->contentElementCache[$languageId][$colPos])) {
1338  return array_keys($this->contentElementCache[$languageId][$colPos]);
1339  }
1340  return array();
1341  }
1342 
1348  public function pageIsNotLockedForEditors()
1349  {
1350  return $this->getBackendUser()->isAdmin() || ($this->CALC_PERMS & Permission::PAGE_EDIT) === Permission::PAGE_EDIT && !$this->pageinfo['editlock'];
1351  }
1352 
1358  protected function getLanguageService()
1359  {
1360  return $GLOBALS['LANG'];
1361  }
1362 
1368  protected function getBackendUser()
1369  {
1370  return $GLOBALS['BE_USER'];
1371  }
1372 
1378  protected function getDatabaseConnection()
1379  {
1380  return $GLOBALS['TYPO3_DB'];
1381  }
1382 
1388  protected function getPageRenderer()
1389  {
1390  return GeneralUtility::makeInstance(PageRenderer::class);
1391  }
1392 
1398  protected function makeQuickEditMenu($edit_record)
1399  {
1400  $lang = $this->getLanguageService();
1401  $databaseConnection = $this->getDatabaseConnection();
1402  $beUser = $this->getBackendUser();
1403 
1404  $quickEditMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1405  $quickEditMenu->setIdentifier('quickEditMenu');
1406  $quickEditMenu->setLabel('');
1407 
1408  // Setting close url/return url for exiting this script:
1409  // Goes to 'Columns' view if close is pressed (default)
1410  $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
1411  if ($this->returnUrl) {
1412  $this->closeUrl = $this->returnUrl;
1413  }
1414  $retUrlStr = $this->returnUrl ? '&returnUrl=' . rawurlencode($this->returnUrl) : '';
1415 
1416  // Creating the selector box, allowing the user to select which element to edit:
1417  $isSelected = 0;
1418  $languageOverlayRecord = '';
1419  if ($this->current_sys_language) {
1420  list($languageOverlayRecord) = BackendUtility::getRecordsByField(
1421  'pages_language_overlay',
1422  'pid',
1423  $this->id,
1424  'AND sys_language_uid=' . (int)$this->current_sys_language
1425  );
1426  }
1427  if (is_array($languageOverlayRecord)) {
1428  $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
1429  $isSelected += (int)$edit_record == $inValue;
1430  $menuItem = $quickEditMenu->makeMenuItem()
1431  ->setTitle('[ ' . $lang->getLL('editLanguageHeader', true) . ' ]')
1432  ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $inValue . $retUrlStr)
1433  ->setActive($edit_record == $inValue);
1434  $quickEditMenu->addMenuItem($menuItem);
1435  } else {
1436  $inValue = 'pages:' . $this->id;
1437  $isSelected += (int)$edit_record == $inValue;
1438  $menuItem = $quickEditMenu->makeMenuItem()
1439  ->setTitle('[ ' . $lang->getLL('editPageProperties', true) . ' ]')
1440  ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $inValue . $retUrlStr)
1441  ->setActive($edit_record == $inValue);
1442  $quickEditMenu->addMenuItem($menuItem);
1443  }
1444  // Selecting all content elements from this language and allowed colPos:
1445  $whereClause = 'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . ' AND colPos IN (' . $this->colPosList . ')' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content');
1446  if (!$this->getBackendUser()->user['admin']) {
1447  $whereClause .= ' AND editlock = 0';
1448  }
1449  $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', $whereClause, '', 'colPos,sorting');
1450  $colPos = null;
1451  $first = 1;
1452  // Page is the pid if no record to put this after.
1453  $prev = $this->id;
1454  while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
1455  BackendUtility::workspaceOL('tt_content', $cRow);
1456  if (is_array($cRow)) {
1457  if ($first) {
1458  if (!$edit_record) {
1459  $edit_record = 'tt_content:' . $cRow['uid'];
1460  }
1461  $first = 0;
1462  }
1463  if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
1464  $colPos = $cRow['colPos'];
1465  $menuItem = $quickEditMenu->makeMenuItem()
1466  ->setTitle(' ')
1467  ->setHref('#');
1468  $quickEditMenu->addMenuItem($menuItem);
1469  $menuItem = $quickEditMenu->makeMenuItem()
1470  ->setTitle('__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), true) . ':__')
1471  ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=_EDIT_COL:' . $colPos . $retUrlStr);
1472  $quickEditMenu->addMenuItem($menuItem);
1473  }
1474  $inValue = 'tt_content:' . $cRow['uid'];
1475  $isSelected += (int)$edit_record == $inValue;
1476  $menuItem = $quickEditMenu->makeMenuItem()
1477  ->setTitle(htmlspecialchars(GeneralUtility::fixed_lgd_cs(($cRow['header'] ? $cRow['header'] : '[' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title') . '] ' . strip_tags($cRow['bodytext'])), $beUser->uc['titleLen'])))
1478  ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $inValue . $retUrlStr)
1479  ->setActive($edit_record == $inValue);
1480  $quickEditMenu->addMenuItem($menuItem);
1481  $prev = -$cRow['uid'];
1482  }
1483  }
1484  // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
1485  if (!$edit_record) {
1486  $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
1487  $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
1488  $isSelected += (int)$edit_record == $inValue;
1489  $menuItem = $quickEditMenu->makeMenuItem()
1490  ->setTitle('[ ' . $lang->getLL('newLabel', 1) . ' ]')
1491  ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $inValue . $retUrlStr)
1492  ->setActive($edit_record == $inValue);
1493  $quickEditMenu->addMenuItem($menuItem);
1494  }
1495  // If none is yet selected...
1496  if (!$isSelected) {
1497  $menuItem = $quickEditMenu->makeMenuItem()
1498  ->setTitle('__________')
1499  ->setHref('#');
1500  $quickEditMenu->addMenuItem($menuItem);
1501  $menuItem = $quickEditMenu->makeMenuItem()
1502  ->setTitle('[ ' . $lang->getLL('newLabel', true) . ' ]')
1503  ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&edit_record=' . $edit_record . $retUrlStr)
1504  ->setActive($edit_record == $inValue);
1505  $quickEditMenu->addMenuItem($menuItem);
1506  }
1507  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($quickEditMenu);
1508  return $edit_record;
1509  }
1510 
1516  protected function makeLanguageMenu()
1517  {
1518  if (count($this->MOD_MENU['language']) > 1) {
1519  $lang = $this->getLanguageService();
1520  $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1521  $languageMenu->setIdentifier('languageMenu');
1522  $languageMenu->setLabel($lang->sL('LLL:EXT:lang/locallang_general.xlf:LGL.language', true));
1523  foreach ($this->MOD_MENU['language'] as $key => $language) {
1524  $menuItem = $languageMenu
1525  ->makeMenuItem()
1526  ->setTitle($language)
1527  ->setHref(BackendUtility::getModuleUrl($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
1528  if ((int)$this->current_sys_language === $key) {
1529  $menuItem->setActive(true);
1530  }
1531  $languageMenu->addMenuItem($menuItem);
1532  }
1533  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
1534  }
1535  }
1536 }