[TASK] Reduce PageLayoutController and PageLayoutView dependencies
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageLayoutController.php
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
17 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedException;
18 use TYPO3\CMS\Backend\Form\FormDataCompiler;
19 use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
20 use TYPO3\CMS\Backend\Form\FormResultCompiler;
21 use TYPO3\CMS\Backend\Form\NodeFactory;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Backend\Utility\IconUtility;
24 use TYPO3\CMS\Core\Imaging\Icon;
25 use TYPO3\CMS\Core\Imaging\IconFactory;
26 use TYPO3\CMS\Core\Page\PageRenderer;
27 use TYPO3\CMS\Core\Type\Bitmask\Permission;
28 use TYPO3\CMS\Core\Messaging\FlashMessage;
29 use TYPO3\CMS\Core\Utility\GeneralUtility;
30 use TYPO3\CMS\Core\Utility\HttpUtility;
31 use TYPO3\CMS\Core\Utility\MathUtility;
32 use TYPO3\CMS\Fluid\View\StandaloneView;
33 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
34 use TYPO3\CMS\Recordlist\RecordList;
35 use TYPO3\CMS\Core\DataHandling\DataHandler;
36 use TYPO3\CMS\Frontend\Page\PageRepository;
37 use TYPO3\CMS\Backend\Module\ModuleLoader;
38 use TYPO3\CMS\Backend\Template\DocumentTemplate;
39 use TYPO3\CMS\Backend\View\BackendLayoutView;
40 use TYPO3\CMS\Core\Messaging\FlashMessageService;
41 use TYPO3\CMS\Backend\View\PageLayoutView;
42 use TYPO3\CMS\Backend\Tree\View\ContentLayoutPagePositionMap;
43 use TYPO3\CMS\Core\Versioning\VersionState;
44
45 /**
46 * Script Class for Web > Layout module
47 */
48 class PageLayoutController {
49
50 /**
51 * Page Id for which to make the listing
52 *
53 * @var int
54 */
55 public $id;
56
57 /**
58 * Pointer - for browsing list of records.
59 *
60 * @var int
61 */
62 public $pointer;
63
64 /**
65 * Thumbnails or not
66 *
67 * @var string
68 */
69 public $imagemode;
70
71 /**
72 * Search-fields
73 *
74 * @var string
75 */
76 public $search_field;
77
78 /**
79 * Search-levels
80 *
81 * @var int
82 */
83 public $search_levels;
84
85 /**
86 * Show-limit
87 *
88 * @var int
89 */
90 public $showLimit;
91
92 /**
93 * Return URL
94 *
95 * @var string
96 */
97 public $returnUrl;
98
99 /**
100 * Clear-cache flag - if set, clears page cache for current id.
101 *
102 * @var bool
103 */
104 public $clear_cache;
105
106 /**
107 * PopView id - for opening a window with the page
108 *
109 * @var bool
110 */
111 public $popView;
112
113 /**
114 * QuickEdit: Variable, that tells quick edit what to show/edit etc.
115 * Format is [tablename]:[uid] with some exceptional values for both parameters (with special meanings).
116 *
117 * @var string
118 */
119 public $edit_record;
120
121 /**
122 * QuickEdit: If set, this variable tells quick edit that the last edited record had
123 * this value as UID and we should look up the new, real uid value in sys_log.
124 *
125 * @var string
126 */
127 public $new_unique_uid;
128
129 /**
130 * Page select perms clause
131 *
132 * @var string
133 */
134 public $perms_clause;
135
136 /**
137 * Module TSconfig
138 *
139 * @var array
140 */
141 public $modTSconfig;
142
143 /**
144 * Module shared TSconfig
145 *
146 * @var array
147 */
148 public $modSharedTSconfig;
149
150 /**
151 * Current ids page record
152 *
153 * @var array
154 */
155 public $pageinfo;
156
157 /**
158 * Document template object
159 *
160 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
161 */
162 public $doc;
163
164 /**
165 * "Pseudo" Description -table name
166 *
167 * @var string
168 */
169 public $descrTable;
170
171 /**
172 * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
173 *
174 * @var string
175 */
176 public $colPosList;
177
178 /**
179 * Flag: If content can be edited or not.
180 *
181 * @var bool
182 */
183 public $EDIT_CONTENT;
184
185 /**
186 * Users permissions integer for this page.
187 *
188 * @var int
189 */
190 public $CALC_PERMS;
191
192 /**
193 * Currently selected language for editing content elements
194 *
195 * @var int
196 */
197 public $current_sys_language;
198
199 /**
200 * Module configuration
201 *
202 * @var array
203 */
204 public $MCONF = array();
205
206 /**
207 * Menu configuration
208 *
209 * @var array
210 */
211 public $MOD_MENU = array();
212
213 /**
214 * Module settings (session variable)
215 *
216 * @var array
217 */
218 public $MOD_SETTINGS = array();
219
220 /**
221 * Array of tables to be listed by the Web > Page module in addition to the default tables
222 *
223 * @var array
224 */
225 public $externalTables = array();
226
227 /**
228 * Module output accumulation
229 *
230 * @var string
231 */
232 public $content;
233
234 /**
235 * Function menu temporary storage
236 *
237 * @var string
238 */
239 public $topFuncMenu;
240
241 /**
242 * List of column-integers accessible to the current BE user.
243 * Is set from TSconfig, default is $colPosList
244 *
245 * @var string
246 */
247 public $activeColPosList;
248
249 /**
250 * Markers array
251 *
252 * @var array
253 */
254 protected $markers = array();
255
256 /**
257 * @var array
258 */
259 protected $eRParts = array();
260
261 /**
262 * @var string
263 */
264 protected $editSelect;
265
266 /**
267 * @var bool
268 */
269 protected $deleteButton;
270
271 /**
272 * @var bool
273 */
274 protected $undoButton;
275
276 /**
277 * @var array
278 */
279 protected $undoButtonR;
280
281 /**
282 * @var string
283 */
284 protected $R_URI;
285
286 /**
287 * @var string
288 */
289 protected $closeUrl;
290
291 /**
292 * @var IconFactory
293 */
294 protected $iconFactory;
295
296 /**
297 * Initializing the module
298 *
299 * @return void
300 */
301 public function init() {
302 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
303 $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
304
305 // Setting module configuration / page select clause
306 $this->MCONF = $GLOBALS['MCONF'];
307 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
308 // Get session data
309 $sessionData = $this->getBackendUser()->getSessionData(RecordList::class);
310 $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
311 // GPvars:
312 $this->id = (int)GeneralUtility::_GP('id');
313 $this->pointer = GeneralUtility::_GP('pointer');
314 $this->imagemode = GeneralUtility::_GP('imagemode');
315 $this->clear_cache = GeneralUtility::_GP('clear_cache');
316 $this->popView = GeneralUtility::_GP('popView');
317 $this->edit_record = GeneralUtility::_GP('edit_record');
318 $this->new_unique_uid = GeneralUtility::_GP('new_unique_uid');
319 $this->search_field = GeneralUtility::_GP('search_field');
320 $this->search_levels = GeneralUtility::_GP('search_levels');
321 $this->showLimit = GeneralUtility::_GP('showLimit');
322 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
323 $this->externalTables = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables'];
324 $sessionData['search_field'] = $this->search_field;
325 // Store session data
326 $this->getBackendUser()->setAndSaveSessionData(RecordList::class, $sessionData);
327 // Load page info array:
328 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
329 // Initialize menu
330 $this->menuConfig();
331 // Setting sys language from session var:
332 $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
333 // CSH / Descriptions:
334 $this->descrTable = '_MOD_' . $this->MCONF['name'];
335
336 $this->markers['SEARCHBOX'] = '';
337 $this->markers['BUTTONLIST_ADDITIONAL'] = '';
338 }
339
340 /**
341 * Initialize menu array
342 *
343 * @return void
344 */
345 public function menuConfig() {
346 $lang = $this->getLanguageService();
347 // MENU-ITEMS:
348 $this->MOD_MENU = array(
349 'tt_content_showHidden' => '',
350 'function' => array(
351 0 => $lang->getLL('m_function_0'),
352 1 => $lang->getLL('m_function_1'),
353 2 => $lang->getLL('m_function_2')
354 ),
355 'language' => array(
356 0 => $lang->getLL('m_default')
357 )
358 );
359 // example settings:
360 // $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables']['tx_myext'] =
361 // array ('default' => array(
362 // 'MENU' => 'LLL:EXT:tx_myext/locallang_db.xlf:menuDefault',
363 // 'fList' => 'title,description,image',
364 // 'icon' => TRUE));
365 if (is_array($this->externalTables)) {
366 foreach ($this->externalTables as $table => $tableSettings) {
367 // delete the default settings from above
368 if (is_array($this->MOD_MENU[$table])) {
369 unset($this->MOD_MENU[$table]);
370 }
371 if (is_array($tableSettings) && count($tableSettings) > 1) {
372 foreach ($tableSettings as $key => $settings) {
373 $this->MOD_MENU[$table][$key] = $lang->sL($settings['MENU']);
374 }
375 }
376 }
377 }
378 // 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.
379 $res = $this->exec_languageQuery($this->id);
380 while ($lRow = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
381 if ($this->getBackendUser()->checkLanguageAccess($lRow['uid'])) {
382 $this->MOD_MENU['language'][$lRow['uid']] = $lRow['hidden'] ? '(' . $lRow['title'] . ')' : $lRow['title'];
383 }
384 }
385 // Find if there are ANY languages at all (and if not, remove the language option from function menu).
386 $count = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', $this->getBackendUser()->isAdmin() ? '' : 'hidden=0');
387 if (!$count) {
388 unset($this->MOD_MENU['function']['2']);
389 }
390 // page/be_user TSconfig settings and blinding of menu-items
391 $this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
392 $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
393 if ($this->modTSconfig['properties']['QEisDefault']) {
394 ksort($this->MOD_MENU['function']);
395 }
396 $this->MOD_MENU['function'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function');
397 // Remove QuickEdit as option if page type is not...
398 if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ',6', $this->pageinfo['doktype'])) {
399 unset($this->MOD_MENU['function'][0]);
400 }
401 // Setting alternative default label:
402 if (($this->modSharedTSconfig['properties']['defaultLanguageLabel'] || $this->modTSconfig['properties']['defaultLanguageLabel']) && isset($this->MOD_MENU['language'][0])) {
403 $this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
404 }
405 // Clean up settings
406 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), 'web_layout');
407 // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
408 if ($this->getBackendUser()->workspace != 0 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0') {
409 $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
410 }
411 }
412
413 /**
414 * Clears page cache for the current id, $this->id
415 *
416 * @return void
417 */
418 public function clearCache() {
419 if ($this->clear_cache) {
420 $tce = GeneralUtility::makeInstance(DataHandler::class);
421 $tce->stripslashes_values = FALSE;
422 $tce->start(array(), array());
423 $tce->clear_cacheCmd($this->id);
424 }
425 }
426
427 /**
428 * Generate the flashmessages for current pid
429 *
430 * @return string HTML content with flashmessages
431 */
432 protected function getHeaderFlashMessagesForCurrentPid() {
433 $content = '';
434 $lang = $this->getLanguageService();
435 // If page is a folder
436 if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
437 // Access to list module
438 $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
439 $moduleLoader->load($GLOBALS['TBE_MODULES']);
440 $modules = $moduleLoader->modules;
441 if (is_array($modules['web']['sub']['list'])) {
442 $title = $lang->getLL('goToListModule');
443 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
444 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
445
446 $view = GeneralUtility::makeInstance(StandaloneView::class);
447 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
448 $view->assignMultiple(array(
449 'title' => $title,
450 'message' => $message,
451 'state' => InfoboxViewHelper::STATE_INFO
452 ));
453 $content .= $view->render();
454 }
455 }
456 // If content from different pid is displayed
457 if ($this->pageinfo['content_from_pid']) {
458 $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
459 $title = BackendUtility::getRecordTitle('pages', $contentPage);
460 $linkToPid = $this->local_linkThisScript(array('id' => $this->pageinfo['content_from_pid']));
461 $link = '<a href="' . $linkToPid . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
462 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, sprintf($lang->getLL('content_from_pid_title'), $link), '', FlashMessage::INFO);
463 $content .= $flashMessage->render();
464 }
465 return $content;
466 }
467
468 /**
469 *
470 * @return string $title
471 */
472 protected function getLocalizedPageTitle() {
473 if ($this->current_sys_language > 0) {
474 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
475 'title',
476 'pages_language_overlay',
477 'pid = ' . (int)$this->id .
478 ' AND sys_language_uid = ' . (int)$this->current_sys_language .
479 BackendUtility::deleteClause('pages_language_overlay') .
480 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
481 '',
482 '',
483 '',
484 'sys_language_uid'
485 );
486 return $overlayRecord['title'];
487 } else {
488 return $this->pageinfo['title'];
489 }
490 }
491
492 /**
493 * Main function.
494 * Creates some general objects and calls other functions for the main rendering of module content.
495 *
496 * @return void
497 */
498 public function main() {
499 $lang = $this->getLanguageService();
500 // Access check...
501 // The page will show only if there is a valid page and if this page may be viewed by the user
502 $access = is_array($this->pageinfo) ? 1 : 0;
503 if ($this->id && $access) {
504 // Initialize permission settings:
505 $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
506 $this->EDIT_CONTENT = $this->pageIsNotLockedForEditors();
507
508 // Start document template object:
509 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
510 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
511
512 // override the default jumpToUrl
513 $this->doc->JScodeArray['jumpToUrl'] = '
514 function jumpToUrl(URL,formEl) {
515 if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
516 if (!TBE_EDITOR.isFormChanged()) {
517 window.location.href = URL;
518 } else if (formEl) {
519 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
520 }
521 } else {
522 window.location.href = URL;
523 }
524 }
525 ';
526
527 $this->doc->JScode .= $this->doc->wrapScriptTags('
528 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
529 if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
530 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
531
532 function deleteRecord(table,id,url) { //
533 if (confirm(' . GeneralUtility::quoteJSvalue($lang->getLL('deleteWarning')) . ')) {
534 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";
535 }
536 return false;
537 }
538 ');
539 // Setting doc-header
540 $this->doc->form = '<form action="' . htmlspecialchars(
541 BackendUtility::getModuleUrl(
542 'web_layout', array('id' => $this->id, 'imagemode' => $this->imagemode)
543 )) . '" method="post">';
544 // Creating the top function menu:
545 $this->topFuncMenu = BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function'], '', '');
546 $languageMenu = count($this->MOD_MENU['language']) > 1 ? $lang->sL('LLL:EXT:lang/locallang_general.xlf:LGL.language', TRUE) . BackendUtility::getFuncMenu($this->id, 'SET[language]', $this->current_sys_language, $this->MOD_MENU['language'], '', '') : '';
547 // Find backend layout / coumns
548 $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
549 if (!empty($backendLayout['__colPosList'])) {
550 $this->colPosList = implode(',', $backendLayout['__colPosList']);
551 }
552 // Removing duplicates, if any
553 $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
554 // Accessible columns
555 if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
556 $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
557 // Match with the list which is present in the colPosList for the current page
558 if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
559 $this->activeColPosList = array_unique(array_intersect(
560 $this->activeColPosList,
561 $this->colPosList
562 ));
563 }
564 } else {
565 $this->activeColPosList = $this->colPosList;
566 }
567 $this->activeColPosList = implode(',', $this->activeColPosList);
568 $this->colPosList = implode(',', $this->colPosList);
569
570 $body = '';
571 $body .= $this->getHeaderFlashMessagesForCurrentPid();
572 // Render the primary module content:
573 if ($this->MOD_SETTINGS['function'] == 0) {
574 // QuickEdit
575 $body .= $this->renderQuickEdit();
576 } else {
577 // Page title
578 $body .= $this->doc->header($this->getLocalizedPageTitle());
579 // All other listings
580 $body .= $this->renderListContent();
581 }
582 // Setting up the buttons and markers for docheader
583 $docHeaderButtons = $this->getButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
584 $this->markers['CSH'] = $docHeaderButtons['csh'];
585 $this->markers['TOP_FUNCTION_MENU'] = $this->topFuncMenu . $this->editSelect;
586 $this->markers['LANGSELECTOR'] = $languageMenu;
587 $this->markers['CONTENT'] = $body;
588 // Build the <body> for the module
589 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
590 // Renders the module page
591 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
592 } else {
593 // If no access or id value, create empty document:
594 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
595 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
596 $this->doc->JScode = $this->doc->wrapScriptTags('
597 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
598 ');
599
600 $body = $this->doc->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
601
602 $title = $lang->getLL('clickAPage_header');
603 $message = $lang->getLL('clickAPage_content');
604
605 $view = GeneralUtility::makeInstance(StandaloneView::class);
606 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
607 $view->assignMultiple(array(
608 'title' => $title,
609 'message' => $message,
610 'state' => InfoboxViewHelper::STATE_INFO
611 ));
612 $body .= $view->render();
613
614 // Setting up the buttons and markers for docheader
615 $docHeaderButtons = array(
616 'view' => '',
617 'history_page' => '',
618 'new_content' => '',
619 'move_page' => '',
620 'move_record' => '',
621 'new_page' => '',
622 'edit_page' => '',
623 'csh' => '',
624 'shortcut' => '',
625 'cache' => '',
626 'savedok' => '',
627 'savedokshow' => '',
628 'closedok' => '',
629 'deletedok' => '',
630 'undo' => '',
631 'history_record' => '',
632 'edit_language' => ''
633 );
634 $this->markers['CSH'] = '';
635 $this->markers['TOP_FUNCTION_MENU'] = '';
636 $this->markers['LANGSELECTOR'] = '';
637 $this->markers['CONTENT'] = $body;
638 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
639 // Renders the module page
640 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
641 }
642 }
643
644 /**
645 * Rendering the quick-edit view.
646 *
647 * @return string
648 */
649 public function renderQuickEdit() {
650 $databaseConnection = $this->getDatabaseConnection();
651 $beUser = $this->getBackendUser();
652 $lang = $this->getLanguageService();
653 // Alternative template
654 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout_quickedit.html');
655 // Alternative form tag; Quick Edit submits its content to tce_db.php.
656 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db', ['prErr' => 1, 'uPT' => 1])) . '" method="post" enctype="multipart/form-data" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
657 // Setting up the context sensitive menu:
658 $this->doc->getContextMenuCode();
659 // Set the edit_record value for internal use in this function:
660 $edit_record = $this->edit_record;
661 // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
662 if (substr($edit_record, 0, 9) == '_EDIT_COL') {
663 $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');
664 $idListA = array();
665 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
666 $idListA[] = $cRow['uid'];
667 }
668 $url = BackendUtility::getModuleUrl('record_edit', array(
669 'edit[tt_content][' . implode(',', $idListA) . ']' => 'edit',
670 'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))
671 ));
672 HttpUtility::redirect($url);
673 }
674 // If the former record edited was the creation of a NEW record, this will look up the created records uid:
675 if ($this->new_unique_uid) {
676 $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int)$beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
677 $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
678 if (is_array($sys_log_row)) {
679 $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
680 }
681 }
682 // Creating the selector box, allowing the user to select which element to edit:
683 $opt = array();
684 $is_selected = 0;
685 $languageOverlayRecord = '';
686 if ($this->current_sys_language) {
687 list($languageOverlayRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . (int)$this->current_sys_language);
688 }
689 if (is_array($languageOverlayRecord)) {
690 $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
691 $is_selected += (int)$edit_record == $inValue;
692 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editLanguageHeader', TRUE) . ' ]</option>';
693 } else {
694 $inValue = 'pages:' . $this->id;
695 $is_selected += (int)$edit_record == $inValue;
696 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editPageProperties', TRUE) . ' ]</option>';
697 }
698 // Selecting all content elements from this language and allowed colPos:
699 $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');
700 if (!$this->getBackendUser()->user['admin']) {
701 $whereClause .= ' AND editlock = 0';
702 }
703 $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', $whereClause, '', 'colPos,sorting');
704 $colPos = NULL;
705 $first = 1;
706 // Page is the pid if no record to put this after.
707 $prev = $this->id;
708 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
709 BackendUtility::workspaceOL('tt_content', $cRow);
710 if (is_array($cRow)) {
711 if ($first) {
712 if (!$edit_record) {
713 $edit_record = 'tt_content:' . $cRow['uid'];
714 }
715 $first = 0;
716 }
717 if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
718 $colPos = $cRow['colPos'];
719 $opt[] = '<option value=""></option>';
720 $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
721 }
722 $inValue = 'tt_content:' . $cRow['uid'];
723 $is_selected += (int)$edit_record == $inValue;
724 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>' . 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'])) . '</option>';
725 $prev = -$cRow['uid'];
726 }
727 }
728 // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
729 if (!$edit_record) {
730 $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
731 $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
732 $is_selected += (int)$edit_record == $inValue;
733 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('newLabel', 1) . ' ]</option>';
734 }
735 // If none is yet selected...
736 if (!$is_selected) {
737 $opt[] = '<option value=""></option>';
738 $opt[] = '<option value="' . $edit_record . '" selected="selected">[ ' . $lang->getLL('newLabel', TRUE) . ' ]</option>';
739 }
740 // Splitting the edit-record cmd value into table/uid:
741 $this->eRParts = explode(':', $edit_record);
742 $tableName = $this->eRParts[0];
743 // Delete-button flag?
744 $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($tableName !== 'pages' && $this->EDIT_CONTENT || $tableName === 'pages' && $this->CALC_PERMS & Permission::PAGE_DELETE);
745 // If undo-button should be rendered (depends on available items in sys_history)
746 $this->undoButton = FALSE;
747 $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($tableName, 'sys_history') . ' AND recuid=' . (int)$this->eRParts[1], '', 'tstamp DESC', '1');
748 if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
749 $this->undoButton = TRUE;
750 }
751 // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
752 $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
753 $R_URL_getvars = GeneralUtility::_GET();
754 unset($R_URL_getvars['popView']);
755 unset($R_URL_getvars['new_unique_uid']);
756 $R_URL_getvars['edit_record'] = $edit_record;
757 $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
758 // Setting close url/return url for exiting this script:
759 // Goes to 'Columns' view if close is pressed (default)
760 $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
761 if ($this->returnUrl) {
762 $this->closeUrl = $this->returnUrl;
763 }
764 // Return-url for JavaScript:
765 $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+' . GeneralUtility::quoteJSvalue(rawurlencode($this->returnUrl)) : '';
766 // Drawing the edit record selectbox
767 $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue(
768 BackendUtility::getModuleUrl('web_layout') . '&id=' . $this->id . '&edit_record='
769 ) . '+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
770
771 // Creating editing form:
772 $content = '';
773
774 if ($edit_record) {
775 // Splitting uid parts for special features, if new:
776 list($uidVal, $neighborRecordUid, $ex_colPos) = explode('/', $this->eRParts[1]);
777
778 if ($uidVal === 'new') {
779 $command = 'new';
780 // Page id of this new record
781 $theUid = $this->id;
782 if ($neighborRecordUid) {
783 $theUid = $neighborRecordUid;
784 }
785 } else {
786 $command = 'edit';
787 $theUid = $uidVal;
788 // Convert $uidVal to workspace version if any:
789 $draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $tableName, $theUid, 'uid');
790 if ($draftRecord) {
791 $theUid = $draftRecord['uid'];
792 }
793 }
794
795 // @todo: Hack because DatabaseInitializeNewRow reads from _GP directly
796 $GLOBALS['_GET']['defVals'][$tableName] = array(
797 'colPos' => (int)$ex_colPos,
798 'sys_language_uid' => (int)$this->current_sys_language
799 );
800
801 /** @var TcaDatabaseRecord $formDataGroup */
802 $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
803 /** @var FormDataCompiler $formDataCompiler */
804 $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
805 /** @var NodeFactory $nodeFactory */
806 $nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
807
808 try {
809 $formDataCompilerInput = [
810 'tableName' => $tableName,
811 'vanillaUid' => (int)$theUid,
812 'command' => $command,
813 ];
814 $formData = $formDataCompiler->compile($formDataCompilerInput);
815
816 if ($command !== 'new') {
817 BackendUtility::lockRecords($tableName, $formData['databaseRow']['uid'], $tableName === 'tt_content' ? $formData['databaseRow']['pid'] : 0);
818 }
819
820 $formData['renderType'] = 'outerWrapContainer';
821 $formResult = $nodeFactory->create($formData)->render();
822
823 $panel = $formResult['html'];
824 $formResult['html'] = '';
825
826 /** @var FormResultCompiler $formResultCompiler */
827 $formResultCompiler = GeneralUtility::makeInstance(FormResultCompiler::class);
828 $formResultCompiler->mergeResult($formResult);
829
830 $row = $formData['databaseRow'];
831 $new_unique_uid = '';
832 if ($command === 'new') {
833 $new_unique_uid = $row['uid'];
834 }
835
836 // Add hidden fields:
837 if ($uidVal == 'new') {
838 $panel .= '<input type="hidden" name="data[' . $tableName . '][' . $row['uid'] . '][pid]" value="' . $row['pid'] . '" />';
839 }
840 $panel .= '
841 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
842 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
843 <input type="hidden" name="redirect" value="' . htmlspecialchars(($uidVal == 'new' ? BackendUtility::getModuleUrl(
844 'web_layout',
845 array(
846 'id' => $this->id,
847 'new_unique_uid' => $new_unique_uid,
848 'returnUrl' => $this->returnUrl
849 )
850 ) : $this->R_URI)) . '" />
851 ';
852 // Add JavaScript as needed around the form:
853 $panel = $formResultCompiler->JStop() . $panel . $formResultCompiler->printNeededJSFunctions();
854 $content = $this->doc->section('', $panel);
855
856 // Display "is-locked" message:
857 if ($command === 'edit') {
858 $lockInfo = BackendUtility::isRecordLocked($tableName, $formData['databaseRow']['uid']);
859 if ($lockInfo) {
860 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
861 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
862 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
863 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
864 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
865 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
866 $defaultFlashMessageQueue->enqueue($flashMessage);
867 }
868 }
869 } catch (AccessDeniedException $e) {
870 // If no edit access, print error message:
871 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg')
872 . '<br /><br />'
873 . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : ''), 0, 1
874 );
875 }
876 } else {
877 // If no edit access, print error message:
878 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />', 0, 1);
879 }
880
881 // Bottom controls (function menus):
882 $q_count = $this->getNumberOfHiddenElements();
883 if ($q_count) {
884 $h_func_b = '<div class="checkbox">' .
885 '<label for="checkTt_content_showHidden">' .
886 BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"') .
887 (!$q_count ? ('<span class="text-muted">' . $lang->getLL('hiddenCE', TRUE) . '</span>') : $lang->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') .
888 '</label>' .
889 '</div>';
890
891 $content .= $this->doc->section('', $h_func_b, 0, 0);
892 $content .= $this->doc->spacer(10);
893 }
894
895 // Select element matrix:
896 if ($tableName === 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
897 $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
898 $posMap->cur_sys_language = $this->current_sys_language;
899 $HTMLcode = '';
900 // CSH:
901 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
902 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
903 $content .= $this->doc->spacer(20);
904 $content .= $this->doc->section($lang->getLL('CEonThisPage'), $HTMLcode, 0, 1);
905 $content .= $this->doc->spacer(20);
906 }
907
908 return $content;
909 }
910
911 /**
912 * Rendering all other listings than QuickEdit
913 *
914 * @return string
915 */
916 public function renderListContent() {
917 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
918 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
919 $dbList->thumbs = $this->imagemode;
920 $dbList->no_noWrap = 1;
921 $dbList->descrTable = $this->descrTable;
922 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
923 $dbList->script = BackendUtility::getModuleUrl('web_layout');
924 $dbList->showIcon = 0;
925 $dbList->setLMargin = 0;
926 $dbList->doEdit = $this->EDIT_CONTENT;
927 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
928 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
929 $dbList->id = $this->id;
930 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
931 $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
932 $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
933 if (!$dbList->nextThree) {
934 $dbList->nextThree = 1;
935 }
936 $dbList->externalTables = $this->externalTables;
937 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
938 // also fills $dbList->activeTables
939 $dbList->getTableMenu($this->id);
940 // Initialize other variables:
941 $h_func = '';
942 $tableOutput = array();
943 $tableJSOutput = array();
944 $CMcounter = 0;
945 // Traverse the list of table names which has records on this page (that array is populated
946 // by the $dblist object during the function getTableMenu()):
947 foreach ($dbList->activeTables as $table => $value) {
948 $h_func_b = '';
949 if (!isset($dbList->externalTables[$table])) {
950 $q_count = $this->getNumberOfHiddenElements();
951
952 if ($q_count > 0) {
953 $h_func_b =
954 '<div class="checkbox">'
955 . '<label for="checkTt_content_showHidden">'
956 . '<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />'
957 . $this->getLanguageService()->getLL('hiddenCE', TRUE) . ' (<span class="t3js-hidden-counter">' . $q_count . '</span>)'
958 . '</label>'
959 . '</div>';
960 }
961 // Boolean: Display up/down arrows and edit icons for tt_content records
962 $dbList->tt_contentConfig['showCommands'] = 1;
963 // Boolean: Display info-marks or not
964 $dbList->tt_contentConfig['showInfo'] = 1;
965 // Setting up the tt_content columns to show:
966 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
967 $colList = array();
968 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
969 foreach ($tcaItems as $temp) {
970 $colList[] = $temp[1];
971 }
972 } else {
973 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
974 $colList = array('1', '0', '2', '3');
975 }
976 if ($this->colPosList !== '') {
977 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
978 }
979 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
980 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
981 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
982 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
983 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
984 // If the function menu is set to "Language":
985 if ($this->MOD_SETTINGS['function'] == 2) {
986 $dbList->tt_contentConfig['languageMode'] = 1;
987 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
988 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
989 }
990 } else {
991 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
992 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
993 } else {
994 $h_func = '';
995 }
996 }
997 // Start the dblist object:
998 $dbList->itemsLimitSingleTable = 1000;
999 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
1000 $dbList->counter = $CMcounter;
1001 $dbList->ext_function = $this->MOD_SETTINGS['function'];
1002 // Render versioning selector:
1003 $dbList->HTMLcode .= $this->doc->getVersionSelector($this->id);
1004 // Generate the list of elements here:
1005 $dbList->generateList();
1006 // Adding the list content to the tableOutput variable:
1007 $tableOutput[$table] = ($h_func ? $h_func . '<br /><span style="width: 1px; height: 4px; display: inline-block;"></span><br />' : '') . $dbList->HTMLcode . ($h_func_b ? '<span style="width: 1px; height: 10px; display:inline-block;"></span><br />' . $h_func_b : '');
1008 // ... and any accumulated JavaScript goes the same way!
1009 $tableJSOutput[$table] = $dbList->JScode;
1010 // Increase global counter:
1011 $CMcounter += $dbList->counter;
1012 // Reset variables after operation:
1013 $dbList->HTMLcode = '';
1014 $dbList->JScode = '';
1015 $h_func = '';
1016 }
1017 // END: traverse tables
1018 // For Context Sensitive Menus:
1019 $this->doc->getContextMenuCode();
1020 // Init the content
1021 $content = '';
1022 // Additional header content
1023 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
1024 if (is_array($headerContentHook)) {
1025 foreach ($headerContentHook as $hook) {
1026 $params = array();
1027 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1028 }
1029 }
1030 // Add the content for each table we have rendered (traversing $tableOutput variable)
1031 foreach ($tableOutput as $table => $output) {
1032 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
1033 $content .= $this->doc->sectionEnd();
1034 }
1035 // Making search form:
1036 if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
1037 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
1038 $this->markers['BUTTONLIST_ADDITIONAL'] = '<a href="#" class="t3js-toggle-search-toolbox" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', TRUE) . '">' . $this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL) . '</a>';
1039 $this->markers['SEARCHBOX'] = $dbList->getSearchBox(0);
1040 }
1041 // Additional footer content
1042 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1043 if (is_array($footerContentHook)) {
1044 foreach ($footerContentHook as $hook) {
1045 $params = array();
1046 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1047 }
1048 }
1049 return $content;
1050 }
1051
1052 /**
1053 * Print accumulated content of module
1054 *
1055 * @return void
1056 */
1057 public function printContent() {
1058 echo $this->content;
1059 }
1060
1061 /***************************
1062 *
1063 * Sub-content functions, rendering specific parts of the module content.
1064 *
1065 ***************************/
1066 /**
1067 * Create the panel of buttons for submitting the form or otherwise perform operations.
1068 *
1069 * @param string $function Identifier for function of module
1070 * @return array all available buttons as an assoc. array
1071 */
1072 protected function getButtons($function = '') {
1073 $lang = $this->getLanguageService();
1074 $buttons = array(
1075 'view' => '',
1076 'history_page' => '',
1077 'new_content' => '',
1078 'move_page' => '',
1079 'move_record' => '',
1080 'new_page' => '',
1081 'edit_page' => '',
1082 'edit_language' => '',
1083 'csh' => '',
1084 'shortcut' => '',
1085 'cache' => '',
1086 'savedok' => '',
1087 'save_close' => '',
1088 'savedokshow' => '',
1089 'closedok' => '',
1090 'deletedok' => '',
1091 'undo' => '',
1092 'history_record' => ''
1093 );
1094 // View page
1095 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1096 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL) . '</a>';
1097 }
1098 // Shortcut
1099 if ($this->getBackendUser()->mayMakeShortcut()) {
1100 $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
1101 }
1102 // Cache
1103 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1104 $buttons['cache'] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_layout', array('id' => $this->pageinfo['uid'], 'clear_cache' => '1'))) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.clear_cache', TRUE) . '">' . $this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL)->render() . '</a>';
1105 }
1106 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1107 // Move record
1108 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1109 $urlParameters = [
1110 'table' => $this->eRParts[0],
1111 'uid' => $this->eRParts[1],
1112 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1113 ];
1114 $buttons['move_record'] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('move_element', $urlParameters)) . '" title="' . $lang->getLL('move_' . ($this->eRParts[0] == 'tt_content' ? 'record' : 'page'), TRUE) . '">' . $this->iconFactory->getIcon('actions-' . ($this->eRParts[0] == 'tt_content' ? 'document' : 'page') . '-move', Icon::SIZE_SMALL)->render() . '</a>';
1115 }
1116
1117 // Edit page properties and page language overlay icons
1118 if ($this->pageIsNotLockedForEditors()) {
1119
1120 // Edit localized page_language_overlay only when one specific language is selected
1121 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1122 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
1123 'uid',
1124 'pages_language_overlay',
1125 'pid = ' . (int)$this->id . ' ' .
1126 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1127 BackendUtility::deleteClause('pages_language_overlay') .
1128 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1129 '',
1130 '',
1131 '',
1132 'sys_language_uid'
1133 );
1134
1135 $editLanguageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit'));
1136 $buttons['edit_language'] = '<a href="#" ' .
1137 'onclick="' . $editLanguageOnClick . '"' .
1138 'title="' . $lang->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1139 $this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL) .
1140 '</a>';
1141 }
1142
1143
1144 // Edit page properties
1145 $editPageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit'));
1146 $buttons['edit_page'] = '<a href="#" onclick="' . $editPageOnClick . '" title="' . $lang->getLL('editPageProperties', TRUE) . '">'
1147 . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)
1148 . '</a>';
1149 }
1150
1151 // Add CSH (Context Sensitive Help) icon to tool bar
1152 if ($function == 'quickEdit') {
1153 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit');
1154 } else {
1155 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function']);
1156 }
1157 if ($function == 'quickEdit') {
1158 // Save record
1159 $buttons['savedok'] = '<button class="c-inputButton" name="_savedok_x" value="1" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '">'
1160 . $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)
1161 . '</button>';
1162 // Save and close
1163 $buttons['save_close'] = '<button class="c-inputButton" name="_saveandclosedok_x" value="1" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '">'
1164 . $this->iconFactory->getIcon('actions-document-save-close', Icon::SIZE_SMALL)
1165 . '</button>';
1166 // Save record and show page
1167 $buttons['savedokshow'] = '<a href="#" onclick="' . htmlspecialchars('document.editform.redirect.value+=\'&popView=1\'; TBE_EDITOR.checkAndDoSubmit(1); return false;') . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', TRUE) . '">'
1168 . $this->iconFactory->getIcon('actions-document-save-view', Icon::SIZE_SMALL)
1169 . '</a>';
1170 // Close record
1171 $buttons['closedok'] = '<a href="#" onclick="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue($this->closeUrl) . '); return false;') . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">'
1172 . $this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)
1173 . '</a>';
1174 // Delete record
1175 if ($this->deleteButton) {
1176 $buttons['deletedok'] = '<a href="#" onclick="' . htmlspecialchars('return deleteRecord(' . GeneralUtility::quoteJSvalue($this->eRParts[0]) . ',' . GeneralUtility::quoteJSvalue($this->eRParts[1]) . ',' . GeneralUtility::quoteJSvalue(GeneralUtility::getIndpEnv('SCRIPT_NAME') . '?id=' . $this->id) . ');') . '" title="' . $lang->getLL('deleteItem', TRUE) . '">'
1177 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)
1178 . '</a>';
1179 }
1180 if ($this->undoButton) {
1181 // Undo button
1182 $buttons['undo'] = '<a href="#"
1183 onclick="' . htmlspecialchars('window.location.href=' .
1184 GeneralUtility::quoteJSvalue(
1185 BackendUtility::getModuleUrl(
1186 'record_history',
1187 array(
1188 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1189 'revert' => 'ALL_FIELDS',
1190 'sumUp' => -1,
1191 'returnUrl' => $this->R_URI,
1192 )
1193 )
1194 ) . '; return false;') . '"
1195 title="' . htmlspecialchars(sprintf($lang->getLL('undoLastChange'), BackendUtility::calcAge($GLOBALS['EXEC_TIME'] - $this->undoButtonR['tstamp'], $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '">' . $this->iconFactory->getIcon('actions-edit-undo', Icon::SIZE_SMALL) . '</a>';
1196 // History button
1197 $buttons['history_record'] = '<a href="#"
1198 onclick="' . htmlspecialchars('jumpToUrl(' .
1199 GeneralUtility::quoteJSvalue(
1200 BackendUtility::getModuleUrl(
1201 'record_history',
1202 array(
1203 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1204 'returnUrl' => $this->R_URI,
1205 )
1206 ) . '#latest'
1207 ) . ');return false;') . '"
1208 title="' . $lang->getLL('recordHistory', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL) . '</a>';
1209 }
1210 }
1211 }
1212 return $buttons;
1213 }
1214
1215 /*******************************
1216 *
1217 * Other functions
1218 *
1219 ******************************/
1220 /**
1221 * Returns the number of hidden elements (including those hidden by start/end times)
1222 * on the current page (for the current sys_language)
1223 *
1224 * @return int
1225 */
1226 public function getNumberOfHiddenElements() {
1227 return $this->getDatabaseConnection()->exec_SELECTcountRows(
1228 'uid',
1229 'tt_content',
1230 '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')
1231 );
1232 }
1233
1234 /**
1235 * Returns URL to the current script.
1236 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1237 *
1238 * @param array $params Parameters array, merged with global GET vars.
1239 * @return string URL
1240 */
1241 public function local_linkThisScript($params) {
1242 $params['popView'] = '';
1243 $params['new_unique_uid'] = '';
1244 return GeneralUtility::linkThisScript($params);
1245 }
1246
1247 /**
1248 * Returns a SQL query for selecting sys_language records.
1249 *
1250 * @param int $id Page id: If zero, the query will select all sys_language records from root level which are NOT hidden. If set to another value, the query will select all sys_language records that has a pages_language_overlay record on that page (and is not hidden, unless you are admin user)
1251 * @return string Return query string.
1252 */
1253 public function exec_languageQuery($id) {
1254 if ($id) {
1255 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1256 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1257 return $this->getDatabaseConnection()->exec_SELECTquery(
1258 'sys_language.*',
1259 'pages_language_overlay,sys_language',
1260 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1261 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1262 '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',
1263 'sys_language.title'
1264 );
1265 } else {
1266 return $this->getDatabaseConnection()->exec_SELECTquery(
1267 'sys_language.*',
1268 'sys_language',
1269 'sys_language.hidden=0',
1270 '',
1271 'sys_language.title'
1272 );
1273 }
1274 }
1275
1276 /**
1277 * Check the editlock access
1278 *
1279 * @return bool
1280 */
1281 public function pageIsNotLockedForEditors() {
1282 return $this->getBackendUser()->isAdmin() || !($this->CALC_PERMS & Permission::PAGE_EDIT && $this->pageinfo['editlock']);
1283 }
1284
1285 /**
1286 * Returns LanguageService
1287 *
1288 * @return \TYPO3\CMS\Lang\LanguageService
1289 */
1290 protected function getLanguageService() {
1291 return $GLOBALS['LANG'];
1292 }
1293
1294 /**
1295 * Returns the current BE user.
1296 *
1297 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1298 */
1299 protected function getBackendUser() {
1300 return $GLOBALS['BE_USER'];
1301 }
1302
1303 /**
1304 * Returns the database connection
1305 *
1306 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1307 */
1308 protected function getDatabaseConnection() {
1309 return $GLOBALS['TYPO3_DB'];
1310 }
1311
1312 /**
1313 * Returns current PageRenderer
1314 *
1315 * @return PageRenderer
1316 */
1317 protected function getPageRenderer() {
1318 return GeneralUtility::makeInstance(PageRenderer::class);
1319 }
1320 }