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