[!!!][TASK] Use native trigger_error and ErrorHandler for deprecations
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayoutView.php
1 <?php
2
3 namespace TYPO3\CMS\Backend\View;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Doctrine\DBAL\Driver\Statement;
19 use Psr\Log\LoggerAwareInterface;
20 use Psr\Log\LoggerAwareTrait;
21 use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
22 use TYPO3\CMS\Backend\Controller\Page\LocalizationController;
23 use TYPO3\CMS\Backend\Controller\PageLayoutController;
24 use TYPO3\CMS\Backend\Routing\Router;
25 use TYPO3\CMS\Backend\Routing\UriBuilder;
26 use TYPO3\CMS\Backend\Tree\View\PageTreeView;
27 use TYPO3\CMS\Backend\Utility\BackendUtility;
28 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
29 use TYPO3\CMS\Core\Database\Connection;
30 use TYPO3\CMS\Core\Database\ConnectionPool;
31 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
32 use TYPO3\CMS\Core\Database\Query\QueryHelper;
33 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
34 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
35 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
36 use TYPO3\CMS\Core\Imaging\Icon;
37 use TYPO3\CMS\Core\Imaging\IconFactory;
38 use TYPO3\CMS\Core\Localization\LanguageService;
39 use TYPO3\CMS\Core\Messaging\FlashMessage;
40 use TYPO3\CMS\Core\Messaging\FlashMessageService;
41 use TYPO3\CMS\Core\Page\PageRenderer;
42 use TYPO3\CMS\Core\Service\DependencyOrderingService;
43 use TYPO3\CMS\Core\Type\Bitmask\Permission;
44 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
45 use TYPO3\CMS\Core\Utility\GeneralUtility;
46 use TYPO3\CMS\Core\Utility\HttpUtility;
47 use TYPO3\CMS\Core\Utility\MathUtility;
48 use TYPO3\CMS\Core\Utility\StringUtility;
49 use TYPO3\CMS\Core\Versioning\VersionState;
50 use TYPO3\CMS\Extbase\Service\FlexFormService;
51 use TYPO3\CMS\Fluid\View\StandaloneView;
52 use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
53
54 /**
55 * Child class for the Web > Page module
56 */
57 class PageLayoutView implements LoggerAwareInterface
58 {
59 use LoggerAwareTrait;
60
61 /**
62 * If TRUE, users/groups are shown in the page info box.
63 *
64 * @var int
65 */
66 public $pI_showUser = 0;
67
68 /**
69 * The number of successive records to edit when showing content elements.
70 *
71 * @var int
72 */
73 public $nextThree = 3;
74
75 /**
76 * If TRUE, disables the edit-column icon for tt_content elements
77 *
78 * @var int
79 */
80 public $pages_noEditColumns = 0;
81
82 /**
83 * If TRUE, new-wizards are linked to rather than the regular new-element list.
84 *
85 * @var int
86 */
87 public $option_newWizard = 1;
88
89 /**
90 * If set to "1", will link a big button to content element wizard.
91 *
92 * @var int
93 */
94 public $ext_function = 0;
95
96 /**
97 * If TRUE, elements will have edit icons (probably this is whether the user has permission to edit the page content). Set externally.
98 *
99 * @var int
100 */
101 public $doEdit = 1;
102
103 /**
104 * Age prefixes for displaying times. May be set externally to localized values.
105 *
106 * @var string
107 */
108 public $agePrefixes = ' min| hrs| days| yrs| min| hour| day| year';
109
110 /**
111 * Array of tables to be listed by the Web > Page module in addition to the default tables.
112 *
113 * @var array
114 */
115 public $externalTables = [];
116
117 /**
118 * "Pseudo" Description -table name
119 *
120 * @var string
121 */
122 public $descrTable;
123
124 /**
125 * If set TRUE, the language mode of tt_content elements will be rendered with hard binding between
126 * default language content elements and their translations!
127 *
128 * @var bool
129 */
130 public $defLangBinding = false;
131
132 /**
133 * External, static: Configuration of tt_content element display:
134 *
135 * @var array
136 */
137 public $tt_contentConfig = [
138 // Boolean: Display info-marks or not
139 'showInfo' => 1,
140 // Boolean: Display up/down arrows and edit icons for tt_content records
141 'showCommands' => 1,
142 'languageCols' => 0,
143 'languageMode' => 0,
144 'languageColsPointer' => 0,
145 'showHidden' => 1,
146 // Displays hidden records as well
147 'sys_language_uid' => 0,
148 // Which language
149 'cols' => '1,0,2,3',
150 'activeCols' => '1,0,2,3'
151 // Which columns can be accessed by current BE user
152 ];
153
154 /**
155 * Contains icon/title of pages which are listed in the tables menu (see getTableMenu() function )
156 *
157 * @var array
158 */
159 public $activeTables = [];
160
161 /**
162 * @var array
163 */
164 public $tt_contentData = [
165 'nextThree' => [],
166 'prev' => [],
167 'next' => []
168 ];
169
170 /**
171 * Used to store labels for CTypes for tt_content elements
172 *
173 * @var array
174 */
175 public $CType_labels = [];
176
177 /**
178 * Used to store labels for the various fields in tt_content elements
179 *
180 * @var array
181 */
182 public $itemLabels = [];
183
184 /**
185 * Indicates if all available fields for a user should be selected or not.
186 *
187 * @var int
188 */
189 public $allFields = 0;
190
191 /**
192 * Number of records to show
193 *
194 * @var int
195 */
196 public $showLimit = 0;
197
198 /**
199 * Whether to show localization view or not
200 *
201 * @var bool
202 */
203 public $localizationView = false;
204
205 /**
206 * Shared module configuration, used by localization features
207 *
208 * @var array
209 */
210 public $modSharedTSconfig = [];
211
212 /**
213 * Tables which should not get listed
214 *
215 * @var string
216 */
217 public $hideTables = '';
218
219 /**
220 * Containing which fields to display in extended mode
221 *
222 * @var string[]
223 */
224 public $displayFields;
225
226 /**
227 * Tables which should not list their translations
228 *
229 * @var string
230 */
231 public $hideTranslations = '';
232
233 /**
234 * If set, csvList is outputted.
235 *
236 * @var bool
237 */
238 public $csvOutput = false;
239
240 /**
241 * Cache for record path
242 *
243 * @var mixed[]
244 */
245 public $recPath_cache = [];
246
247 /**
248 * Field, to sort list by
249 *
250 * @var string
251 */
252 public $sortField;
253
254 /**
255 * default Max items shown per table in "multi-table mode", may be overridden by tables.php
256 *
257 * @var int
258 */
259 public $itemsLimitPerTable = 20;
260
261 /**
262 * Page select permissions
263 *
264 * @var string
265 */
266 public $perms_clause = '';
267
268 /**
269 * Page id
270 *
271 * @var int
272 */
273 public $id;
274
275 /**
276 * Return URL
277 *
278 * @var string
279 */
280 public $returnUrl = '';
281
282 /**
283 * Tablename if single-table mode
284 *
285 * @var string
286 */
287 public $table = '';
288
289 /**
290 * Some permissions...
291 *
292 * @var int
293 */
294 public $calcPerms = 0;
295
296 /**
297 * Mode for what happens when a user clicks the title of a record.
298 *
299 * @var string
300 */
301 public $clickTitleMode = '';
302
303 /**
304 * Levels to search down.
305 *
306 * @var int
307 */
308 public $searchLevels = '';
309
310 /**
311 * "LIMIT " in SQL...
312 *
313 * @var int
314 */
315 public $iLimit = 0;
316
317 /**
318 * Set to the total number of items for a table when selecting.
319 *
320 * @var string
321 */
322 public $totalItems = '';
323
324 /**
325 * TSconfig which overwrites TCA-Settings
326 *
327 * @var mixed[][]
328 */
329 public $tableTSconfigOverTCA = [];
330
331 /**
332 * Loaded with page record with version overlay if any.
333 *
334 * @var string[]
335 */
336 public $pageRecord = [];
337
338 /**
339 * Used for tracking duplicate values of fields
340 *
341 * @var string[]
342 */
343 public $duplicateStack = [];
344
345 /**
346 * Fields to display for the current table
347 *
348 * @var string[]
349 */
350 public $setFields = [];
351
352 /**
353 * Current script name
354 *
355 * @var string
356 */
357 public $script = 'index.php';
358
359 /**
360 * If TRUE, records are listed only if a specific table is selected.
361 *
362 * @var bool
363 */
364 public $listOnlyInSingleTableMode = false;
365
366 /**
367 * JavaScript code accumulation
368 *
369 * @var string
370 */
371 public $JScode = '';
372
373 /**
374 * Pointer for browsing list
375 *
376 * @var int
377 */
378 public $firstElementNumber = 0;
379
380 /**
381 * Counting the elements no matter what...
382 *
383 * @var int
384 */
385 public $eCounter = 0;
386
387 /**
388 * Search string
389 *
390 * @var string
391 */
392 public $searchString = '';
393
394 /**
395 * default Max items shown per table in "single-table mode", may be overridden by tables.php
396 *
397 * @var int
398 */
399 public $itemsLimitSingleTable = 100;
400
401 /**
402 * Field, indicating to sort in reverse order.
403 *
404 * @var bool
405 */
406 public $sortRev;
407
408 /**
409 * String, can contain the field name from a table which must have duplicate values marked.
410 *
411 * @var string
412 */
413 public $duplicateField;
414
415 /**
416 * Specify a list of tables which are the only ones allowed to be displayed.
417 *
418 * @var string
419 */
420 public $tableList = '';
421
422 /**
423 * Array of collapsed / uncollapsed tables in multi table view
424 *
425 * @var int[][]
426 */
427 public $tablesCollapsed = [];
428
429 /**
430 * @var array[] Module configuration
431 */
432 public $modTSconfig;
433
434 /**
435 * HTML output
436 *
437 * @var string
438 */
439 public $HTMLcode = '';
440
441 /**
442 * Thumbnails on records containing files (pictures)
443 *
444 * @var bool
445 */
446 public $thumbs = 0;
447
448 /**
449 * Used for tracking next/prev uids
450 *
451 * @var int[][]
452 */
453 public $currentTable = [];
454
455 /**
456 * OBSOLETE - NOT USED ANYMORE. leftMargin
457 *
458 * @var int
459 */
460 public $leftMargin = 0;
461
462 /**
463 * Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
464 *
465 * @var array
466 */
467 public $fieldArray = [];
468
469 /**
470 * Set to zero, if you don't want a left-margin with addElement function
471 *
472 * @var int
473 */
474 public $setLMargin = 1;
475
476 /**
477 * Contains page translation languages
478 *
479 * @var array
480 */
481 public $pageOverlays = [];
482
483 /**
484 * Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
485 *
486 * @var int
487 */
488 public $counter = 0;
489
490 /**
491 * Contains sys language icons and titles
492 *
493 * @var array
494 */
495 public $languageIconTitles = [];
496
497 /**
498 * Script URL
499 *
500 * @var string
501 */
502 public $thisScript = '';
503
504 /**
505 * If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
506 *
507 * @var string
508 */
509 public $oddColumnsCssClass = '';
510
511 /**
512 * Not used in this class - but maybe extension classes...
513 * Max length of strings
514 *
515 * @var int
516 */
517 public $fixedL = 30;
518
519 /**
520 * @var TranslationConfigurationProvider
521 */
522 public $translateTools;
523
524 /**
525 * Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
526 *
527 * @var array
528 */
529 public $addElement_tdParams = [];
530
531 /**
532 * @var int
533 */
534 public $no_noWrap = 0;
535
536 /**
537 * @var int
538 */
539 public $showIcon = 1;
540
541 /**
542 * Keys are fieldnames and values are td-css-classes to add in addElement();
543 *
544 * @var array
545 */
546 public $addElement_tdCssClass = [];
547
548 /**
549 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
550 */
551 protected $clipboard;
552
553 /**
554 * User permissions
555 *
556 * @var int
557 */
558 public $ext_CALC_PERMS;
559
560 /**
561 * Current ids page record
562 *
563 * @var array
564 */
565 protected $pageinfo;
566
567 /**
568 * Caches the available languages in a colPos
569 *
570 * @var array
571 */
572 protected $languagesInColumnCache = [];
573
574 /**
575 * Caches the amount of content elements as a matrix
576 *
577 * @var array
578 * @internal
579 */
580 protected $contentElementCache = [];
581
582 /**
583 * @var IconFactory
584 */
585 protected $iconFactory;
586
587 /**
588 * Stores whether a certain language has translations in it
589 *
590 * @var array
591 */
592 protected $languageHasTranslationsCache = [];
593
594 /**
595 * @var LocalizationController
596 */
597 protected $localizationController;
598
599 /**
600 * Override the page ids taken into account by getPageIdConstraint()
601 *
602 * @var array
603 */
604 protected $overridePageIdList = [];
605
606 /**
607 * Override/add urlparameters in listUrl() method
608 *
609 * @var string[]
610 */
611 protected $overrideUrlParameters = [];
612
613 /**
614 * Array with before/after setting for tables
615 * Structure:
616 * 'tableName' => [
617 * 'before' => ['A', ...]
618 * 'after' => []
619 * ]
620 * @var array[]
621 */
622 protected $tableDisplayOrder = [];
623
624 /**
625 * Construct to initialize class variables.
626 */
627 public function __construct()
628 {
629 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
630 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
631 }
632 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
633 $this->getTranslateTools();
634 $this->determineScriptUrl();
635 $this->localizationController = GeneralUtility::makeInstance(LocalizationController::class);
636 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
637 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
638 $pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
639 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
640 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
641 }
642
643 /*****************************************
644 *
645 * Renderings
646 *
647 *****************************************/
648 /**
649 * Adds the code of a single table
650 *
651 * @param string $table Table name
652 * @param int $id Current page id
653 * @param string $fields
654 * @return string HTML for listing.
655 */
656 public function getTable($table, $id, $fields = '')
657 {
658 if (isset($this->externalTables[$table])) {
659 return $this->getExternalTables($id, $table);
660 }
661 // Branch out based on table name:
662 switch ($table) {
663 case 'pages':
664 return $this->getTable_pages($id);
665 break;
666 case 'tt_content':
667 return $this->getTable_tt_content($id);
668 break;
669 default:
670 return '';
671 }
672 }
673
674 /**
675 * Renders an external table from page id
676 *
677 * @param int $id Page id
678 * @param string $table Name of the table
679 * @return string HTML for the listing
680 */
681 public function getExternalTables($id, $table)
682 {
683 $this->pageinfo = BackendUtility::readPageAccess($id, '');
684 $type = $this->getPageLayoutController()->MOD_SETTINGS[$table];
685 if (!isset($type)) {
686 $type = 0;
687 }
688 // eg. "name;title;email;company,image"
689 $fList = $this->externalTables[$table][$type]['fList'];
690 // The columns are separeted by comma ','.
691 // Values separated by semicolon ';' are shown in the same column.
692 $icon = $this->externalTables[$table][$type]['icon'];
693 $addWhere = $this->externalTables[$table][$type]['addWhere'];
694 // Create listing
695 $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
696 return $out;
697 }
698
699 /**
700 * Renders records from the pages table from page id
701 * (Used to get information about the page tree content by "Web>Info"!)
702 *
703 * @param int $id Page id
704 * @return string HTML for the listing
705 */
706 public function getTable_pages($id)
707 {
708 // Initializing:
709 $out = '';
710 $lang = $this->getLanguageService();
711 // Select current page:
712 if (!$id) {
713 // The root has a pseudo record in pageinfo...
714 $row = $this->getPageLayoutController()->pageinfo;
715 } else {
716 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
717 ->getQueryBuilderForTable('pages');
718 $queryBuilder->getRestrictions()
719 ->removeAll()
720 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
721 $row = $queryBuilder
722 ->select('*')
723 ->from('pages')
724 ->where(
725 $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)),
726 $this->getBackendUser()->getPagePermsClause(1)
727 )
728 ->execute()
729 ->fetch();
730 BackendUtility::workspaceOL('pages', $row);
731 }
732 // If there was found a page:
733 if (is_array($row)) {
734 // Getting select-depth:
735 $depth = (int)$this->getPageLayoutController()->MOD_SETTINGS['pages_levels'];
736 // Overriding a few things:
737 $this->no_noWrap = 0;
738 // Items
739 $this->eCounter = $this->firstElementNumber;
740 // Creating elements:
741 list($flag, $code) = $this->fwd_rwd_nav();
742 $out .= $code;
743 $editUids = [];
744 if ($flag) {
745 // Getting children:
746 $theRows = $this->getPageRecordsRecursive($row['uid'], $depth);
747 if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
748 $editUids[] = $row['uid'];
749 }
750 $out .= $this->pages_drawItem($row, $this->fieldArray);
751 // Traverse all pages selected:
752 foreach ($theRows as $sRow) {
753 if ($this->getBackendUser()->doesUserHaveAccess($sRow, 2)) {
754 $editUids[] = $sRow['uid'];
755 }
756 $out .= $this->pages_drawItem($sRow, $this->fieldArray);
757 }
758 $this->eCounter++;
759 }
760 // Header line is drawn
761 $theData = [];
762 $editIdList = implode(',', $editUids);
763 // Traverse fields (as set above) in order to create header values:
764 foreach ($this->fieldArray as $field) {
765 if ($editIdList
766 && isset($GLOBALS['TCA']['pages']['columns'][$field])
767 && $field !== 'uid'
768 && !$this->pages_noEditColumns
769 ) {
770 $iTitle = sprintf(
771 $lang->getLL('editThisColumn'),
772 rtrim(trim($lang->sL(BackendUtility::getItemLabel('pages', $field))), ':')
773 );
774 $urlParameters = [
775 'edit' => [
776 'pages' => [
777 $editIdList => 'edit'
778 ]
779 ],
780 'columnsOnly' => $field,
781 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
782 ];
783 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
784 $eI = '<a class="btn btn-default" href="' . htmlspecialchars($url)
785 . '" title="' . htmlspecialchars($iTitle) . '">'
786 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
787 } else {
788 $eI = '';
789 }
790 switch ($field) {
791 case 'title':
792 $theData[$field] = '&nbsp;' . $eI . '<strong>'
793 . $lang->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'])
794 . '</strong>';
795 break;
796 case 'uid':
797 $theData[$field] = '&nbsp;<strong>ID:</strong>';
798 break;
799 default:
800 if (substr($field, 0, 6) === 'table_') {
801 $f2 = substr($field, 6);
802 if ($GLOBALS['TCA'][$f2]) {
803 $theData[$field] = '&nbsp;' .
804 '<span title="' .
805 htmlspecialchars($lang->sL($GLOBALS['TCA'][$f2]['ctrl']['title'])) .
806 '">' .
807 $this->iconFactory->getIconForRecord($f2, [], Icon::SIZE_SMALL)->render() .
808 '</span>';
809 }
810 } else {
811 $theData[$field] = '&nbsp;&nbsp;' . $eI . '<strong>'
812 . htmlspecialchars($lang->sL($GLOBALS['TCA']['pages']['columns'][$field]['label']))
813 . '</strong>';
814 }
815 }
816 }
817 $out = '<div class="table-fit">'
818 . '<table class="table table-striped table-hover typo3-page-pages">'
819 . '<thead>'
820 . $this->addElement(1, '', $theData)
821 . '</thead>'
822 . '<tbody>'
823 . $out
824 . '</tbody>'
825 . '</table>'
826 . '</div>';
827 }
828 return $out;
829 }
830
831 /**
832 * Renders Content Elements from the tt_content table from page id
833 *
834 * @param int $id Page id
835 * @return string HTML for the listing
836 */
837 public function getTable_tt_content($id)
838 {
839 $backendUser = $this->getBackendUser();
840 $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
841 ->getConnectionForTable('tt_content')
842 ->getExpressionBuilder();
843 $this->pageinfo = BackendUtility::readPageAccess($this->id, '');
844 $this->initializeLanguages();
845 $this->initializeClipboard();
846 $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', BackendUtility::getRecordWSOL('pages', $id), true));
847 /** @var $pageRenderer PageRenderer */
848 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
849 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
850 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
851 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
852 $userCanEditPage = $this->ext_CALC_PERMS & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
853 if ($this->tt_contentConfig['languageColsPointer'] > 0) {
854 $userCanEditPage = $this->getBackendUser()->check('tables_modify', 'pages_language_overlay');
855 }
856 if ($userCanEditPage) {
857 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
858 ->getQueryBuilderForTable('pages_language_overlay');
859 $queryBuilder->getRestrictions()
860 ->removeAll()
861 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
862 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
863
864 $queryBuilder->select('uid')
865 ->from('pages_language_overlay')
866 ->where(
867 $queryBuilder->expr()->eq(
868 'pid',
869 $queryBuilder->createNamedParameter((int)$this->id, \PDO::PARAM_INT)
870 ),
871 $queryBuilder->expr()->eq(
872 'sys_language_uid',
873 $queryBuilder->createNamedParameter(
874 $this->tt_contentConfig['sys_language_uid'],
875 \PDO::PARAM_INT
876 )
877 )
878 )
879 ->setMaxResults(1);
880
881 $languageOverlayId = (int)$queryBuilder->execute()->fetchColumn(0);
882
883 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', 'function(PageActions) {
884 PageActions.setPageId(' . (int)$this->id . ');
885 PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
886 PageActions.initializePageTitleRenaming();
887 }');
888 }
889 // Get labels for CTypes and tt_content element fields in general:
890 $this->CType_labels = [];
891 foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
892 $this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
893 }
894 $this->itemLabels = [];
895 foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
896 $this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
897 }
898 $languageColumn = [];
899 $out = '';
900
901 // Setting language list:
902 $langList = $this->tt_contentConfig['sys_language_uid'];
903 if ($this->tt_contentConfig['languageMode']) {
904 if ($this->tt_contentConfig['languageColsPointer']) {
905 $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
906 } else {
907 $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
908 }
909 $languageColumn = [];
910 }
911 $langListArr = GeneralUtility::intExplode(',', $langList);
912 $defaultLanguageElementsByColumn = [];
913 $defLangBinding = [];
914 // For each languages... :
915 // If not languageMode, then we'll only be through this once.
916 foreach ($langListArr as $lP) {
917 $lP = (int)$lP;
918
919 if (!isset($this->contentElementCache[$lP])) {
920 $this->contentElementCache[$lP] = [];
921 }
922
923 if (count($langListArr) === 1 || $lP === 0) {
924 $showLanguage = $expressionBuilder->in('sys_language_uid', [$lP, -1]);
925 } else {
926 $showLanguage = $expressionBuilder->eq('sys_language_uid', $lP);
927 }
928 $content = [];
929 $head = [];
930
931 $backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
932 $columns = $backendLayout['__colPosList'];
933 // Select content records per column
934 $contentRecordsPerColumn = $this->getContentRecordsPerColumn('table', $id, $columns, $showLanguage);
935 $cList = array_keys($contentRecordsPerColumn);
936 // For each column, render the content into a variable:
937 foreach ($cList as $columnId) {
938 if (!isset($this->contentElementCache[$lP][$columnId])) {
939 $this->contentElementCache[$lP][$columnId] = [];
940 }
941
942 if (!$lP) {
943 $defaultLanguageElementsByColumn[$columnId] = [];
944 }
945 // Start wrapping div
946 $content[$columnId] .= '<div data-colpos="' . $columnId . '" data-language-uid="' . $lP . '" class="t3js-sortable t3js-sortable-lang t3js-sortable-lang-' . $lP . ' t3-page-ce-wrapper';
947 if (empty($contentRecordsPerColumn[$columnId])) {
948 $content[$columnId] .= ' t3-page-ce-empty';
949 }
950 $content[$columnId] .= '">';
951 // Add new content at the top most position
952 $link = '';
953 if ($this->getPageLayoutController()->contentIsNotLockedForEditors()
954 && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
955 ) {
956 if ($this->option_newWizard) {
957 $urlParameters = [
958 'id' => $id,
959 'sys_language_uid' => $lP,
960 'colPos' => $columnId,
961 'uid_pid' => $id,
962 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
963 ];
964 $tsConfig = BackendUtility::getModTSconfig($id, 'mod');
965 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
966 ? $tsConfig['properties']['newContentElementWizard.']['override']
967 : 'new_content_element';
968 $url = BackendUtility::getModuleUrl($moduleName, $urlParameters);
969 } else {
970 $urlParameters = [
971 'edit' => [
972 'tt_content' => [
973 $id => 'new'
974 ]
975 ],
976 'defVals' => [
977 'tt_content' => [
978 'colPos' => $columnId,
979 'sys_language_uid' => $lP
980 ]
981 ],
982 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
983 ];
984 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
985 }
986
987 $link = '<a href="' . htmlspecialchars($url) . '" title="'
988 . htmlspecialchars($this->getLanguageService()->getLL('newContentElement')) . '" class="btn btn-default btn-sm">'
989 . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render()
990 . ' '
991 . htmlspecialchars($this->getLanguageService()->getLL('content')) . '</a>';
992 }
993 if ($this->getBackendUser()->checkLanguageAccess($lP) && $columnId !== 'unused') {
994 $content[$columnId] .= '
995 <div class="t3-page-ce t3js-page-ce" data-page="' . (int)$id . '" id="' . StringUtility::getUniqueId() . '">
996 <div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $columnId . '-' . 'page-' . $id . '-' . StringUtility::getUniqueId() . '">'
997 . $link
998 . '</div>
999 <div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div>
1000 </div>
1001 ';
1002 }
1003 $editUidList = '';
1004 if (!isset($contentRecordsPerColumn[$columnId]) || !is_array($contentRecordsPerColumn[$columnId])) {
1005 $message = GeneralUtility::makeInstance(
1006 FlashMessage::class,
1007 $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:error.invalidBackendLayout'),
1008 '',
1009 FlashMessage::WARNING
1010 );
1011 $service = GeneralUtility::makeInstance(FlashMessageService::class);
1012 $queue = $service->getMessageQueueByIdentifier();
1013 $queue->addMessage($message);
1014 } else {
1015 $rowArr = $contentRecordsPerColumn[$columnId];
1016 $this->generateTtContentDataArray($rowArr);
1017
1018 foreach ((array)$rowArr as $rKey => $row) {
1019 $this->contentElementCache[$lP][$columnId][$row['uid']] = $row;
1020 if ($this->tt_contentConfig['languageMode']) {
1021 $languageColumn[$columnId][$lP] = $head[$columnId] . $content[$columnId];
1022 if (!$this->defLangBinding && $columnId !== 'unused') {
1023 $languageColumn[$columnId][$lP] .= $this->newLanguageButton(
1024 $this->getNonTranslatedTTcontentUids($defaultLanguageElementsByColumn[$columnId], $id, $lP),
1025 $lP,
1026 $columnId
1027 );
1028 }
1029 }
1030 if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1031 $singleElementHTML = '';
1032 if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
1033 $defaultLanguageElementsByColumn[$columnId][] = (isset($row['_ORIG_uid']) ? $row['_ORIG_uid'] : $row['uid']);
1034 }
1035 $editUidList .= $row['uid'] . ',';
1036 $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0;
1037 if (!$this->tt_contentConfig['languageMode']) {
1038 $singleElementHTML .= '<div class="t3-page-ce-dragitem" id="' . StringUtility::getUniqueId() . '">';
1039 }
1040 $singleElementHTML .= $this->tt_content_drawHeader(
1041 $row,
1042 $this->tt_contentConfig['showInfo'] ? 15 : 5,
1043 $disableMoveAndNewButtons,
1044 true,
1045 $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
1046 );
1047 $innerContent = '<div ' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . '>'
1048 . $this->tt_content_drawItem($row) . '</div>';
1049 $singleElementHTML .= '<div class="t3-page-ce-body-inner">' . $innerContent . '</div>'
1050 . $this->tt_content_drawFooter($row);
1051 $isDisabled = $this->isDisabled('tt_content', $row);
1052 $statusHidden = $isDisabled ? ' t3-page-ce-hidden t3js-hidden-record' : '';
1053 $displayNone = !$this->tt_contentConfig['showHidden'] && $isDisabled ? ' style="display: none;"' : '';
1054 $highlightHeader = '';
1055 if ($this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid']) && (int)$row['l18n_parent'] === 0) {
1056 $highlightHeader = ' t3-page-ce-danger';
1057 } elseif ($columnId === 'unused') {
1058 $highlightHeader = ' t3-page-ce-warning';
1059 }
1060 $singleElementHTML = '<div class="t3-page-ce' . $highlightHeader . ' t3js-page-ce t3js-page-ce-sortable ' . $statusHidden . '" id="element-tt_content-'
1061 . $row['uid'] . '" data-table="tt_content" data-uid="' . $row['uid'] . '"' . $displayNone . '>' . $singleElementHTML . '</div>';
1062
1063 if ($this->tt_contentConfig['languageMode']) {
1064 $singleElementHTML .= '<div class="t3-page-ce t3js-page-ce">';
1065 }
1066 $singleElementHTML .= '<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $columnId . '-' . 'page-' . $id .
1067 '-' . StringUtility::getUniqueId() . '">';
1068 // Add icon "new content element below"
1069 if (!$disableMoveAndNewButtons
1070 && $this->getPageLayoutController()->contentIsNotLockedForEditors()
1071 && $this->getBackendUser()->checkLanguageAccess($lP)
1072 && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
1073 && $columnId !== 'unused'
1074 ) {
1075 // New content element:
1076 if ($this->option_newWizard) {
1077 $urlParameters = [
1078 'id' => $row['pid'],
1079 'sys_language_uid' => $row['sys_language_uid'],
1080 'colPos' => $row['colPos'],
1081 'uid_pid' => -$row['uid'],
1082 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1083 ];
1084 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod');
1085 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
1086 ? $tsConfig['properties']['newContentElementWizard.']['override']
1087 : 'new_content_element';
1088 $url = BackendUtility::getModuleUrl($moduleName, $urlParameters);
1089 } else {
1090 $urlParameters = [
1091 'edit' => [
1092 'tt_content' => [
1093 -$row['uid'] => 'new'
1094 ]
1095 ],
1096 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1097 ];
1098 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1099 }
1100 $singleElementHTML .= '
1101 <a href="' . htmlspecialchars($url) . '" title="'
1102 . htmlspecialchars($this->getLanguageService()->getLL('newContentElement')) . '" class="btn btn-default btn-sm">'
1103 . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render()
1104 . ' '
1105 . htmlspecialchars($this->getLanguageService()->getLL('content')) . '</a>
1106 ';
1107 }
1108 $singleElementHTML .= '</div></div><div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div></div>';
1109 if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
1110 $defLangBinding[$columnId][$lP][$row[$lP ? 'l18n_parent' : 'uid']] = $singleElementHTML;
1111 } else {
1112 $content[$columnId] .= $singleElementHTML;
1113 }
1114 } else {
1115 unset($rowArr[$rKey]);
1116 }
1117 }
1118 $content[$columnId] .= '</div>';
1119 $colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', $columnId);
1120 $tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $id, $this);
1121 foreach ($tcaItems as $item) {
1122 if ($item[1] == $columnId) {
1123 $colTitle = $this->getLanguageService()->sL($item[0]);
1124 }
1125 }
1126 if ($columnId === 'unused') {
1127 if (empty($unusedElementsMessage)) {
1128 $unusedElementsMessage = GeneralUtility::makeInstance(
1129 FlashMessage::class,
1130 $this->getLanguageService()->getLL('staleUnusedElementsWarning'),
1131 $this->getLanguageService()->getLL('staleUnusedElementsWarningTitle'),
1132 FlashMessage::WARNING
1133 );
1134 $service = GeneralUtility::makeInstance(FlashMessageService::class);
1135 $queue = $service->getMessageQueueByIdentifier();
1136 $queue->addMessage($unusedElementsMessage);
1137 }
1138 $colTitle = $this->getLanguageService()->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:colPos.I.unused');
1139 $editParam = '';
1140 } else {
1141 $editParam = $this->doEdit && !empty($rowArr)
1142 ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc
1143 : '';
1144 }
1145 $head[$columnId] .= $this->tt_content_drawColHeader($colTitle, $editParam);
1146 }
1147 }
1148 // For each column, fit the rendered content into a table cell:
1149 $out = '';
1150 if ($this->tt_contentConfig['languageMode']) {
1151 // in language mode process the content elements, but only fill $languageColumn. output will be generated later
1152 $sortedLanguageColumn = [];
1153 foreach ($cList as $columnId) {
1154 if (GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnId) || $columnId === 'unused') {
1155 $languageColumn[$columnId][$lP] = $head[$columnId] . $content[$columnId];
1156 if (!$this->defLangBinding && $columnId !== 'unused') {
1157 $languageColumn[$columnId][$lP] .= $this->newLanguageButton(
1158 $this->getNonTranslatedTTcontentUids($defaultLanguageElementsByColumn[$columnId], $id, $lP),
1159 $lP,
1160 $columnId
1161 );
1162 }
1163 // We sort $languageColumn again according to $cList as it may contain data already from above.
1164 $sortedLanguageColumn[$columnId] = $languageColumn[$columnId];
1165 }
1166 }
1167 if (!empty($languageColumn['unused'])) {
1168 $sortedLanguageColumn['unused'] = $languageColumn['unused'];
1169 }
1170 $languageColumn = $sortedLanguageColumn;
1171 } else {
1172 // GRID VIEW:
1173 $grid = '<div class="t3-grid-container"><table border="0" cellspacing="0" cellpadding="0" width="100%" class="t3-page-columns t3-grid-table t3js-page-columns">';
1174 // Add colgroups
1175 $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
1176 $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
1177 $grid .= '<colgroup>';
1178 for ($i = 0; $i < $colCount; $i++) {
1179 $grid .= '<col />';
1180 }
1181 $grid .= '</colgroup>';
1182 // Cycle through rows
1183 for ($row = 1; $row <= $rowCount; $row++) {
1184 $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
1185 if (!isset($rowConfig)) {
1186 continue;
1187 }
1188 $grid .= '<tr>';
1189 for ($col = 1; $col <= $colCount; $col++) {
1190 $columnConfig = $rowConfig['columns.'][$col . '.'];
1191 if (!isset($columnConfig)) {
1192 continue;
1193 }
1194 // Which tt_content colPos should be displayed inside this cell
1195 $columnKey = (int)$columnConfig['colPos'];
1196 // Render the grid cell
1197 $colSpan = (int)$columnConfig['colspan'];
1198 $rowSpan = (int)$columnConfig['rowspan'];
1199 $grid .= '<td valign="top"' .
1200 ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
1201 ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
1202 ' data-colpos="' . (int)$columnConfig['colPos'] . '" data-language-uid="' . $lP . '" class="t3js-page-lang-column-' . $lP . ' t3js-page-column t3-grid-cell t3-page-column t3-page-column-' . $columnKey .
1203 ((!isset($columnConfig['colPos']) || $columnConfig['colPos'] === '') ? ' t3-grid-cell-unassigned' : '') .
1204 ((isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && !$head[$columnKey]) || !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos']) ? ' t3-grid-cell-restricted' : '') .
1205 ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') .
1206 ($rowSpan > 0 ? ' t3-gridCell-height' . $rowSpan : '') . '">';
1207
1208 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
1209 // If not, a new header without any buttons will be generated.
1210 if (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && $head[$columnKey]
1211 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
1212 ) {
1213 $grid .= $head[$columnKey] . $content[$columnKey];
1214 } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
1215 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
1216 ) {
1217 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('noAccess'));
1218 } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
1219 && !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
1220 ) {
1221 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name']) .
1222 ' (' . $this->getLanguageService()->getLL('noAccess') . ')');
1223 } elseif (isset($columnConfig['name']) && $columnConfig['name'] !== '') {
1224 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name'])
1225 . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')');
1226 } else {
1227 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('notAssigned'));
1228 }
1229
1230 $grid .= '</td>';
1231 }
1232 $grid .= '</tr>';
1233 }
1234 if (!empty($content['unused'])) {
1235 $grid .= '<tr>';
1236 // Which tt_content colPos should be displayed inside this cell
1237 $columnKey = 'unused';
1238 // Render the grid cell
1239 $colSpan = (int)$backendLayout['__config']['backend_layout.']['colCount'];
1240 $grid .= '<td valign="top"' .
1241 ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
1242 ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
1243 ' data-colpos="unused" data-language-uid="' . $lP . '" class="t3js-page-lang-column-' . $lP . ' t3js-page-column t3-grid-cell t3-page-column t3-page-column-' . $columnKey .
1244 ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') . '">';
1245
1246 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
1247 // If not, a new header without any buttons will be generated.
1248 $grid .= $head[$columnKey] . $content[$columnKey];
1249 $grid .= '</td></tr>';
1250 }
1251 $out .= $grid . '</table></div>';
1252 }
1253 }
1254 $elFromTable = $this->clipboard->elFromTable('tt_content');
1255 if (!empty($elFromTable) && $this->getPageLayoutController()->pageIsNotLockedForEditors()) {
1256 $pasteItem = substr(key($elFromTable), 11);
1257 $pasteRecord = BackendUtility::getRecord('tt_content', (int)$pasteItem);
1258 $pasteTitle = $pasteRecord['header'] ? $pasteRecord['header'] : $pasteItem;
1259 $copyMode = $this->clipboard->clipData['normal']['mode'] ? '-' . $this->clipboard->clipData['normal']['mode'] : '';
1260 $addExtOnReadyCode = '
1261 top.pasteIntoLinkTemplate = '
1262 . $this->tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, 't3js-paste-into', 'pasteIntoColumn')
1263 . ';
1264 top.pasteAfterLinkTemplate = '
1265 . $this->tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, 't3js-paste-after', 'pasteAfterRecord')
1266 . ';';
1267 } else {
1268 $addExtOnReadyCode = '
1269 top.pasteIntoLinkTemplate = \'\';
1270 top.pasteAfterLinkTemplate = \'\';';
1271 }
1272 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
1273 $pageRenderer->addJsInlineCode('pasteLinkTemplates', $addExtOnReadyCode);
1274 // If language mode, then make another presentation:
1275 // Notice that THIS presentation will override the value of $out!
1276 // But it needs the code above to execute since $languageColumn is filled with content we need!
1277 if ($this->tt_contentConfig['languageMode']) {
1278 // Get language selector:
1279 $languageSelector = $this->languageSelector($id);
1280 // Reset out - we will make new content here:
1281 $out = '';
1282 // Traverse languages found on the page and build up the table displaying them side by side:
1283 $cCont = [];
1284 $sCont = [];
1285 foreach ($langListArr as $lP) {
1286 // Header:
1287 $lP = (int)$lP;
1288 $cCont[$lP] = '
1289 <td valign="top" class="t3-page-column" data-language-uid="' . $lP . '">
1290 <h2>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '</h2>
1291 </td>';
1292
1293 // "View page" icon is added:
1294 $viewLink = '';
1295 if (!VersionState::cast($this->getPageLayoutController()->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1296 $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id), '', '', ('&L=' . $lP));
1297 $viewLink = '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage')) . '">' . $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>';
1298 }
1299 // Language overlay page header:
1300 if ($lP) {
1301 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1302 ->getQueryBuilderForTable('pages_language_overlay');
1303 $queryBuilder->getRestrictions()
1304 ->removeAll()
1305 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1306 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1307
1308 $lpRecord = $queryBuilder->select('*')
1309 ->from('pages_language_overlay')
1310 ->where(
1311 $queryBuilder->expr()->eq(
1312 'pid',
1313 $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
1314 ),
1315 $queryBuilder->expr()->eq(
1316 'sys_language_uid',
1317 $queryBuilder->createNamedParameter($lP, \PDO::PARAM_INT)
1318 )
1319 )
1320 ->setMaxResults(1)
1321 ->execute()
1322 ->fetch();
1323
1324 BackendUtility::workspaceOL('pages_language_overlay', $lpRecord);
1325 $recordIcon = BackendUtility::wrapClickMenuOnIcon(
1326 $this->iconFactory->getIconForRecord('pages_language_overlay', $lpRecord, Icon::SIZE_SMALL)->render(),
1327 'pages_language_overlay',
1328 $lpRecord['uid']
1329 );
1330 $urlParameters = [
1331 'edit' => [
1332 'pages_language_overlay' => [
1333 $lpRecord['uid'] => 'edit'
1334 ]
1335 ],
1336 'overrideVals' => [
1337 'pages_language_overlay' => [
1338 'sys_language_uid' => $lP
1339 ]
1340 ],
1341 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1342 ];
1343 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1344 $editLink = (
1345 $this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
1346 ? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
1347 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
1348 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
1349 : ''
1350 );
1351
1352 $lPLabel =
1353 '<div class="btn-group">'
1354 . $viewLink
1355 . $editLink
1356 . '</div>'
1357 . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($lpRecord['title'], 20));
1358 } else {
1359 $editLink = '';
1360 $recordIcon = '';
1361 if ($this->getBackendUser()->checkLanguageAccess(0)) {
1362 $recordIcon = BackendUtility::wrapClickMenuOnIcon(
1363 $this->iconFactory->getIconForRecord('pages', $this->pageRecord, Icon::SIZE_SMALL)->render(),
1364 'pages',
1365 $this->id
1366 );
1367 $urlParameters = [
1368 'edit' => [
1369 'pages' => [
1370 $this->id => 'edit'
1371 ]
1372 ],
1373 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1374 ];
1375 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1376 $editLink = (
1377 $this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
1378 ? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
1379 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
1380 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
1381 : ''
1382 );
1383 }
1384
1385 $lPLabel =
1386 '<div class="btn-group">'
1387 . $viewLink
1388 . $editLink
1389 . '</div>'
1390 . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->pageRecord['title'], 20));
1391 }
1392 $sCont[$lP] = '
1393 <td class="t3-page-column t3-page-lang-label nowrap">' . $lPLabel . '</td>';
1394 }
1395 // Add headers:
1396 $out .= '<tr>' . implode($cCont) . '</tr>';
1397 $out .= '<tr>' . implode($sCont) . '</tr>';
1398 unset($cCont, $sCont);
1399
1400 // Traverse previously built content for the columns:
1401 foreach ($languageColumn as $cKey => $cCont) {
1402 $out .= '<tr>';
1403 foreach ($cCont as $languageId => $columnContent) {
1404 $out .= '<td valign="top" data-colpos="' . $cKey . '" class="t3-grid-cell t3-page-column t3js-page-column t3js-page-lang-column t3js-page-lang-column-' . $languageId . '">' . $columnContent . '</td>';
1405 }
1406 $out .= '</tr>';
1407 if ($this->defLangBinding) {
1408 // "defLangBinding" mode
1409 foreach ($defaultLanguageElementsByColumn[$cKey] as $defUid) {
1410 $cCont = [];
1411 foreach ($langListArr as $lP) {
1412 $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
1413 $this->getNonTranslatedTTcontentUids([$defUid], $id, $lP),
1414 $lP,
1415 $cKey
1416 );
1417 }
1418 $out .= '
1419 <tr>
1420 <td valign="top" class="t3-grid-cell">' . implode(('</td>' . '
1421 <td valign="top" class="t3-grid-cell">'), $cCont) . '</td>
1422 </tr>';
1423 }
1424 }
1425 }
1426 // Finally, wrap it all in a table and add the language selector on top of it:
1427 $out = $languageSelector . '
1428 <div class="t3-grid-container">
1429 <table cellpadding="0" cellspacing="0" class="t3-page-columns t3-grid-table t3js-page-columns">
1430 ' . $out . '
1431 </table>
1432 </div>';
1433 }
1434
1435 return $out;
1436 }
1437
1438 /**********************************
1439 *
1440 * Generic listing of items
1441 *
1442 **********************************/
1443 /**
1444 * Creates a standard list of elements from a table.
1445 *
1446 * @param string $table Table name
1447 * @param int $id Page id.
1448 * @param string $fList Comma list of fields to display
1449 * @param bool $icon If TRUE, icon is shown
1450 * @param string $addWhere Additional WHERE-clauses.
1451 * @return string HTML table
1452 */
1453 public function makeOrdinaryList($table, $id, $fList, $icon = false, $addWhere = '')
1454 {
1455 // Initialize
1456 $addWhere = empty($addWhere) ? [] : [QueryHelper::stripLogicalOperatorPrefix($addWhere)];
1457 $queryBuilder = $this->getQueryBuilder($table, $id, $addWhere);
1458 $this->setTotalItems($table, $id, $addWhere);
1459 $dbCount = 0;
1460 $result = false;
1461 // Make query for records if there were any records found in the count operation
1462 if ($this->totalItems) {
1463 $result = $queryBuilder->execute();
1464 // Will return FALSE, if $result is invalid
1465 $dbCount = $result->rowCount();
1466 }
1467 // If records were found, render the list
1468 if (!$dbCount) {
1469 return '';
1470 }
1471 // Set fields
1472 $out = '';
1473 $this->fieldArray = GeneralUtility::trimExplode(',', '__cmds__,' . $fList . ',__editIconLink__', true);
1474 $theData = [];
1475 $theData = $this->headerFields($this->fieldArray, $table, $theData);
1476 // Title row
1477 $localizedTableTitle = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title']));
1478 $out .= '<tr><th class="col-icon"></th>'
1479 . '<th colspan="' . (count($theData) - 2) . '"><span class="c-table">'
1480 . $localizedTableTitle . '</span> (' . $dbCount . ')</td>' . '<td class="col-icon"></td>'
1481 . '</tr>';
1482 // Column's titles
1483 if ($this->doEdit) {
1484 $urlParameters = [
1485 'edit' => [
1486 $table => [
1487 $this->id => 'new'
1488 ]
1489 ],
1490 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1491 ];
1492 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1493 $theData['__cmds__'] = '<a href="' . htmlspecialchars($url) . '" '
1494 . 'title="' . htmlspecialchars($this->getLanguageService()->getLL('new')) . '">'
1495 . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render() . '</a>';
1496 }
1497 $out .= $this->addElement(1, '', $theData, ' class="c-headLine"', 15, '', 'th');
1498 // Render Items
1499 $this->eCounter = $this->firstElementNumber;
1500 while ($row = $result->fetch()) {
1501 BackendUtility::workspaceOL($table, $row);
1502 if (is_array($row)) {
1503 list($flag, $code) = $this->fwd_rwd_nav();
1504 $out .= $code;
1505 if ($flag) {
1506 $Nrow = [];
1507 // Setting icons links
1508 if ($icon) {
1509 $Nrow['__cmds__'] = $this->getIcon($table, $row);
1510 }
1511 // Get values:
1512 $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
1513 // Attach edit icon
1514 if ($this->doEdit && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1515 $urlParameters = [
1516 'edit' => [
1517 $table => [
1518 $row['uid'] => 'edit'
1519 ]
1520 ],
1521 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1522 ];
1523 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1524 $Nrow['__editIconLink__'] = '<a class="btn btn-default" href="' . htmlspecialchars($url)
1525 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
1526 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
1527 } else {
1528 $Nrow['__editIconLink__'] = $this->noEditIcon();
1529 }
1530 $out .= $this->addElement(1, '', $Nrow);
1531 }
1532 $this->eCounter++;
1533 }
1534 }
1535 // Wrap it all in a table:
1536 $out = '
1537 <!--
1538 Standard list of table "' . $table . '"
1539 -->
1540 <div class="table-fit"><table class="table table-hover table-striped">
1541 ' . $out . '
1542 </table></div>';
1543 return $out;
1544 }
1545
1546 /**
1547 * Adds content to all data fields in $out array
1548 *
1549 * Each field name in $fieldArr has a special feature which is that the field name can be specified as more field names.
1550 * Eg. "field1,field2;field3".
1551 * Field 2 and 3 will be shown in the same cell of the table separated by <br /> while field1 will have its own cell.
1552 *
1553 * @param array $fieldArr Array of fields to display
1554 * @param string $table Table name
1555 * @param array $row Record array
1556 * @param array $out Array to which the data is added
1557 * @return array $out array returned after processing.
1558 * @see makeOrdinaryList()
1559 */
1560 public function dataFields($fieldArr, $table, $row, $out = [])
1561 {
1562 // Check table validity
1563 if (!isset($GLOBALS['TCA'][$table])) {
1564 return $out;
1565 }
1566
1567 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
1568 // Traverse fields
1569 foreach ($fieldArr as $fieldName) {
1570 if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
1571 // Each field has its own cell (if configured in TCA)
1572 // If the column is a thumbnail column:
1573 if ($fieldName == $thumbsCol) {
1574 $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
1575 } else {
1576 // ... otherwise just render the output:
1577 $out[$fieldName] = nl2br(htmlspecialchars(trim(GeneralUtility::fixed_lgd_cs(
1578 BackendUtility::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']),
1579 250
1580 ))));
1581 }
1582 } else {
1583 // Each field is separated by <br /> and shown in the same cell (If not a TCA field, then explode
1584 // the field name with ";" and check each value there as a TCA configured field)
1585 $theFields = explode(';', $fieldName);
1586 // Traverse fields, separated by ";" (displayed in a single cell).
1587 foreach ($theFields as $fName2) {
1588 if ($GLOBALS['TCA'][$table]['columns'][$fName2]) {
1589 $out[$fieldName] .= '<strong>' . htmlspecialchars($this->getLanguageService()->sL(
1590 $GLOBALS['TCA'][$table]['columns'][$fName2]['label']
1591 )) . '</strong>' . '&nbsp;&nbsp;' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(
1592 BackendUtility::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']),
1593 25
1594 )) . '<br />';
1595 }
1596 }
1597 }
1598 // If no value, add a nbsp.
1599 if (!$out[$fieldName]) {
1600 $out[$fieldName] = '&nbsp;';
1601 }
1602 // Wrap in dimmed-span tags if record is "disabled"
1603 if ($this->isDisabled($table, $row)) {
1604 $out[$fieldName] = '<span class="text-muted">' . $out[$fieldName] . '</span>';
1605 }
1606 }
1607 return $out;
1608 }
1609
1610 /**
1611 * Header fields made for the listing of records
1612 *
1613 * @param array $fieldArr Field names
1614 * @param string $table The table name
1615 * @param array $out Array to which the headers are added.
1616 * @return array $out returned after addition of the header fields.
1617 * @see makeOrdinaryList()
1618 */
1619 public function headerFields($fieldArr, $table, $out = [])
1620 {
1621 foreach ($fieldArr as $fieldName) {
1622 $ll = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']));
1623 $out[$fieldName] = $ll ? $ll : '&nbsp;';
1624 }
1625 return $out;
1626 }
1627
1628 /**
1629 * Gets content records per column.
1630 * This is required for correct workspace overlays.
1631 *
1632 * @param string $table UNUSED (will always be queried from tt_content)
1633 * @param int $id Page Id to be used (not used at all, but part of the API, see $this->pidSelect)
1634 * @param array $columns colPos values to be considered to be shown
1635 * @param string $additionalWhereClause Additional where clause for database select
1636 * @return array Associative array for each column (colPos)
1637 */
1638 protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '')
1639 {
1640 $contentRecordsPerColumn = array_fill_keys($columns, []);
1641 $columns = array_flip($columns);
1642 $queryBuilder = $this->getQueryBuilder(
1643 'tt_content',
1644 $id,
1645 [
1646 $additionalWhereClause
1647 ]
1648 );
1649
1650 // Traverse any selected elements and render their display code:
1651 $results = $this->getResult($queryBuilder->execute());
1652 $unused = [];
1653 foreach ($results as $record) {
1654 if (isset($columns[$record['colPos']])) {
1655 $columnValue = (string)$record['colPos'];
1656 $contentRecordsPerColumn[$columnValue][] = $record;
1657 } else {
1658 $unused[] = $record;
1659 }
1660 }
1661 if (!empty($unused)) {
1662 $contentRecordsPerColumn['unused'] = $unused;
1663 }
1664 return $contentRecordsPerColumn;
1665 }
1666
1667 /**********************************
1668 *
1669 * Additional functions; Pages
1670 *
1671 **********************************/
1672
1673 /**
1674 * Adds pages-rows to an array, selecting recursively in the page tree.
1675 *
1676 * @param int $pid Starting page id to select from
1677 * @param string $iconPrefix Prefix for icon code.
1678 * @param int $depth Depth (decreasing)
1679 * @param array $rows Array which will accumulate page rows
1680 * @return array $rows with added rows.
1681 */
1682 protected function getPageRecordsRecursive(int $pid, int $depth, string $iconPrefix = '', array $rows = []): array
1683 {
1684 $depth--;
1685 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1686 $queryBuilder->getRestrictions()
1687 ->removeAll()
1688 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1689 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1690
1691 $queryBuilder
1692 ->select('*')
1693 ->from('pages')
1694 ->where(
1695 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)),
1696 $this->getBackendUser()->getPagePermsClause(1)
1697 );
1698
1699 if (!empty($GLOBALS['TCA']['pages']['ctrl']['sortby'])) {
1700 $queryBuilder->orderBy($GLOBALS['TCA']['pages']['ctrl']['sortby']);
1701 }
1702
1703 if ($depth >= 0) {
1704 $result = $queryBuilder->execute();
1705 $rowCount = $result->rowCount();
1706 $count = 0;
1707 while ($row = $result->fetch()) {
1708 BackendUtility::workspaceOL('pages', $row);
1709 if (is_array($row)) {
1710 $count++;
1711 $row['treeIcons'] = $iconPrefix
1712 . '<span class="treeline-icon treeline-icon-join'
1713 . ($rowCount === $count ? 'bottom' : '')
1714 . '"></span>';
1715 $rows[] = $row;
1716 // Get the branch
1717 $spaceOutIcons = '<span class="treeline-icon treeline-icon-'
1718 . ($rowCount === $count ? 'clear' : 'line')
1719 . '"></span>';
1720 $rows = $this->getPageRecordsRecursive(
1721 $row['uid'],
1722 $row['php_tree_stop'] ? 0 : $depth,
1723 $iconPrefix . $spaceOutIcons,
1724 $rows
1725 );
1726 }
1727 }
1728 }
1729
1730 return $rows;
1731 }
1732
1733 /**
1734 * Adds a list item for the pages-rendering
1735 *
1736 * @param array $row Record array
1737 * @param array $fieldArr Field list
1738 * @return string HTML for the item
1739 */
1740 public function pages_drawItem($row, $fieldArr)
1741 {
1742 // Initialization
1743 $theIcon = $this->getIcon('pages', $row);
1744 // Preparing and getting the data-array
1745 $theData = [];
1746 foreach ($fieldArr as $field) {
1747 switch ($field) {
1748 case 'title':
1749 $pTitle = htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field], 20));
1750 $theData[$field] = $row['treeIcons'] . $theIcon . $pTitle . '&nbsp;&nbsp;';
1751 break;
1752 case 'php_tree_stop':
1753 // Intended fall through
1754 case 'TSconfig':
1755 $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1756 break;
1757 case 'uid':
1758 if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
1759 $urlParameters = [
1760 'edit' => [
1761 'pages' => [
1762 $row['uid'] => 'edit'
1763 ]
1764 ],
1765 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1766 ];
1767 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1768 $eI = '<a class="btn btn-default" href="' . htmlspecialchars($url)
1769 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('editThisPage')) . '">'
1770 . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render() . '</a>';
1771 } else {
1772 $eI = '';
1773 }
1774 $theData[$field] = $eI . '<span align="right">' . $row['uid'] . '</span>';
1775 break;
1776 case 'shortcut':
1777 case 'shortcut_mode':
1778 if ((int)$row['doktype'] === \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1779 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1780 }
1781 break;
1782 default:
1783 if (substr($field, 0, 6) === 'table_') {
1784 $f2 = substr($field, 6);
1785 if ($GLOBALS['TCA'][$f2]) {
1786 $c = $this->numberOfRecords($f2, $row['uid']);
1787 $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1788 }
1789 } else {
1790 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1791 }
1792 }
1793 }
1794 $this->addElement_tdParams['title'] = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '';
1795 return $this->addElement(1, '', $theData);
1796 }
1797
1798 /**
1799 * Returns the HTML code for rendering a field in the pages table.
1800 * The row value is processed to a human readable form and the result is parsed through htmlspecialchars().
1801 *
1802 * @param string $field The name of the field of which the value should be rendered.
1803 * @param array $row The pages table row as an associative array.
1804 * @return string The rendered table field value.
1805 */
1806 protected function getPagesTableFieldValue($field, array $row)
1807 {
1808 return '&nbsp;&nbsp;' . htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field]));
1809 }
1810
1811 /**********************************
1812 *
1813 * Additional functions; Content Elements
1814 *
1815 **********************************/
1816 /**
1817 * Draw header for a content element column:
1818 *
1819 * @param string $colName Column name
1820 * @param string $editParams Edit params (Syntax: &edit[...] for FormEngine)
1821 * @return string HTML table
1822 */
1823 public function tt_content_drawColHeader($colName, $editParams = '')
1824 {
1825 $iconsArr = [];
1826 // Create command links:
1827 if ($this->tt_contentConfig['showCommands']) {
1828 // Edit whole of column:
1829 if ($editParams && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT) && $this->getBackendUser()->checkLanguageAccess(0)) {
1830 $iconsArr['edit'] = '<a href="#" onclick="'
1831 . htmlspecialchars(BackendUtility::editOnClick($editParams)) . '" title="'
1832 . htmlspecialchars($this->getLanguageService()->getLL('editColumn')) . '">'
1833 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1834 }
1835 }
1836 $icons = '';
1837 if (!empty($iconsArr)) {
1838 $icons = '<div class="t3-page-column-header-icons">' . implode('', $iconsArr) . '</div>';
1839 }
1840 // Create header row:
1841 $out = '<div class="t3-page-column-header">
1842 ' . $icons . '
1843 <div class="t3-page-column-header-label">' . htmlspecialchars($colName) . '</div>
1844 </div>';
1845 return $out;
1846 }
1847
1848 /**
1849 * Draw a paste icon either for pasting into a column or for pasting after a record
1850 *
1851 * @param int $pasteItem ID of the item in the clipboard
1852 * @param string $pasteTitle Title for the JS modal
1853 * @param string $copyMode copy or cut
1854 * @param string $cssClass CSS class to determine if pasting is done into column or after record
1855 * @param string $title title attribute of the generated link
1856 *
1857 * @return string Generated HTML code with link and icon
1858 */
1859 protected function tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, $cssClass, $title)
1860 {
1861 $pasteIcon = json_encode(
1862 ' <a data-content="' . htmlspecialchars($pasteItem) . '"'
1863 . ' data-title="' . htmlspecialchars($pasteTitle) . '"'
1864 . ' class="t3js-paste t3js-paste' . htmlspecialchars($copyMode) . ' ' . htmlspecialchars($cssClass) . ' btn btn-default btn-sm"'
1865 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL($title)) . '">'
1866 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
1867 . '</a>'
1868 );
1869 return $pasteIcon;
1870 }
1871
1872 /**
1873 * Draw the footer for a single tt_content element
1874 *
1875 * @param array $row Record array
1876 * @return string HTML of the footer
1877 * @throws \UnexpectedValueException
1878 */
1879 protected function tt_content_drawFooter(array $row)
1880 {
1881 $content = '';
1882 // Get processed values:
1883 $info = [];
1884 $this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,space_before_class,space_after_class', $row, $info);
1885
1886 // Content element annotation
1887 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn'])) {
1888 $info[] = htmlspecialchars($row[$GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']]);
1889 }
1890
1891 // Call drawFooter hooks
1892 $drawFooterHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'];
1893 if (is_array($drawFooterHooks)) {
1894 foreach ($drawFooterHooks as $className) {
1895 $hookObject = GeneralUtility::makeInstance($className);
1896 if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
1897 throw new \UnexpectedValueException($className . ' must implement interface ' . PageLayoutViewDrawFooterHookInterface::class, 1404378171);
1898 }
1899 $hookObject->preProcess($this, $info, $row);
1900 }
1901 }
1902
1903 // Display info from records fields:
1904 if (!empty($info)) {
1905 $content = '<div class="t3-page-ce-info">
1906 ' . implode('<br>', $info) . '
1907 </div>';
1908 }
1909 // Wrap it
1910 if (!empty($content)) {
1911 $content = '<div class="t3-page-ce-footer">' . $content . '</div>';
1912 }
1913 return $content;
1914 }
1915
1916 /**
1917 * Draw the header for a single tt_content element
1918 *
1919 * @param array $row Record array
1920 * @param int $space Amount of pixel space above the header. UNUSED
1921 * @param bool $disableMoveAndNewButtons If set the buttons for creating new elements and moving up and down are not shown.
1922 * @param bool $langMode If set, we are in language mode and flags will be shown for languages
1923 * @param bool $dragDropEnabled If set the move button must be hidden
1924 * @return string HTML table with the record header.
1925 */
1926 public function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = false, $langMode = false, $dragDropEnabled = false)
1927 {
1928 $out = '';
1929 // If show info is set...;
1930 if ($this->tt_contentConfig['showInfo'] && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1931 // Render control panel for the element:
1932 if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1933 // Edit content element:
1934 $urlParameters = [
1935 'edit' => [
1936 'tt_content' => [
1937 $this->tt_contentData['nextThree'][$row['uid']] => 'edit'
1938 ]
1939 ],
1940 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid'],
1941 ];
1942 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters) . '#element-tt_content-' . $row['uid'];
1943
1944 $out .= '<a class="btn btn-default" href="' . htmlspecialchars($url)
1945 . '" title="' . htmlspecialchars($this->nextThree > 1
1946 ? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
1947 : $this->getLanguageService()->getLL('edit'))
1948 . '">' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
1949 // Hide element:
1950 $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
1951 if ($hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
1952 && (!$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
1953 || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField))
1954 ) {
1955 if ($row[$hiddenField]) {
1956 $value = 0;
1957 $label = 'unHide';
1958 } else {
1959 $value = 1;
1960 $label = 'hide';
1961 }
1962 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'])
1963 . '][' . $hiddenField . ']=' . $value;
1964 $out .= '<a class="btn btn-default" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1965 . '#element-tt_content-' . $row['uid'] . '" title="' . htmlspecialchars($this->getLanguageService()->getLL($label)) . '">'
1966 . $this->iconFactory->getIcon('actions-edit-' . strtolower($label), Icon::SIZE_SMALL)->render() . '</a>';
1967 }
1968 // Delete
1969 $disableDeleteTS = $this->getBackendUser()->getTSConfig('options.disableDelete');
1970 $disableDelete = (bool) trim(isset($disableDeleteTS['properties']['tt_content']) ? $disableDeleteTS['properties']['tt_content'] : $disableDeleteTS['value']);
1971 if (!$disableDelete) {
1972 $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1973 $confirm = $this->getLanguageService()->getLL('deleteWarning')
1974 . BackendUtility::translationCount('tt_content', $row['uid'], (' '
1975 . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.translationsOfRecord')));
1976 $out .= '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params)) . '"'
1977 . ' data-severity="warning"'
1978 . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.title')) . '"'
1979 . ' data-content="' . htmlspecialchars($confirm) . '" '
1980 . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:cancel')) . '"'
1981 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('deleteItem')) . '">'
1982 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1983 if ($out && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1984 $out = '<div class="btn-group btn-group-sm" role="group">' . $out . '</div>';
1985 } else {
1986 $out = '';
1987 }
1988 }
1989 if (!$disableMoveAndNewButtons) {
1990 $moveButtonContent = '';
1991 $displayMoveButtons = false;
1992 // Move element up:
1993 if ($this->tt_contentData['prev'][$row['uid']]) {
1994 $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1995 $moveButtonContent .= '<a class="btn btn-default" href="'
1996 . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1997 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
1998 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1999 if (!$dragDropEnabled) {
2000 $displayMoveButtons = true;
2001 }
2002 } else {
2003 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
2004 }
2005 // Move element down:
2006 if ($this->tt_contentData['next'][$row['uid']]) {
2007 $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
2008 $moveButtonContent .= '<a class="btn btn-default" href="'
2009 . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
2010 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
2011 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
2012 if (!$dragDropEnabled) {
2013 $displayMoveButtons = true;
2014 }
2015 } else {
2016 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
2017 }
2018 if ($displayMoveButtons) {
2019 $out .= '<div class="btn-group btn-group-sm" role="group">' . $moveButtonContent . '</div>';
2020 }
2021 }
2022 }
2023 }
2024 $allowDragAndDrop = $this->isDragAndDropAllowed($row);
2025 $additionalIcons = [];
2026 if ($row['sys_language_uid'] > 0 && $this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid'])) {
2027 $allowDragAndDrop = false;
2028 }
2029 $additionalIcons[] = $this->getIcon('tt_content', $row) . ' ';
2030 $additionalIcons[] = $langMode ? $this->languageFlag($row['sys_language_uid'], false) : '';
2031 // Get record locking status:
2032 if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
2033 $additionalIcons[] = '<a href="#" data-toggle="tooltip" data-title="' . htmlspecialchars($lockInfo['msg']) . '">'
2034 . $this->iconFactory->getIcon('warning-in-use', Icon::SIZE_SMALL)->render() . '</a>';
2035 }
2036 // Call stats information hook
2037 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
2038 $_params = ['tt_content', $row['uid'], &$row];
2039 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
2040 $additionalIcons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2041 }
2042 }
2043 // Wrap the whole header
2044 // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
2045 return '<div class="t3-page-ce-header ' . ($allowDragAndDrop ? 't3-page-ce-header-draggable t3js-page-ce-draghandle' : '') . '">
2046 <div class="t3-page-ce-header-icons-left">' . implode('', $additionalIcons) . '</div>
2047 <div class="t3-page-ce-header-icons-right">' . ($out ? '<div class="btn-toolbar">' . $out . '</div>' : '') . '</div>
2048 </div>
2049 <div class="t3-page-ce-body">';
2050 }
2051
2052 /**
2053 * Determine whether Drag & Drop should be allowed
2054 *
2055 * @param array $row
2056 * @return bool
2057 */
2058 protected function isDragAndDropAllowed(array $row)
2059 {
2060 if ($this->getBackendUser()->user['admin']
2061 || ((int)$row['editlock'] === 0 && (int)$this->pageinfo['editlock'] === 0)
2062 && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
2063 && $this->getBackendUser()->checkAuthMode('tt_content', 'CType', $row['CType'], $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'])
2064 ) {
2065 return true;
2066 }
2067 return false;
2068 }
2069
2070 /**
2071 * Draws the preview content for a content element
2072 *
2073 * @param array $row Content element
2074 * @return string HTML
2075 * @throws \UnexpectedValueException
2076 */
2077 public function tt_content_drawItem($row)
2078 {
2079 $out = '';
2080 $outHeader = '';
2081 // Make header:
2082
2083 if ($row['header']) {
2084 $infoArr = [];
2085 $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
2086 $hiddenHeaderNote = '';
2087 // If header layout is set to 'hidden', display an accordant note:
2088 if ($row['header_layout'] == 100) {
2089 $hiddenHeaderNote = ' <em>[' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.hidden')) . ']</em>';
2090 }
2091 $outHeader = $row['date']
2092 ? htmlspecialchars($this->itemLabels['date'] . ' ' . BackendUtility::date($row['date'])) . '<br />'
2093 : '';
2094 $outHeader .= '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row)
2095 . $hiddenHeaderNote . '</strong><br />';
2096 }
2097 // Make content:
2098 $infoArr = [];
2099 $drawItem = true;
2100 // Hook: Render an own preview of a record
2101 $drawItemHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'];
2102 if (is_array($drawItemHooks)) {
2103 foreach ($drawItemHooks as $className) {
2104 $hookObject = GeneralUtility::makeInstance($className);
2105 if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
2106 throw new \UnexpectedValueException($className . ' must implement interface ' . PageLayoutViewDrawItemHookInterface::class, 1218547409);
2107 }
2108 $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
2109 }
2110 }
2111
2112 // If the previous hook did not render something,
2113 // then check if a Fluid-based preview template was defined for this CType
2114 // and render it via Fluid. Possible option:
2115 // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html
2116 if ($drawItem) {
2117 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod.web_layout.tt_content.preview');
2118 $fluidTemplateFile = '';
2119
2120 if (
2121 $row['CType'] === 'list' && !empty($row['list_type'])
2122 && !empty($tsConfig['properties']['list.'][$row['list_type']])
2123 ) {
2124 $fluidTemplateFile = $tsConfig['properties']['list.'][$row['list_type']];
2125 } elseif (!empty($tsConfig['properties'][$row['CType']])) {
2126 $fluidTemplateFile = $tsConfig['properties'][$row['CType']];
2127 }
2128
2129 if ($fluidTemplateFile) {
2130 $fluidTemplateFile = GeneralUtility::getFileAbsFileName($fluidTemplateFile);
2131 if ($fluidTemplateFile) {
2132 try {
2133 /** @var StandaloneView $view */
2134 $view = GeneralUtility::makeInstance(StandaloneView::class);
2135 $view->setTemplatePathAndFilename($fluidTemplateFile);
2136 $view->assignMultiple($row);
2137 if (!empty($row['pi_flexform'])) {
2138 /** @var FlexFormService $flexFormService */
2139 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
2140 $view->assign('pi_flexform_transformed', $flexFormService->convertFlexFormContentToArray($row['pi_flexform']));
2141 }
2142 $out = $view->render();
2143 $drawItem = false;
2144 } catch (\Exception $e) {
2145 // Catch any exception to avoid breaking the view
2146 }
2147 }
2148 }
2149 }
2150
2151 // Draw preview of the item depending on its CType (if not disabled by previous hook):
2152 if ($drawItem) {
2153 switch ($row['CType']) {
2154 case 'header':
2155 if ($row['subheader']) {
2156 $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
2157 }
2158 break;
2159 case 'bullets':
2160 case 'table':
2161 if ($row['bodytext']) {
2162 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
2163 }
2164 break;
2165 case 'uploads':
2166 if ($row['media']) {
2167 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'media'), $row) . '<br />';
2168 }
2169 break;
2170 case 'menu':
2171 $contentType = $this->CType_labels[$row['CType']];
2172 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
2173 // Add Menu Type
2174 $menuTypeLabel = $this->getLanguageService()->sL(
2175 BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'menu_type', $row['menu_type'])
2176 );
2177 $menuTypeLabel = $menuTypeLabel ?: 'invalid menu type';
2178 $out .= $this->linkEditContent($menuTypeLabel, $row);
2179 if ($row['menu_type'] !== '2' && ($row['pages'] || $row['selected_categories'])) {
2180 // Show pages if menu type is not "Sitemap"
2181 $out .= ':' . $this->linkEditContent($this->generateListForCTypeMenu($row), $row) . '<br />';
2182 }
2183 break;
2184 case 'shortcut':
2185 if (!empty($row['records'])) {
2186 $shortcutContent = [];
2187 $recordList = explode(',', $row['records']);
2188 foreach ($recordList as $recordIdentifier) {
2189 $split = BackendUtility::splitTable_Uid($recordIdentifier);
2190 $tableName = empty($split[0]) ? 'tt_content' : $split[0];
2191 $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]);
2192 if (is_array($shortcutRecord)) {
2193 $icon = $this->iconFactory->getIconForRecord($tableName, $shortcutRecord, Icon::SIZE_SMALL)->render();
2194 $icon = BackendUtility::wrapClickMenuOnIcon(
2195 $icon,
2196 $tableName,
2197 $shortcutRecord['uid']
2198 );
2199 $shortcutContent[] = $icon
2200 . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord));
2201 }
2202 }
2203 $out .= implode('<br />', $shortcutContent) . '<br />';
2204 }
2205 break;
2206 case 'list':
2207 $hookArr = [];
2208 $hookOut = '';
2209 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']])) {
2210 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']];
2211 } elseif (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'])) {
2212 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'];
2213 }
2214 if (!empty($hookArr)) {
2215 $_params = ['pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr];
2216 foreach ($hookArr as $_funcRef) {
2217 $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2218 }
2219 }
2220 if ((string)$hookOut !== '') {
2221 $out .= $hookOut;
2222 } elseif (!empty($row['list_type'])) {
2223 $label = BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'list_type', $row['list_type']);
2224 if (!empty($label)) {
2225 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($this->getLanguageService()->sL($label)) . '</strong>', $row) . '<br />';
2226 } else {
2227 $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'), $row['list_type']);
2228 $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>';
2229 }
2230 } else {
2231 $out .= '<strong>' . $this->getLanguageService()->getLL('noPluginSelected') . '</strong>';
2232 }
2233 $out .= htmlspecialchars($this->getLanguageService()->sL(
2234 BackendUtility::getLabelFromItemlist('tt_content', 'pages', $row['pages'])
2235 )) . '<br />';
2236 break;
2237 default:
2238 $contentType = $this->CType_labels[$row['CType']];
2239
2240 if (isset($contentType)) {
2241 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
2242 if ($row['bodytext']) {
2243 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
2244 }
2245 if ($row['image']) {
2246 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'image'), $row) . '<br />';
2247 }
2248 } else {
2249 $message = sprintf(
2250 $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'),
2251 $row['CType']
2252 );
2253 $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>';
2254 }
2255 }
2256 }
2257 // Wrap span-tags:
2258 $out = '
2259 <span class="exampleContent">' . $out . '</span>';
2260 // Add header:
2261 $out = $outHeader . $out;
2262 // Return values:
2263 if ($this->isDisabled('tt_content', $row)) {
2264 return '<span class="text-muted">' . $out . '</span>';
2265 }
2266 return $out;
2267 }
2268
2269 /**
2270 * Generates a list of selected pages or categories for the CType menu
2271 *
2272 * @param array $row row from pages
2273 * @return string
2274 */
2275 protected function generateListForCTypeMenu(array $row)
2276 {
2277 $table = 'pages';
2278 $field = 'pages';
2279 // get categories instead of pages
2280 if (strpos($row['menu_type'], 'categorized_') !== false) {
2281 $table = 'sys_category';
2282 $field = 'selected_categories';
2283 }
2284 if (trim($row[$field]) === '') {
2285 return '';
2286 }
2287 $content = '';
2288 $uidList = explode(',', $row[$field]);
2289 foreach ($uidList as $uid) {
2290 $uid = (int)$uid;
2291 $record = BackendUtility::getRecord($table, $uid, 'title');
2292 $content .= '<br>' . $record['title'] . ' (' . $uid . ')';
2293 }
2294 return $content;
2295 }
2296
2297 /**
2298 * Filters out all tt_content uids which are already translated so only non-translated uids is left.
2299 * Selects across columns, but within in the same PID. Columns are expect to be the same
2300 * for translations and original but this may be a conceptual error (?)
2301 *
2302 * @param array $defaultLanguageUids Numeric array with uids of tt_content elements in the default language
2303 * @param int $id Page pid
2304 * @param int $lP Sys language UID
2305 * @return array Modified $defLanguageCount
2306 */
2307 public function getNonTranslatedTTcontentUids($defaultLanguageUids, $id, $lP)
2308 {
2309 if ($lP && !empty($defaultLanguageUids)) {
2310 // Select all translations here:
2311 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
2312 ->getQueryBuilderForTable('tt_content');
2313 $queryBuilder->getRestrictions()
2314 ->removeAll()
2315 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
2316 $queryBuilder
2317 ->select('*')
2318 ->from('tt_content')
2319 ->where(
2320 $queryBuilder->expr()->eq(
2321 'sys_language_uid',
2322 $queryBuilder->createNamedParameter($lP, \PDO::PARAM_INT)
2323 ),
2324 $queryBuilder->expr()->in(
2325 'l18n_parent',
2326 $queryBuilder->createNamedParameter($defaultLanguageUids, Connection::PARAM_INT_ARRAY)
2327 )
2328 );
2329
2330 $result = $queryBuilder->execute();
2331
2332 // Flip uids:
2333 $defaultLanguageUids = array_flip($defaultLanguageUids);
2334 // Traverse any selected elements and unset original UID if any:
2335 while ($row = $result->fetch()) {
2336 BackendUtility::workspaceOL('tt_content', $row);
2337 unset($defaultLanguageUids[$row['l18n_parent']]);
2338 }
2339 // Flip again:
2340 $defaultLanguageUids = array_keys($defaultLanguageUids);
2341 }
2342 return $defaultLanguageUids;
2343 }
2344
2345 /**
2346 * Creates button which is used to create copies of records..
2347 *
2348 * @param array $defaultLanguageUids Numeric array with uids of tt_content elements in the default language
2349 * @param int $lP Sys language UID
2350 * @param int $colPos Column position
2351 * @return string "Copy languages" button, if available.
2352 */
2353 public function newLanguageButton($defaultLanguageUids, $lP, $colPos = 0)
2354 {
2355 $lP = (int)$lP;
2356 if (!$this->doEdit || !$lP) {
2357 return '';
2358 }
2359 $theNewButton = '';
2360
2361 $localizationTsConfig = BackendUtility::getModTSconfig($this->id, 'mod.web_layout.localization');
2362 $allowCopy = isset($localizationTsConfig['properties']['enableCopy'])
2363 ? (int)$localizationTsConfig['properties']['enableCopy'] === 1
2364 : true;
2365 $allowTranslate = isset($localizationTsConfig['properties']['enableTranslate'])
2366 ? (int)$localizationTsConfig['properties']['enableTranslate'] === 1
2367 : true;
2368
2369 if (!empty($this->languageHasTranslationsCache[$lP])) {
2370 if (isset($this->languageHasTranslationsCache[$lP]['hasStandAloneContent'])) {
2371 $allowTranslate = false;
2372 }
2373 if (isset($this->languageHasTranslationsCache[$lP]['hasTranslations'])) {
2374 $allowCopy = false;
2375 }
2376 }
2377
2378 if (isset($this->contentElementCache[$lP][$colPos]) && is_array($this->contentElementCache[$lP][$colPos])) {
2379 foreach ($this->contentElementCache[$lP][$colPos] as $record) {
2380 $key = array_search($record['l10n_source'], $defaultLanguageUids);
2381 if ($key !== false) {
2382 unset($defaultLanguageUids[$key]);
2383 }
2384 }
2385 }
2386
2387 if (!empty($defaultLanguageUids)) {
2388 $theNewButton =
2389 '<input'
2390 . ' class="btn btn-default t3js-localize"'
2391 . ' type="button"'
2392 . ' disabled'
2393 . ' value="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_translate')) . '"'
2394 . ' data-has-elements="' . (int)!empty($this->contentElementCache[$lP][$colPos]) . '"'
2395 . ' data-allow-copy="' . (int)$allowCopy . '"'
2396 . ' data-allow-translate="' . (int)$allowTranslate . '"'
2397 . ' data-table="tt_content"'
2398 . ' data-page-id="' . (int)GeneralUtility::_GP('id') . '"'
2399 . ' data-language-id="' . $lP . '"'
2400 . ' data-language-name="' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '"'
2401 . ' data-colpos-id="' . $colPos . '"'
2402 . ' data-colpos-name="' . BackendUtility::getProcessedValue('tt_content', 'colPos', $colPos) . '"'
2403 . '/>';
2404 }
2405
2406 return '<div class="t3-page-lang-copyce">' . $theNewButton . '</div>';
2407 }
2408
2409 /**
2410 * Creates onclick-attribute content for a new content element
2411 *
2412 * @param int $id Page id where to create the element.
2413 * @param int $colPos Preset: Column position value
2414 * @param int $sys_language Preset: Sys langauge value
2415 * @return string String for onclick attribute.
2416 * @see getTable_tt_content()
2417 */
2418 public function newContentElementOnClick($id, $colPos, $sys_language)
2419 {
2420 if ($this->option_newWizard) {
2421 $tsConfig = BackendUtility::getModTSconfig($id, 'mod');
2422 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
2423 ? $tsConfig['properties']['newContentElementWizard.']['override']
2424 : 'new_content_element';
2425 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl($moduleName) . '&id=' . $id . '&colPos=' . $colPos
2426 . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id
2427 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
2428 } else {
2429 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]='
2430 . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language);
2431 }
2432 return $onClick;
2433 }
2434
2435 /**
2436 * Will create a link on the input string and possibly a big button after the string which links to editing in the RTE.
2437 * Used for content element content displayed so the user can click the content / "Edit in Rich Text Editor" button
2438 *
2439 * @param string $str String to link. Must be prepared for HTML output.
2440 * @param array $row The row.
2441 * @return string If the whole thing was editable ($this->doEdit) $str is return with link around. Otherwise just $str.
2442 * @see getTable_tt_content()
2443 */
2444 public function linkEditContent($str, $row)
2445 {
2446 if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
2447 $urlParameters = [
2448 'edit' => [
2449 'tt_content' => [
2450 $row['uid'] => 'edit'
2451 ]
2452 ],
2453 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid']
2454 ];
2455 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
2456 // Return link
2457 return '<a href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">' . $str . '</a>';
2458 }
2459 return $str;
2460 }
2461
2462 /**
2463 * Make selector box for creating new translation in a language
2464 * Displays only languages which are not yet present for the current page and
2465 * that are not disabled with page TS.
2466 *
2467 * @param int $id Page id for which to create a new language (pages_language_overlay record)
2468 * @return string <select> HTML element (if there were items for the box anyways...)
2469 * @see getTable_tt_content()
2470 */
2471 public function languageSelector($id)
2472 {
2473 if ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
2474 // First, select all
2475 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
2476 $queryBuilder->getRestrictions()->removeAll();
2477 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
2478 $statement = $queryBuilder->select('uid', 'title')
2479 ->from('sys_language')
2480 ->orderBy('sorting')
2481 ->execute();
2482 $availableTranslations = [];
2483 while ($row = $statement->fetch()) {
2484 if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
2485 $availableTranslations[(int)$row['uid']] = $row['title'];
2486 }
2487 }
2488 // Then, subtract the languages which are already on the page:
2489 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
2490 $queryBuilder->getRestrictions()->removeAll();
2491 $queryBuilder->select('sys_language.uid AS uid', 'sys_language.title AS title')
2492 ->from('sys_language')
2493 ->join(
2494 'sys_language',
2495 'pages_language_overlay',
2496 'pages_language_overlay',
2497 $queryBuilder->expr()->eq('sys_language.uid', $queryBuilder->quoteIdentifier('pages_language_overlay.sys_language_uid'))
2498 )
2499 ->where(
2500 $queryBuilder->expr()->eq(
2501 'pages_language_overlay.deleted',
2502 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
2503 ),
2504 $queryBuilder->expr()->eq(
2505 'pages_language_overlay.pid',
2506 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
2507 ),
2508 $queryBuilder->expr()->orX(
2509 $queryBuilder->expr()->gte(
2510 'pages_language_overlay.t3ver_state',
2511 $queryBuilder->createNamedParameter(
2512 (string)new VersionState(VersionState::DEFAULT_STATE),
2513 \PDO::PARAM_INT
2514 )
2515 ),
2516 $queryBuilder->expr()->eq(
2517 'pages_language_overlay.t3ver_wsid',
2518 $queryBuilder->createNamedParameter($this->getBackendUser()->workspace, \PDO::PARAM_INT)
2519 )
2520 )
2521 )
2522 ->groupBy(
2523 'pages_language_overlay.sys_language_uid',
2524 'sys_language.uid',
2525 'sys_language.pid',
2526 'sys_language.tstamp',
2527 'sys_language.hidden',
2528 'sys_language.title',
2529 'sys_language.language_isocode',
2530 'sys_language.static_lang_isocode',
2531 'sys_language.flag',
2532 'sys_language.sorting'
2533 )
2534 ->orderBy('sys_language.sorting');
2535 if (!$this->getBackendUser()->isAdmin()) {
2536 $queryBuilder->andWhere(
2537 $queryBuilder->expr()->eq(
2538 'sys_language.hidden',
2539 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
2540 )
2541 );
2542 }
2543 $statement = $queryBuilder->execute();
2544 while ($row = $statement->fetch()) {
2545 unset($availableTranslations[(int)$row['uid']]);
2546 }
2547 // Remove disallowed languages
2548 if (!empty($availableTranslations)
2549 && !$this->getBackendUser()->user['admin']
2550 && $this->getBackendUser()->groupData['allowed_languages'] !== ''
2551 ) {
2552 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
2553 if (!empty($allowed_languages)) {
2554 foreach ($availableTranslations as $key => $value) {
2555 if (!isset($allowed_languages[$key]) && $key != 0) {
2556 unset($availableTranslations[$key]);
2557 }
2558 }
2559 }
2560 }
2561 // Remove disabled languages
2562 $modSharedTSconfig = BackendUtility::getModTSconfig($id, 'mod.SHARED');
2563 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
2564 ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true)
2565 : [];
2566 if (!empty($availableTranslations) && !empty($disableLanguages)) {
2567 foreach ($disableLanguages as $language) {
2568 if ($language != 0 && isset($availableTranslations[$language])) {
2569 unset($availableTranslations[$language]);
2570 }
2571 }
2572 }
2573 // If any languages are left, make selector:
2574 if (!empty($availableTranslations)) {
2575 $output = '<option value=""></option>';
2576 foreach ($availableTranslations as $languageUid => $languageTitle) {
2577 // Build localize command URL to DataHandler (tce_db)
2578 // which redirects to FormEngine (record_edit)
2579 // which, when finished editing should return back to the current page (returnUrl)
2580 $parameters = [
2581 'justLocalized' => 'pages:' . $id . ':' . $languageUid,
2582 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
2583 ];
2584 $redirectUrl = BackendUtility::getModuleUrl('record_edit', $parameters);
2585 $targetUrl = BackendUtility::getLinkToDataHandlerAction(
2586 '&cmd[pages][' . $id . '][localize]=' . $languageUid,
2587 $redirectUrl
2588 );
2589
2590 $output .= '<option value="' . htmlspecialchars($targetUrl) . '">' . htmlspecialchars($languageTitle) . '</option>';
2591 }
2592
2593 return '<div class="form-inline form-inline-spaced">'
2594 . '<div class="form-group">'
2595 . '<label for="createNewLanguage">'
2596 . htmlspecialchars($this->getLanguageService()->getLL('new_language'))
2597 . '</label>'
2598 . '<select class="form-control input-sm" name="createNewLanguage" onchange="window.location.href=this.options[this.selectedIndex].value">'
2599 . $output
2600 . '</select></div></div>';
2601 }
2602 }
2603 return '';
2604 }
2605
2606 /**
2607 * Traverse the result pointer given, adding each record to array and setting some internal values at the same time.
2608 *
2609 * @param Statement $result DBAL Statement
2610 * @param string $table Table name defaulting to tt_content
2611 * @return array The selected rows returned in this array.
2612 */
2613 public function getResult(Statement $result, string $table = 'tt_content'): array
2614 {
2615 $output = [];
2616 // Traverse the result:
2617 while ($row = $result->fetch()) {
2618 BackendUtility::workspaceOL($table, $row, -99, true);
2619 if ($row) {
2620 // Add the row to the array:
2621 $output[] = $row;
2622 }
2623 }
2624 $this->generateTtContentDataArray($output);
2625 // Return selected records
2626 return $output;
2627 }
2628
2629 /********************************
2630 *
2631 * Various helper functions
2632 *
2633 ********************************/
2634
2635 /**
2636 * Initializes the clipboard for generating paste links
2637 *
2638 *
2639 * @see \TYPO3\CMS\Recordlist\RecordList::main()
2640 * @see \TYPO3\CMS\Backend\Controller\ContextMenuController::clipboardAction()
2641 * @see \TYPO3\CMS\Filelist\Controller\FileListController::indexAction()
2642 */
2643 protected function initializeClipboard()
2644 {
2645 // Start clipboard
2646 $this->clipboard = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
2647
2648 // Initialize - reads the clipboard content from the user session
2649 $this->clipboard->initializeClipboard();
2650
2651 // This locks the clipboard to the Normal for this request.
2652 $this->clipboard->lockToNormal();
2653
2654 // Clean up pad
2655 $this->clipboard->cleanCurrent();
2656
2657 // Save the clipboard content
2658 $this->clipboard->endClipboard();
2659 }
2660
2661 /**
2662 * Generates the data for previous and next elements which is needed for movements.
2663 *
2664 * @param array $rowArray
2665 */
2666 protected function generateTtContentDataArray(array $rowArray)
2667 {
2668 if (empty($this->tt_contentData)) {
2669 $this->tt_contentData = [
2670 'nextThree' => [],
2671 'next' => [],
2672 'prev' => [],
2673 ];
2674 }
2675 foreach ($rowArray as $key => $value) {
2676 // Create the list of the next three ids (for editing links...)
2677 for ($i = 0; $i < $this->nextThree; $i++) {
2678 if (isset($rowArray[$key - $i])
2679 && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
2680 ) {
2681 $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
2682 }
2683 }
2684
2685 // Create information for next and previous content elements
2686 if (isset($rowArray[$key - 1])) {
2687 if (isset($rowArray[$key - 2])) {
2688 $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
2689 } else {
2690 $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
2691 }
2692 $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
2693 }
2694 }
2695 }
2696
2697 /**
2698 * Counts and returns the number of records on the page with $pid
2699 *
2700 * @param string $table Table name
2701 * @param int $pid Page id
2702 * @return int Number of records.
2703 */
2704 public function numberOfRecords($table, $pid)
2705 {
2706 $count = 0;
2707 if ($GLOBALS['TCA'][$table]) {
2708 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
2709 ->getQueryBuilderForTable($table);
2710 $queryBuilder->getRestrictions()
2711 ->removeAll()
2712 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2713 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
2714 $count = (int)$queryBuilder->count('uid')
2715 ->from($table)
2716 ->where(
2717 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT))
2718 )
2719 ->execute()
2720 ->fetchColumn();
2721 }
2722
2723 return $count;
2724 }
2725
2726 /**
2727 * Processing of larger amounts of text (usually from RTE/bodytext fields) with word wrapping etc.
2728 *
2729 * @param string $input Input string
2730 * @return string Output string
2731 */
2732 public function renderText($input)
2733 {
2734 $input = strip_tags($input);
2735 $input = GeneralUtility::fixed_lgd_cs($input, 1500);
2736 return nl2br(htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8', false));
2737 }
2738
2739 /**
2740 * Creates the icon image tag for record from table and wraps it in a link which will trigger the click menu.
2741 *
2742 * @param string $table Table name
2743 * @param array $row Record array
2744 * @param string $enabledClickMenuItems Passthrough to wrapClickMenuOnIcon
2745 * @return string HTML for the icon
2746 */
2747 public function getIcon($table, $row, $enabledClickMenuItems = '')
2748 {
2749 // Initialization
2750 $toolTip = BackendUtility::getRecordToolTip($row, 'tt_content');
2751 $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
2752 $this->counter++;
2753 // The icon with link
2754 if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) {
2755 $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid']);
2756 }
2757 return $icon;
2758 }
2759
2760 /**
2761 * Creates processed values for all field names in $fieldList based on values from $row array.
2762 * The result is 'returned' through $info which is passed as a reference
2763 *
2764 * @param string $table Table name
2765 * @param string $fieldList Comma separated list of fields.
2766 * @param array $row Record from which to take values for processing.
2767 * @param array $info Array to which the processed values are added.
2768 */
2769 public function getProcessedValue($table, $fieldList, array $row, array &$info)
2770 {
2771 // Splitting values from $fieldList
2772 $fieldArr = explode(',', $fieldList);
2773 // Traverse fields from $fieldList
2774 foreach ($fieldArr as $field) {
2775 if ($row[$field]) {
2776 $info[] = '<strong>' . htmlspecialchars($this->itemLabels[$field]) . '</strong> '
2777 . htmlspecialchars(BackendUtility::getProcessedValue($table, $field, $row[$field]));
2778 }
2779 }
2780 }
2781
2782 /**
2783 * Returns TRUE, if the record given as parameters is NOT visible based on hidden/starttime/endtime (if available)
2784 *
2785 * @param string $table Tablename of table to test
2786 * @param array $row Record row.
2787 * @return bool Returns TRUE, if disabled.
2788 */
2789 public function isDisabled($table, $row)
2790 {
2791 $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
2792 return $enableCols['disabled'] && $row[$enableCols['disabled']]
2793 || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME']
2794 || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME'];
2795 }
2796
2797 /**
2798 * Returns icon for "no-edit" of a record.
2799 * Basically, the point is to signal that this record could have had an edit link if
2800 * the circumstances were right. A placeholder for the regular edit icon...
2801 *
2802 * @param string $label Label key from LOCAL_LANG
2803 * @return string IMG tag for icon.
2804 */
2805 public function noEditIcon($label = 'noEditItems')
2806 {
2807 $title = htmlspecialchars($this->getLanguageService()->getLL($label));
2808 return '<span title="' . $title . '">' . $this->iconFactory->getIcon('status-edit-read-only', Icon::SIZE_SMALL)->render() . '</span>';
2809 }
2810
2811 /*****************************************
2812 *
2813 * External renderings
2814 *
2815 *****************************************/
2816
2817 /**
2818 * Creates a menu of the tables that can be listed by this function
2819 * Only tables which has records on the page will be included.
2820 * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
2821 *
2822 * @param int $id Page id from which we are listing records (the function will look up if there are records on the page)
2823 * @return string HTML output.
2824 */
2825 public function getTableMenu($id)
2826 {
2827 // Initialize:
2828 $this->activeTables = [];
2829 $theTables = ['tt_content'];
2830 // External tables:
2831 if (is_array($this->externalTables)) {
2832 $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2833 }
2834 $out = '';
2835 // Traverse tables to check:
2836 foreach ($theTables as $tName) {
2837 // Check access and whether the proper extensions are loaded:
2838 if ($this->getBackendUser()->check('tables_select', $tName)
2839 && (
2840 isset($this->externalTables[$tName])
2841 || $tName === 'fe_users' || $tName === 'tt_content'
2842 || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName)
2843 )
2844 ) {
2845 // Make query to count records from page:
2846 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
2847 ->getQueryBuilderForTable($tName);
2848 $queryBuilder->getRestrictions()
2849 ->removeAll()
2850 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2851 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
2852 $count = $queryBuilder->count('uid')
2853 ->from($tName)
2854 ->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
2855 ->execute()
2856 ->fetchColumn();
2857 // If records were found (or if "tt_content" is the table...):
2858 if ($count || $tName === 'tt_content') {
2859 // Add row to menu:
2860 $out .= '
2861 <td><a href="#' . $tName . '" title="' . htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'])) . '"></a>'
2862 . $this->iconFactory->getIconForRecord($tName, [], Icon::SIZE_SMALL)->render()
2863 . '</td>';
2864 // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2865 $title = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title']))
2866 . ': ' . $count . ' ' . htmlspecialchars($this->getLanguageService()->getLL('records'));
2867 $this->activeTables[$tName] = '<span title="' . $title . '">'
2868 . $this->iconFactory->getIconForRecord($tName, [], Icon::SIZE_SMALL)->render()
2869 . '</span>'
2870 . '&nbsp;' . htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title']));
2871 }
2872 }
2873 }
2874 // Wrap cells in table tags:
2875 $out = '
2876 <!--
2877 Menu of tables on the page (table menu)
2878 -->
2879 <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
2880 <tr>' . $out . '
2881 </tr>
2882 </table>';
2883 // Return the content:
2884 return $out;
2885 }
2886
2887 /**
2888 * Create thumbnail code for record/field but not linked
2889 *
2890 * @param mixed[] $row Record array
2891 * @param string $table Table (record is from)
2892 * @param string $field Field name for which thumbnail are to be rendered.
2893 * @return string HTML for thumbnails, if any.
2894 */
2895 public function getThumbCodeUnlinked($row, $table, $field)
2896 {
2897 return BackendUtility::thumbCode($row, $table, $field, '', '', null, 0, '', '', false);
2898 }
2899
2900 /**
2901 * Checks whether translated Content Elements exist in the desired language
2902 * If so, deny creating new ones via the UI
2903 *
2904 * @param array $contentElements
2905 * @param int $language
2906 * @return bool
2907 */
2908 protected function checkIfTranslationsExistInLanguage(array $contentElements, $language)
2909 {
2910 // If in default language, you may always create new entries
2911 // Also, you may override this strict behavior via user TS Config
2912 // If you do so, you're on your own and cannot rely on any support by the TYPO3 core
2913 // We jump out here since we don't need to do the expensive loop operations
2914 $allowInconsistentLanguageHandling = BackendUtility::getModTSconfig($this->id, 'mod.web_layout.allowInconsistentLanguageHandling');
2915 if ($language === 0 || $allowInconsistentLanguageHandling['value'] === '1') {
2916 return false;
2917 }
2918 /**
2919 * Build up caches
2920 */
2921 if (!isset($this->languageHasTranslationsCache[$language])) {
2922 foreach ($contentElements as $columns) {
2923 foreach ($columns as $contentElement) {
29