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