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