55b961b5343331c763514e37e374b7c4f2dc459b
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayoutView.php
1 <?php
2
3 namespace TYPO3\CMS\Backend\View;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Doctrine\DBAL\Driver\Statement;
19 use Psr\Log\LoggerAwareInterface;
20 use Psr\Log\LoggerAwareTrait;
21 use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
22 use TYPO3\CMS\Backend\Controller\Page\LocalizationController;
23 use TYPO3\CMS\Backend\Controller\PageLayoutController;
24 use TYPO3\CMS\Backend\Routing\Router;
25 use TYPO3\CMS\Backend\Routing\UriBuilder;
26 use TYPO3\CMS\Backend\Tree\View\PageTreeView;
27 use TYPO3\CMS\Backend\Utility\BackendUtility;
28 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
29 use TYPO3\CMS\Core\Database\Connection;
30 use TYPO3\CMS\Core\Database\ConnectionPool;
31 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
32 use TYPO3\CMS\Core\Database\Query\QueryHelper;
33 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
34 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
35 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
36 use TYPO3\CMS\Core\Imaging\Icon;
37 use TYPO3\CMS\Core\Imaging\IconFactory;
38 use TYPO3\CMS\Core\Localization\LanguageService;
39 use TYPO3\CMS\Core\Messaging\FlashMessage;
40 use TYPO3\CMS\Core\Messaging\FlashMessageService;
41 use TYPO3\CMS\Core\Page\PageRenderer;
42 use TYPO3\CMS\Core\Service\DependencyOrderingService;
43 use TYPO3\CMS\Core\Type\Bitmask\Permission;
44 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
45 use TYPO3\CMS\Core\Utility\GeneralUtility;
46 use TYPO3\CMS\Core\Utility\HttpUtility;
47 use TYPO3\CMS\Core\Utility\MathUtility;
48 use TYPO3\CMS\Core\Utility\StringUtility;
49 use TYPO3\CMS\Core\Versioning\VersionState;
50 use TYPO3\CMS\Extbase\Service\FlexFormService;
51 use TYPO3\CMS\Fluid\View\StandaloneView;
52 use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
53
54 /**
55 * Child class for the Web > Page module
56 */
57 class PageLayoutView implements LoggerAwareInterface
58 {
59 use LoggerAwareTrait;
60
61 /**
62 * If TRUE, users/groups are shown in the page info box.
63 *
64 * @var 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 * Construct to initialize class variables.
619 */
620 public function __construct()
621 {
622 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
623 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
624 }
625 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
626 $this->getTranslateTools();
627 $this->determineScriptUrl();
628 $this->localizationController = GeneralUtility::makeInstance(LocalizationController::class);
629 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
630 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
631 $pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
632 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
633 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
634 }
635
636 /*****************************************
637 *
638 * Renderings
639 *
640 *****************************************/
641 /**
642 * Adds the code of a single table
643 *
644 * @param string $table Table name
645 * @param int $id Current page id
646 * @param string $fields
647 * @return string HTML for listing.
648 */
649 public function getTable($table, $id, $fields = '')
650 {
651 if (isset($this->externalTables[$table])) {
652 return $this->getExternalTables($id, $table);
653 }
654 // Branch out based on table name:
655 switch ($table) {
656 case 'pages':
657 return $this->getTable_pages($id);
658 break;
659 case 'tt_content':
660 return $this->getTable_tt_content($id);
661 break;
662 default:
663 return '';
664 }
665 }
666
667 /**
668 * Renders an external table from page id
669 *
670 * @param int $id Page id
671 * @param string $table Name of the table
672 * @return string HTML for the listing
673 */
674 public function getExternalTables($id, $table)
675 {
676 $this->pageinfo = BackendUtility::readPageAccess($id, '');
677 $type = $this->getPageLayoutController()->MOD_SETTINGS[$table];
678 if (!isset($type)) {
679 $type = 0;
680 }
681 // eg. "name;title;email;company,image"
682 $fList = $this->externalTables[$table][$type]['fList'];
683 // The columns are separeted by comma ','.
684 // Values separated by semicolon ';' are shown in the same column.
685 $icon = $this->externalTables[$table][$type]['icon'];
686 $addWhere = $this->externalTables[$table][$type]['addWhere'];
687 // Create listing
688 $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
689 return $out;
690 }
691
692 /**
693 * Renders records from the pages table from page id
694 * (Used to get information about the page tree content by "Web>Info"!)
695 *
696 * @param int $id Page id
697 * @return string HTML for the listing
698 */
699 public function getTable_pages($id)
700 {
701 // Initializing:
702 $out = '';
703 $lang = $this->getLanguageService();
704 // Select current page:
705 if (!$id) {
706 // The root has a pseudo record in pageinfo...
707 $row = $this->getPageLayoutController()->pageinfo;
708 } else {
709 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
710 ->getQueryBuilderForTable('pages');
711 $queryBuilder->getRestrictions()
712 ->removeAll()
713 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
714 $row = $queryBuilder
715 ->select('*')
716 ->from('pages')
717 ->where(
718 $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)),
719 $this->getBackendUser()->getPagePermsClause(1)
720 )
721 ->execute()
722 ->fetch();
723 BackendUtility::workspaceOL('pages', $row);
724 }
725 // If there was found a page:
726 if (is_array($row)) {
727 // Getting select-depth:
728 $depth = (int)$this->getPageLayoutController()->MOD_SETTINGS['pages_levels'];
729 // Overriding a few things:
730 $this->no_noWrap = 0;
731 // Items
732 $this->eCounter = $this->firstElementNumber;
733 // Creating elements:
734 list($flag, $code) = $this->fwd_rwd_nav();
735 $out .= $code;
736 $editUids = [];
737 if ($flag) {
738 // Getting children:
739 $theRows = $this->getPageRecordsRecursive($row['uid'], $depth);
740 if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
741 $editUids[] = $row['uid'];
742 }
743 $out .= $this->pages_drawItem($row, $this->fieldArray);
744 // Traverse all pages selected:
745 foreach ($theRows as $sRow) {
746 if ($this->getBackendUser()->doesUserHaveAccess($sRow, 2)) {
747 $editUids[] = $sRow['uid'];
748 }
749 $out .= $this->pages_drawItem($sRow, $this->fieldArray);
750 }
751 $this->eCounter++;
752 }
753 // Header line is drawn
754 $theData = [];
755 $editIdList = implode(',', $editUids);
756 // Traverse fields (as set above) in order to create header values:
757 foreach ($this->fieldArray as $field) {
758 if ($editIdList
759 && isset($GLOBALS['TCA']['pages']['columns'][$field])
760 && $field !== 'uid'
761 && !$this->pages_noEditColumns
762 ) {
763 $iTitle = sprintf(
764 $lang->getLL('editThisColumn'),
765 rtrim(trim($lang->sL(BackendUtility::getItemLabel('pages', $field))), ':')
766 );
767 $urlParameters = [
768 'edit' => [
769 'pages' => [
770 $editIdList => 'edit'
771 ]
772 ],
773 'columnsOnly' => $field,
774 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
775 ];
776 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
777 $eI = '<a class="btn btn-default" href="' . htmlspecialchars($url)
778 . '" title="' . htmlspecialchars($iTitle) . '">'
779 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
780 } else {
781 $eI = '';
782 }
783 switch ($field) {
784 case 'title':
785 $theData[$field] = '&nbsp;' . $eI . '<strong>'
786 . $lang->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'])
787 . '</strong>';
788 break;
789 case 'uid':
790 $theData[$field] = '&nbsp;<strong>ID:</strong>';
791 break;
792 default:
793 if (substr($field, 0, 6) === 'table_') {
794 $f2 = substr($field, 6);
795 if ($GLOBALS['TCA'][$f2]) {
796 $theData[$field] = '&nbsp;' .
797 '<span title="' .
798 htmlspecialchars($lang->sL($GLOBALS['TCA'][$f2]['ctrl']['title'])) .
799 '">' .
800 $this->iconFactory->getIconForRecord($f2, [], Icon::SIZE_SMALL)->render() .
801 '</span>';
802 }
803 } else {
804 $theData[$field] = '&nbsp;&nbsp;' . $eI . '<strong>'
805 . htmlspecialchars($lang->sL($GLOBALS['TCA']['pages']['columns'][$field]['label']))
806 . '</strong>';
807 }
808 }
809 }
810 $out = '<div class="table-fit">'
811 . '<table class="table table-striped table-hover typo3-page-pages">'
812 . '<thead>'
813 . $this->addElement(1, '', $theData)
814 . '</thead>'
815 . '<tbody>'
816 . $out
817 . '</tbody>'
818 . '</table>'
819 . '</div>';
820 }
821 return $out;
822 }
823
824 /**
825 * Renders Content Elements from the tt_content table from page id
826 *
827 * @param int $id Page id
828 * @return string HTML for the listing
829 */
830 public function getTable_tt_content($id)
831 {
832 $backendUser = $this->getBackendUser();
833 $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
834 ->getConnectionForTable('tt_content')
835 ->getExpressionBuilder();
836 $this->pageinfo = BackendUtility::readPageAccess($this->id, '');
837 $this->initializeLanguages();
838 $this->initializeClipboard();
839 $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', BackendUtility::getRecordWSOL('pages', $id), true));
840 /** @var $pageRenderer PageRenderer */
841 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
842 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
843 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
844 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
845 $userCanEditPage = $this->ext_CALC_PERMS & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
846 if ($userCanEditPage) {
847 $languageOverlayId = 0;
848 $pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, (int)$this->tt_contentConfig['sys_language_uid']);
849 if (is_array($pageLocalizationRecord)) {
850 $pageLocalizationRecord = reset($pageLocalizationRecord);
851 }
852 if (!empty($pageLocalizationRecord['uid'])) {
853 $languageOverlayId = $pageLocalizationRecord['uid'];
854 }
855 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', 'function(PageActions) {
856 PageActions.setPageId(' . (int)$this->id . ');
857 PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
858 PageActions.initializePageTitleRenaming();
859 }');
860 }
861 // Get labels for CTypes and tt_content element fields in general:
862 $this->CType_labels = [];
863 foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
864 $this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
865 }
866 $this->itemLabels = [];
867 foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
868 $this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
869 }
870 $languageColumn = [];
871 $out = '';
872
873 // Setting language list:
874 $langList = $this->tt_contentConfig['sys_language_uid'];
875 if ($this->tt_contentConfig['languageMode']) {
876 if ($this->tt_contentConfig['languageColsPointer']) {
877 $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
878 } else {
879 $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
880 }
881 $languageColumn = [];
882 }
883 $langListArr = GeneralUtility::intExplode(',', $langList);
884 $defaultLanguageElementsByColumn = [];
885 $defLangBinding = [];
886 // For each languages... :
887 // If not languageMode, then we'll only be through this once.
888 foreach ($langListArr as $lP) {
889 $lP = (int)$lP;
890
891 if (!isset($this->contentElementCache[$lP])) {
892 $this->contentElementCache[$lP] = [];
893 }
894
895 if (count($langListArr) === 1 || $lP === 0) {
896 $showLanguage = $expressionBuilder->in('sys_language_uid', [$lP, -1]);
897 } else {
898 $showLanguage = $expressionBuilder->eq('sys_language_uid', $lP);
899 }
900 $content = [];
901 $head = [];
902
903 $backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
904 $columns = $backendLayout['__colPosList'];
905 // Select content records per column
906 $contentRecordsPerColumn = $this->getContentRecordsPerColumn('table', $id, $columns, $showLanguage);
907 $cList = array_keys($contentRecordsPerColumn);
908 // For each column, render the content into a variable:
909 foreach ($cList as $columnId) {
910 if (!isset($this->contentElementCache[$lP][$columnId])) {
911 $this->contentElementCache[$lP][$columnId] = [];
912 }
913
914 if (!$lP) {
915 $defaultLanguageElementsByColumn[$columnId] = [];
916 }
917 // Start wrapping div
918 $content[$columnId] .= '<div data-colpos="' . $columnId . '" data-language-uid="' . $lP . '" class="t3js-sortable t3js-sortable-lang t3js-sortable-lang-' . $lP . ' t3-page-ce-wrapper';
919 if (empty($contentRecordsPerColumn[$columnId])) {
920 $content[$columnId] .= ' t3-page-ce-empty';
921 }
922 $content[$columnId] .= '">';
923 // Add new content at the top most position
924 $link = '';
925 if ($this->getPageLayoutController()->contentIsNotLockedForEditors()
926 && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
927 ) {
928 if ($this->option_newWizard) {
929 $urlParameters = [
930 'id' => $id,
931 'sys_language_uid' => $lP,
932 'colPos' => $columnId,
933 'uid_pid' => $id,
934 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
935 ];
936 $tsConfig = BackendUtility::getModTSconfig($id, 'mod');
937 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
938 ? $tsConfig['properties']['newContentElementWizard.']['override']
939 : 'new_content_element_wizard';
940 $url = BackendUtility::getModuleUrl($moduleName, $urlParameters);
941 } else {
942 $urlParameters = [
943 'edit' => [
944 'tt_content' => [
945 $id => 'new'
946 ]
947 ],
948 'defVals' => [
949 'tt_content' => [
950 'colPos' => $columnId,
951 'sys_language_uid' => $lP
952 ]
953 ],
954 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
955 ];
956 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
957 }
958 $title = htmlspecialchars($this->getLanguageService()->getLL('newContentElement'));
959 $link = '<a href="#" data-url="' . htmlspecialchars($url) . '" '
960 . 'title="' . $title . '"'
961 . 'data-title="' . $title . '"'
962 . 'class="btn btn-default btn-sm t3js-toggle-new-content-element-wizard">'
963 . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render()
964 . ' '
965 . htmlspecialchars($this->getLanguageService()->getLL('content')) . '</a>';
966 }
967 if ($this->getBackendUser()->checkLanguageAccess($lP) && $columnId !== 'unused') {
968 $content[$columnId] .= '
969 <div class="t3-page-ce t3js-page-ce" data-page="' . (int)$id . '" id="' . StringUtility::getUniqueId() . '">
970 <div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $columnId . '-' . 'page-' . $id . '-' . StringUtility::getUniqueId() . '">'
971 . $link
972 . '</div>
973 <div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div>
974 </div>
975 ';
976 }
977 $editUidList = '';
978 if (!isset($contentRecordsPerColumn[$columnId]) || !is_array($contentRecordsPerColumn[$columnId])) {
979 $message = GeneralUtility::makeInstance(
980 FlashMessage::class,
981 $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:error.invalidBackendLayout'),
982 '',
983 FlashMessage::WARNING
984 );
985 $service = GeneralUtility::makeInstance(FlashMessageService::class);
986 $queue = $service->getMessageQueueByIdentifier();
987 $queue->addMessage($message);
988 } else {
989 $rowArr = $contentRecordsPerColumn[$columnId];
990 $this->generateTtContentDataArray($rowArr);
991
992 foreach ((array)$rowArr as $rKey => $row) {
993 $this->contentElementCache[$lP][$columnId][$row['uid']] = $row;
994 if ($this->tt_contentConfig['languageMode']) {
995 $languageColumn[$columnId][$lP] = $head[$columnId] . $content[$columnId];
996 if (!$this->defLangBinding && $columnId !== 'unused') {
997 $languageColumn[$columnId][$lP] .= $this->newLanguageButton(
998 $this->getNonTranslatedTTcontentUids($defaultLanguageElementsByColumn[$columnId], $id, $lP),
999 $lP,
1000 $columnId
1001 );
1002 }
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][] = (isset($row['_ORIG_uid']) ? $row['_ORIG_uid'] : $row['uid']);
1008 }
1009 $editUidList .= $row['uid'] . ',';
1010 $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0;
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 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod');
1059 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
1060 ? $tsConfig['properties']['newContentElementWizard.']['override']
1061 : 'new_content_element_wizard';
1062 $url = BackendUtility::getModuleUrl($moduleName, $urlParameters);
1063 } else {
1064 $urlParameters = [
1065 'edit' => [
1066 'tt_content' => [
1067 -$row['uid'] => 'new'
1068 ]
1069 ],
1070 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1071 ];
1072 $url = BackendUtility::getModuleUrl('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']] = $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 if (!$this->defLangBinding && $columnId !== 'unused') {
1132 $languageColumn[$columnId][$lP] .= $this->newLanguageButton(
1133 $this->getNonTranslatedTTcontentUids($defaultLanguageElementsByColumn[$columnId], $id, $lP),
1134 $lP,
1135 $columnId
1136 );
1137 }
1138 // We sort $languageColumn again according to $cList as it may contain data already from above.
1139 $sortedLanguageColumn[$columnId] = $languageColumn[$columnId];
1140 }
1141 }
1142 if (!empty($languageColumn['unused'])) {
1143 $sortedLanguageColumn['unused'] = $languageColumn['unused'];
1144 }
1145 $languageColumn = $sortedLanguageColumn;
1146 } else {
1147 // GRID VIEW:
1148 $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">';
1149 // Add colgroups
1150 $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
1151 $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
1152 $grid .= '<colgroup>';
1153 for ($i = 0; $i < $colCount; $i++) {
1154 $grid .= '<col />';
1155 }
1156 $grid .= '</colgroup>';
1157 // Cycle through rows
1158 for ($row = 1; $row <= $rowCount; $row++) {
1159 $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
1160 if (!isset($rowConfig)) {
1161 continue;
1162 }
1163 $grid .= '<tr>';
1164 for ($col = 1; $col <= $colCount; $col++) {
1165 $columnConfig = $rowConfig['columns.'][$col . '.'];
1166 if (!isset($columnConfig)) {
1167 continue;
1168 }
1169 // Which tt_content colPos should be displayed inside this cell
1170 $columnKey = (int)$columnConfig['colPos'];
1171 // Render the grid cell
1172 $colSpan = (int)$columnConfig['colspan'];
1173 $rowSpan = (int)$columnConfig['rowspan'];
1174 $grid .= '<td valign="top"' .
1175 ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
1176 ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
1177 ' 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 .
1178 ((!isset($columnConfig['colPos']) || $columnConfig['colPos'] === '') ? ' t3-grid-cell-unassigned' : '') .
1179 ((isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && !$head[$columnKey]) || !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos']) ? ' t3-grid-cell-restricted' : '') .
1180 ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') .
1181 ($rowSpan > 0 ? ' t3-gridCell-height' . $rowSpan : '') . '">';
1182
1183 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
1184 // If not, a new header without any buttons will be generated.
1185 if (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && $head[$columnKey]
1186 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
1187 ) {
1188 $grid .= $head[$columnKey] . $content[$columnKey];
1189 } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
1190 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
1191 ) {
1192 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('noAccess'));
1193 } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
1194 && !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
1195 ) {
1196 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name']) .
1197 ' (' . $this->getLanguageService()->getLL('noAccess') . ')');
1198 } elseif (isset($columnConfig['name']) && $columnConfig['name'] !== '') {
1199 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name'])
1200 . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')');
1201 } else {
1202 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('notAssigned'));
1203 }
1204
1205 $grid .= '</td>';
1206 }
1207 $grid .= '</tr>';
1208 }
1209 if (!empty($content['unused'])) {
1210 $grid .= '<tr>';
1211 // Which tt_content colPos should be displayed inside this cell
1212 $columnKey = 'unused';
1213 // Render the grid cell
1214 $colSpan = (int)$backendLayout['__config']['backend_layout.']['colCount'];
1215 $grid .= '<td valign="top"' .
1216 ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
1217 ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
1218 ' 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 .
1219 ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') . '">';
1220
1221 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
1222 // If not, a new header without any buttons will be generated.
1223 $grid .= $head[$columnKey] . $content[$columnKey];
1224 $grid .= '</td></tr>';
1225 }
1226 $out .= $grid . '</table></div>';
1227 }
1228 }
1229 $elFromTable = $this->clipboard->elFromTable('tt_content');
1230 if (!empty($elFromTable) && $this->getPageLayoutController()->pageIsNotLockedForEditors()) {
1231 $pasteItem = substr(key($elFromTable), 11);
1232 $pasteRecord = BackendUtility::getRecord('tt_content', (int)$pasteItem);
1233 $pasteTitle = $pasteRecord['header'] ? $pasteRecord['header'] : $pasteItem;
1234 $copyMode = $this->clipboard->clipData['normal']['mode'] ? '-' . $this->clipboard->clipData['normal']['mode'] : '';
1235 $addExtOnReadyCode = '
1236 top.pasteIntoLinkTemplate = '
1237 . $this->tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, 't3js-paste-into', 'pasteIntoColumn')
1238 . ';
1239 top.pasteAfterLinkTemplate = '
1240 . $this->tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, 't3js-paste-after', 'pasteAfterRecord')
1241 . ';';
1242 } else {
1243 $addExtOnReadyCode = '
1244 top.pasteIntoLinkTemplate = \'\';
1245 top.pasteAfterLinkTemplate = \'\';';
1246 }
1247 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
1248 $pageRenderer->addJsInlineCode('pasteLinkTemplates', $addExtOnReadyCode);
1249 // If language mode, then make another presentation:
1250 // Notice that THIS presentation will override the value of $out!
1251 // But it needs the code above to execute since $languageColumn is filled with content we need!
1252 if ($this->tt_contentConfig['languageMode']) {
1253 // Get language selector:
1254 $languageSelector = $this->languageSelector($id);
1255 // Reset out - we will make new content here:
1256 $out = '';
1257 // Traverse languages found on the page and build up the table displaying them side by side:
1258 $cCont = [];
1259 $sCont = [];
1260 foreach ($langListArr as $lP) {
1261 // Header:
1262 $lP = (int)$lP;
1263 $cCont[$lP] = '
1264 <td valign="top" class="t3-page-column" data-language-uid="' . $lP . '">
1265 <h2>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '</h2>
1266 </td>';
1267
1268 // "View page" icon is added:
1269 $viewLink = '';
1270 if (!VersionState::cast($this->getPageLayoutController()->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1271 $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id), '', '', ('&L=' . $lP));
1272 $viewLink = '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage')) . '">' . $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>';
1273 }
1274 // Language overlay page header:
1275 if ($lP) {
1276 $pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $id, $lP);
1277 if (is_array($pageLocalizationRecord)) {
1278 $pageLocalizationRecord = reset($pageLocalizationRecord);
1279 }
1280 BackendUtility::workspaceOL('pages', $pageLocalizationRecord);
1281 $recordIcon = BackendUtility::wrapClickMenuOnIcon(
1282 $this->iconFactory->getIconForRecord('pages', $pageLocalizationRecord, Icon::SIZE_SMALL)->render(),
1283 'pages',
1284 $pageLocalizationRecord['uid']
1285 );
1286 $urlParameters = [
1287 'edit' => [
1288 'pages' => [
1289 $pageLocalizationRecord['uid'] => 'edit'
1290 ]
1291 ],
1292 'overrideVals' => [
1293 'pages' => [
1294 'sys_language_uid' => $lP
1295 ]
1296 ],
1297 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1298 ];
1299 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1300 $editLink = (
1301 $this->getBackendUser()->check('tables_modify', 'pages')
1302 ? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
1303 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
1304 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
1305 : ''
1306 );
1307
1308 $lPLabel =
1309 '<div class="btn-group">'
1310 . $viewLink
1311 . $editLink
1312 . '</div>'
1313 . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($pageLocalizationRecord['title'], 20));
1314 } else {
1315 $editLink = '';
1316 $recordIcon = '';
1317 if ($this->getBackendUser()->checkLanguageAccess(0)) {
1318 $recordIcon = BackendUtility::wrapClickMenuOnIcon(
1319 $this->iconFactory->getIconForRecord('pages', $this->pageRecord, Icon::SIZE_SMALL)->render(),
1320 'pages',
1321 $this->id
1322 );
1323 $urlParameters = [
1324 'edit' => [
1325 'pages' => [
1326 $this->id => 'edit'
1327 ]
1328 ],
1329 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1330 ];
1331 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1332 $editLink = (
1333 $this->getBackendUser()->check('tables_modify', 'pages')
1334 ? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
1335 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
1336 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
1337 : ''
1338 );
1339 }
1340
1341 $lPLabel =
1342 '<div class="btn-group">'
1343 . $viewLink
1344 . $editLink
1345 . '</div>'
1346 . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->pageRecord['title'], 20));
1347 }
1348 $sCont[$lP] = '
1349 <td class="t3-page-column t3-page-lang-label nowrap">' . $lPLabel . '</td>';
1350 }
1351 // Add headers:
1352 $out .= '<tr>' . implode($cCont) . '</tr>';
1353 $out .= '<tr>' . implode($sCont) . '</tr>';
1354 unset($cCont, $sCont);
1355
1356 // Traverse previously built content for the columns:
1357 foreach ($languageColumn as $cKey => $cCont) {
1358 $out .= '<tr>';
1359 foreach ($cCont as $languageId => $columnContent) {
1360 $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>';
1361 }
1362 $out .= '</tr>';
1363 if ($this->defLangBinding) {
1364 // "defLangBinding" mode
1365 foreach ($defaultLanguageElementsByColumn[$cKey] as $defUid) {
1366 $cCont = [];
1367 foreach ($langListArr as $lP) {
1368 $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
1369 $this->getNonTranslatedTTcontentUids([$defUid], $id, $lP),
1370 $lP,
1371 $cKey
1372 );
1373 }
1374 $out .= '
1375 <tr>
1376 <td valign="top" class="t3-grid-cell">' . implode(('</td>' . '
1377 <td valign="top" class="t3-grid-cell">'), $cCont) . '</td>
1378 </tr>';
1379 }
1380 }
1381 }
1382 // Finally, wrap it all in a table and add the language selector on top of it:
1383 $out = $languageSelector . '
1384 <div class="t3-grid-container">
1385 <table cellpadding="0" cellspacing="0" class="t3-page-columns t3-grid-table t3js-page-columns">
1386 ' . $out . '
1387 </table>
1388 </div>';
1389 }
1390
1391 return $out;
1392 }
1393
1394 /**********************************
1395 *
1396 * Generic listing of items
1397 *
1398 **********************************/
1399 /**
1400 * Creates a standard list of elements from a table.
1401 *
1402 * @param string $table Table name
1403 * @param int $id Page id.
1404 * @param string $fList Comma list of fields to display
1405 * @param bool $icon If TRUE, icon is shown
1406 * @param string $addWhere Additional WHERE-clauses.
1407 * @return string HTML table
1408 */
1409 public function makeOrdinaryList($table, $id, $fList, $icon = false, $addWhere = '')
1410 {
1411 // Initialize
1412 $addWhere = empty($addWhere) ? [] : [QueryHelper::stripLogicalOperatorPrefix($addWhere)];
1413 $queryBuilder = $this->getQueryBuilder($table, $id, $addWhere);
1414 $this->setTotalItems($table, $id, $addWhere);
1415 $dbCount = 0;
1416 $result = false;
1417 // Make query for records if there were any records found in the count operation
1418 if ($this->totalItems) {
1419 $result = $queryBuilder->execute();
1420 // Will return FALSE, if $result is invalid
1421 $dbCount = $result->rowCount();
1422 }
1423 // If records were found, render the list
1424 if (!$dbCount) {
1425 return '';
1426 }
1427 // Set fields
1428 $out = '';
1429 $this->fieldArray = GeneralUtility::trimExplode(',', '__cmds__,' . $fList . ',__editIconLink__', true);
1430 $theData = [];
1431 $theData = $this->headerFields($this->fieldArray, $table, $theData);
1432 // Title row
1433 $localizedTableTitle = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title']));
1434 $out .= '<tr><th class="col-icon"></th>'
1435 . '<th colspan="' . (count($theData) - 2) . '"><span class="c-table">'
1436 . $localizedTableTitle . '</span> (' . $dbCount . ')</td>' . '<td class="col-icon"></td>'
1437 . '</tr>';
1438 // Column's titles
1439 if ($this->doEdit) {
1440 $urlParameters = [
1441 'edit' => [
1442 $table => [
1443 $this->id => 'new'
1444 ]
1445 ],
1446 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1447 ];
1448 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1449 $title = htmlspecialchars($this->getLanguageService()->getLL('new'));
1450 $theData['__cmds__'] = '<a href="#" data-url="' . htmlspecialchars($url) . '" class="t3js-toggle-new-content-element-wizard" '
1451 . 'title="' . $title . '"'
1452 . 'data-title="' . $title . '">'
1453 . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render() . '</a>';
1454 }
1455 $out .= $this->addElement(1, '', $theData, ' class="c-headLine"', 15, '', 'th');
1456 // Render Items
1457 $this->eCounter = $this->firstElementNumber;
1458 while ($row = $result->fetch()) {
1459 BackendUtility::workspaceOL($table, $row);
1460 if (is_array($row)) {
1461 list($flag, $code) = $this->fwd_rwd_nav();
1462 $out .= $code;
1463 if ($flag) {
1464 $Nrow = [];
1465 // Setting icons links
1466 if ($icon) {
1467 $Nrow['__cmds__'] = $this->getIcon($table, $row);
1468 }
1469 // Get values:
1470 $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
1471 // Attach edit icon
1472 if ($this->doEdit && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1473 $urlParameters = [
1474 'edit' => [
1475 $table => [
1476 $row['uid'] => 'edit'
1477 ]
1478 ],
1479 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1480 ];
1481 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1482 $Nrow['__editIconLink__'] = '<a class="btn btn-default" href="' . htmlspecialchars($url)
1483 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
1484 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
1485 } else {
1486 $Nrow['__editIconLink__'] = $this->noEditIcon();
1487 }
1488 $out .= $this->addElement(1, '', $Nrow);
1489 }
1490 $this->eCounter++;
1491 }
1492 }
1493 // Wrap it all in a table:
1494 $out = '
1495 <!--
1496 Standard list of table "' . $table . '"
1497 -->
1498 <div class="table-fit"><table class="table table-hover table-striped">
1499 ' . $out . '
1500 </table></div>';
1501 return $out;
1502 }
1503
1504 /**
1505 * Adds content to all data fields in $out array
1506 *
1507 * Each field name in $fieldArr has a special feature which is that the field name can be specified as more field names.
1508 * Eg. "field1,field2;field3".
1509 * Field 2 and 3 will be shown in the same cell of the table separated by <br /> while field1 will have its own cell.
1510 *
1511 * @param array $fieldArr Array of fields to display
1512 * @param string $table Table name
1513 * @param array $row Record array
1514 * @param array $out Array to which the data is added
1515 * @return array $out array returned after processing.
1516 * @see makeOrdinaryList()
1517 */
1518 public function dataFields($fieldArr, $table, $row, $out = [])
1519 {
1520 // Check table validity
1521 if (!isset($GLOBALS['TCA'][$table])) {
1522 return $out;
1523 }
1524
1525 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
1526 // Traverse fields
1527 foreach ($fieldArr as $fieldName) {
1528 if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
1529 // Each field has its own cell (if configured in TCA)
1530 // If the column is a thumbnail column:
1531 if ($fieldName == $thumbsCol) {
1532 $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
1533 } else {
1534 // ... otherwise just render the output:
1535 $out[$fieldName] = nl2br(htmlspecialchars(trim(GeneralUtility::fixed_lgd_cs(
1536 BackendUtility::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']),
1537 250
1538 ))));
1539 }
1540 } else {
1541 // Each field is separated by <br /> and shown in the same cell (If not a TCA field, then explode
1542 // the field name with ";" and check each value there as a TCA configured field)
1543 $theFields = explode(';', $fieldName);
1544 // Traverse fields, separated by ";" (displayed in a single cell).
1545 foreach ($theFields as $fName2) {
1546 if ($GLOBALS['TCA'][$table]['columns'][$fName2]) {
1547 $out[$fieldName] .= '<strong>' . htmlspecialchars($this->getLanguageService()->sL(
1548 $GLOBALS['TCA'][$table]['columns'][$fName2]['label']
1549 )) . '</strong>' . '&nbsp;&nbsp;' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(
1550 BackendUtility::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']),
1551 25
1552 )) . '<br />';
1553 }
1554 }
1555 }
1556 // If no value, add a nbsp.
1557 if (!$out[$fieldName]) {
1558 $out[$fieldName] = '&nbsp;';
1559 }
1560 // Wrap in dimmed-span tags if record is "disabled"
1561 if ($this->isDisabled($table, $row)) {
1562 $out[$fieldName] = '<span class="text-muted">' . $out[$fieldName] . '</span>';
1563 }
1564 }
1565 return $out;
1566 }
1567
1568 /**
1569 * Header fields made for the listing of records
1570 *
1571 * @param array $fieldArr Field names
1572 * @param string $table The table name
1573 * @param array $out Array to which the headers are added.
1574 * @return array $out returned after addition of the header fields.
1575 * @see makeOrdinaryList()
1576 */
1577 public function headerFields($fieldArr, $table, $out = [])
1578 {
1579 foreach ($fieldArr as $fieldName) {
1580 $ll = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']));
1581 $out[$fieldName] = $ll ? $ll : '&nbsp;';
1582 }
1583 return $out;
1584 }
1585
1586 /**
1587 * Gets content records per column.
1588 * This is required for correct workspace overlays.
1589 *
1590 * @param string $table UNUSED (will always be queried from tt_content)
1591 * @param int $id Page Id to be used (not used at all, but part of the API, see $this->pidSelect)
1592 * @param array $columns colPos values to be considered to be shown
1593 * @param string $additionalWhereClause Additional where clause for database select
1594 * @return array Associative array for each column (colPos)
1595 */
1596 protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '')
1597 {
1598 $contentRecordsPerColumn = array_fill_keys($columns, []);
1599 $columns = array_flip($columns);
1600 $queryBuilder = $this->getQueryBuilder(
1601 'tt_content',
1602 $id,
1603 [
1604 $additionalWhereClause
1605 ]
1606 );
1607
1608 // Traverse any selected elements and render their display code:
1609 $results = $this->getResult($queryBuilder->execute());
1610 $unused = [];
1611 $hookArray = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['record_is_used'] ?? [];
1612 foreach ($results as $record) {
1613 $used = isset($columns[$record['colPos']]);
1614 foreach ($hookArray as $_funcRef) {
1615 $_params = ['columns' => $columns, 'record' => $record, 'used' => $used];
1616 $used = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1617 }
1618 if ($used) {
1619 $columnValue = (string)$record['colPos'];
1620 $contentRecordsPerColumn[$columnValue][] = $record;
1621 } else {
1622 $unused[] = $record;
1623 }
1624 }
1625 if (!empty($unused)) {
1626 $contentRecordsPerColumn['unused'] = $unused;
1627 }
1628 return $contentRecordsPerColumn;
1629 }
1630
1631 /**********************************
1632 *
1633 * Additional functions; Pages
1634 *
1635 **********************************/
1636
1637 /**
1638 * Adds pages-rows to an array, selecting recursively in the page tree.
1639 *
1640 * @param int $pid Starting page id to select from
1641 * @param string $iconPrefix Prefix for icon code.
1642 * @param int $depth Depth (decreasing)
1643 * @param array $rows Array which will accumulate page rows
1644 * @return array $rows with added rows.
1645 */
1646 protected function getPageRecordsRecursive(int $pid, int $depth, string $iconPrefix = '', array $rows = []): array
1647 {
1648 $depth--;
1649 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1650 $queryBuilder->getRestrictions()
1651 ->removeAll()
1652 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1653 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1654
1655 $queryBuilder
1656 ->select('*')
1657 ->from('pages')
1658 ->where(
1659 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)),
1660 $queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
1661 $this->getBackendUser()->getPagePermsClause(1)
1662 );
1663
1664 if (!empty($GLOBALS['TCA']['pages']['ctrl']['sortby'])) {
1665 $queryBuilder->orderBy($GLOBALS['TCA']['pages']['ctrl']['sortby']);
1666 }
1667
1668 if ($depth >= 0) {
1669 $result = $queryBuilder->execute();
1670 $rowCount = $result->rowCount();
1671 $count = 0;
1672 while ($row = $result->fetch()) {
1673 BackendUtility::workspaceOL('pages', $row);
1674 if (is_array($row)) {
1675 $count++;
1676 $row['treeIcons'] = $iconPrefix
1677 . '<span class="treeline-icon treeline-icon-join'
1678 . ($rowCount === $count ? 'bottom' : '')
1679 . '"></span>';
1680 $rows[] = $row;
1681 // Get the branch
1682 $spaceOutIcons = '<span class="treeline-icon treeline-icon-'
1683 . ($rowCount === $count ? 'clear' : 'line')
1684 . '"></span>';
1685 $rows = $this->getPageRecordsRecursive(
1686 $row['uid'],
1687 $row['php_tree_stop'] ? 0 : $depth,
1688 $iconPrefix . $spaceOutIcons,
1689 $rows
1690 );
1691 }
1692 }
1693 }
1694
1695 return $rows;
1696 }
1697
1698 /**
1699 * Adds a list item for the pages-rendering
1700 *
1701 * @param array $row Record array
1702 * @param array $fieldArr Field list
1703 * @return string HTML for the item
1704 */
1705 public function pages_drawItem($row, $fieldArr)
1706 {
1707 // Initialization
1708 $theIcon = $this->getIcon('pages', $row);
1709 // Preparing and getting the data-array
1710 $theData = [];
1711 foreach ($fieldArr as $field) {
1712 switch ($field) {
1713 case 'title':
1714 $pTitle = htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field], 20));
1715 $theData[$field] = $row['treeIcons'] . $theIcon . $pTitle . '&nbsp;&nbsp;';
1716 break;
1717 case 'php_tree_stop':
1718 // Intended fall through
1719 case 'TSconfig':
1720 $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1721 break;
1722 case 'uid':
1723 if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
1724 $urlParameters = [
1725 'edit' => [
1726 'pages' => [
1727 $row['uid'] => 'edit'
1728 ]
1729 ],
1730 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1731 ];
1732 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1733 $eI = '<a class="btn btn-default" href="' . htmlspecialchars($url)
1734 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('editThisPage')) . '">'
1735 . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render() . '</a>';
1736 } else {
1737 $eI = '';
1738 }
1739 $theData[$field] = $eI . '<span align="right">' . $row['uid'] . '</span>';
1740 break;
1741 case 'shortcut':
1742 case 'shortcut_mode':
1743 if ((int)$row['doktype'] === \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1744 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1745 }
1746 break;
1747 default:
1748 if (substr($field, 0, 6) === 'table_') {
1749 $f2 = substr($field, 6);
1750 if ($GLOBALS['TCA'][$f2]) {
1751 $c = $this->numberOfRecords($f2, $row['uid']);
1752 $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1753 }
1754 } else {
1755 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1756 }
1757 }
1758 }
1759 $this->addElement_tdParams['title'] = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '';
1760 return $this->addElement(1, '', $theData);
1761 }
1762
1763 /**
1764 * Returns the HTML code for rendering a field in the pages table.
1765 * The row value is processed to a human readable form and the result is parsed through htmlspecialchars().
1766 *
1767 * @param string $field The name of the field of which the value should be rendered.
1768 * @param array $row The pages table row as an associative array.
1769 * @return string The rendered table field value.
1770 */
1771 protected function getPagesTableFieldValue($field, array $row)
1772 {
1773 return '&nbsp;&nbsp;' . htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field]));
1774 }
1775
1776 /**********************************
1777 *
1778 * Additional functions; Content Elements
1779 *
1780 **********************************/
1781 /**
1782 * Draw header for a content element column:
1783 *
1784 * @param string $colName Column name
1785 * @param string $editParams Edit params (Syntax: &edit[...] for FormEngine)
1786 * @return string HTML table
1787 */
1788 public function tt_content_drawColHeader($colName, $editParams = '')
1789 {
1790 $iconsArr = [];
1791 // Create command links:
1792 if ($this->tt_contentConfig['showCommands']) {
1793 // Edit whole of column:
1794 if ($editParams && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT) && $this->getBackendUser()->checkLanguageAccess(0)) {
1795 $iconsArr['edit'] = '<a href="#" onclick="'
1796 . htmlspecialchars(BackendUtility::editOnClick($editParams)) . '" title="'
1797 . htmlspecialchars($this->getLanguageService()->getLL('editColumn')) . '">'
1798 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1799 }
1800 }
1801 $icons = '';
1802 if (!empty($iconsArr)) {
1803 $icons = '<div class="t3-page-column-header-icons">' . implode('', $iconsArr) . '</div>';
1804 }
1805 // Create header row:
1806 $out = '<div class="t3-page-column-header">
1807 ' . $icons . '
1808 <div class="t3-page-column-header-label">' . htmlspecialchars($colName) . '</div>
1809 </div>';
1810 return $out;
1811 }
1812
1813 /**
1814 * Draw a paste icon either for pasting into a column or for pasting after a record
1815 *
1816 * @param int $pasteItem ID of the item in the clipboard
1817 * @param string $pasteTitle Title for the JS modal
1818 * @param string $copyMode copy or cut
1819 * @param string $cssClass CSS class to determine if pasting is done into column or after record
1820 * @param string $title title attribute of the generated link
1821 *
1822 * @return string Generated HTML code with link and icon
1823 */
1824 protected function tt_content_drawPasteIcon($pasteItem, $pasteTitle, $copyMode, $cssClass, $title)
1825 {
1826 $pasteIcon = json_encode(
1827 ' <a data-content="' . htmlspecialchars($pasteItem) . '"'
1828 . ' data-title="' . htmlspecialchars($pasteTitle) . '"'
1829 . ' class="t3js-paste t3js-paste' . htmlspecialchars($copyMode) . ' ' . htmlspecialchars($cssClass) . ' btn btn-default btn-sm"'
1830 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL($title)) . '">'
1831 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
1832 . '</a>'
1833 );
1834 return $pasteIcon;
1835 }
1836
1837 /**
1838 * Draw the footer for a single tt_content element
1839 *
1840 * @param array $row Record array
1841 * @return string HTML of the footer
1842 * @throws \UnexpectedValueException
1843 */
1844 protected function tt_content_drawFooter(array $row)
1845 {
1846 $content = '';
1847 // Get processed values:
1848 $info = [];
1849 $this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,space_before_class,space_after_class', $row, $info);
1850
1851 // Content element annotation
1852 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn'])) {
1853 $info[] = htmlspecialchars($row[$GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']]);
1854 }
1855
1856 // Call drawFooter hooks
1857 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'] ?? [] as $className) {
1858 $hookObject = GeneralUtility::makeInstance($className);
1859 if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
1860 throw new \UnexpectedValueException($className . ' must implement interface ' . PageLayoutViewDrawFooterHookInterface::class, 1404378171);
1861 }
1862 $hookObject->preProcess($this, $info, $row);
1863 }
1864
1865 // Display info from records fields:
1866 if (!empty($info)) {
1867 $content = '<div class="t3-page-ce-info">
1868 ' . implode('<br>', $info) . '
1869 </div>';
1870 }
1871 // Wrap it
1872 if (!empty($content)) {
1873 $content = '<div class="t3-page-ce-footer">' . $content . '</div>';
1874 }
1875 return $content;
1876 }
1877
1878 /**
1879 * Draw the header for a single tt_content element
1880 *
1881 * @param array $row Record array
1882 * @param int $space Amount of pixel space above the header. UNUSED
1883 * @param bool $disableMoveAndNewButtons If set the buttons for creating new elements and moving up and down are not shown.
1884 * @param bool $langMode If set, we are in language mode and flags will be shown for languages
1885 * @param bool $dragDropEnabled If set the move button must be hidden
1886 * @return string HTML table with the record header.
1887 */
1888 public function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = false, $langMode = false, $dragDropEnabled = false)
1889 {
1890 $out = '';
1891 // If show info is set...;
1892 if ($this->tt_contentConfig['showInfo'] && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1893 // Render control panel for the element:
1894 if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1895 // Edit content element:
1896 $urlParameters = [
1897 'edit' => [
1898 'tt_content' => [
1899 $this->tt_contentData['nextThree'][$row['uid']] => 'edit'
1900 ]
1901 ],
1902 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid'],
1903 ];
1904 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters) . '#element-tt_content-' . $row['uid'];
1905
1906 $out .= '<a class="btn btn-default" href="' . htmlspecialchars($url)
1907 . '" title="' . htmlspecialchars($this->nextThree > 1
1908 ? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
1909 : $this->getLanguageService()->getLL('edit'))
1910 . '">' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
1911 // Hide element:
1912 $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
1913 if ($hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
1914 && (!$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
1915 || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField))
1916 ) {
1917 if ($row[$hiddenField]) {
1918 $value = 0;
1919 $label = 'unHide';
1920 } else {
1921 $value = 1;
1922 $label = 'hide';
1923 }
1924 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'])
1925 . '][' . $hiddenField . ']=' . $value;
1926 $out .= '<a class="btn btn-default" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1927 . '#element-tt_content-' . $row['uid'] . '" title="' . htmlspecialchars($this->getLanguageService()->getLL($label)) . '">'
1928 . $this->iconFactory->getIcon('actions-edit-' . strtolower($label), Icon::SIZE_SMALL)->render() . '</a>';
1929 }
1930 // Delete
1931 $disableDeleteTS = $this->getBackendUser()->getTSConfig('options.disableDelete');
1932 $disableDelete = (bool) trim(isset($disableDeleteTS['properties']['tt_content']) ? $disableDeleteTS['properties']['tt_content'] : $disableDeleteTS['value']);
1933 if (!$disableDelete) {
1934 $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1935 $confirm = $this->getLanguageService()->getLL('deleteWarning')
1936 . BackendUtility::translationCount('tt_content', $row['uid'], (' '
1937 . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.translationsOfRecord')));
1938 $out .= '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params)) . '"'
1939 . ' data-severity="warning"'
1940 . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.title')) . '"'
1941 . ' data-content="' . htmlspecialchars($confirm) . '" '
1942 . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:cancel')) . '"'
1943 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('deleteItem')) . '">'
1944 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1945 if ($out && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1946 $out = '<div class="btn-group btn-group-sm" role="group">' . $out . '</div>';
1947 } else {
1948 $out = '';
1949 }
1950 }
1951 if (!$disableMoveAndNewButtons) {
1952 $moveButtonContent = '';
1953 $displayMoveButtons = false;
1954 // Move element up:
1955 if ($this->tt_contentData['prev'][$row['uid']]) {
1956 $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1957 $moveButtonContent .= '<a class="btn btn-default" href="'
1958 . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1959 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
1960 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1961 if (!$dragDropEnabled) {
1962 $displayMoveButtons = true;
1963 }
1964 } else {
1965 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1966 }
1967 // Move element down:
1968 if ($this->tt_contentData['next'][$row['uid']]) {
1969 $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
1970 $moveButtonContent .= '<a class="btn btn-default" href="'
1971 . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1972 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
1973 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
1974 if (!$dragDropEnabled) {
1975 $displayMoveButtons = true;
1976 }
1977 } else {
1978 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1979 }
1980 if ($displayMoveButtons) {
1981 $out .= '<div class="btn-group btn-group-sm" role="group">' . $moveButtonContent . '</div>';
1982 }
1983 }
1984 }
1985 }
1986 $allowDragAndDrop = $this->isDragAndDropAllowed($row);
1987 $additionalIcons = [];
1988 if ($row['sys_language_uid'] > 0 && $this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid'])) {
1989 $allowDragAndDrop = false;
1990 }
1991 $additionalIcons[] = $this->getIcon('tt_content', $row) . ' ';
1992 $additionalIcons[] = $langMode ? $this->languageFlag($row['sys_language_uid'], false) : '';
1993 // Get record locking status:
1994 if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
1995 $additionalIcons[] = '<a href="#" data-toggle="tooltip" data-title="' . htmlspecialchars($lockInfo['msg']) . '">'
1996 . $this->iconFactory->getIcon('warning-in-use', Icon::SIZE_SMALL)->render() . '</a>';
1997 }
1998 // Call stats information hook
1999 $_params = ['tt_content', $row['uid'], &$row];
2000 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] ?? [] as $_funcRef) {
2001 $additionalIcons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2002 }
2003
2004 // Wrap the whole header
2005 // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
2006 return '<div class="t3-page-ce-header ' . ($allowDragAndDrop ? 't3-page-ce-header-draggable t3js-page-ce-draghandle' : '') . '">
2007 <div class="t3-page-ce-header-icons-left">' . implode('', $additionalIcons) . '</div>
2008 <div class="t3-page-ce-header-icons-right">' . ($out ? '<div class="btn-toolbar">' . $out . '</div>' : '') . '</div>
2009 </div>
2010 <div class="t3-page-ce-body">';
2011 }
2012
2013 /**
2014 * Determine whether Drag & Drop should be allowed
2015 *
2016 * @param array $row
2017 * @return bool
2018 */
2019 protected function isDragAndDropAllowed(array $row)
2020 {
2021 if ($this->getBackendUser()->isAdmin()
2022 || ((int)$row['editlock'] === 0 && (int)$this->pageinfo['editlock'] === 0)
2023 && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
2024 && $this->getBackendUser()->checkAuthMode('tt_content', 'CType', $row['CType'], $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'])
2025 ) {
2026 return true;
2027 }
2028 return false;
2029 }
2030
2031 /**
2032 * Draws the preview content for a content element
2033 *
2034 * @param array $row Content element
2035 * @return string HTML
2036 * @throws \UnexpectedValueException
2037 */
2038 public function tt_content_drawItem($row)
2039 {
2040 $out = '';
2041 $outHeader = '';
2042 // Make header:
2043
2044 if ($row['header']) {
2045 $infoArr = [];
2046 $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
2047 $hiddenHeaderNote = '';
2048 // If header layout is set to 'hidden', display an accordant note:
2049 if ($row['header_layout'] == 100) {
2050 $hiddenHeaderNote = ' <em>[' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.hidden')) . ']</em>';
2051 }
2052 $outHeader = $row['date']
2053 ? htmlspecialchars($this->itemLabels['date'] . ' ' . BackendUtility::date($row['date'])) . '<br />'
2054 : '';
2055 $outHeader .= '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row)
2056 . $hiddenHeaderNote . '</strong><br />';
2057 }
2058 // Make content:
2059 $infoArr = [];
2060 $drawItem = true;
2061 // Hook: Render an own preview of a record
2062 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'] ?? [] as $className) {
2063 $hookObject = GeneralUtility::makeInstance($className);
2064 if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
2065 throw new \UnexpectedValueException($className . ' must implement interface ' . PageLayoutViewDrawItemHookInterface::class, 1218547409);
2066 }
2067 $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
2068 }
2069
2070 // If the previous hook did not render something,
2071 // then check if a Fluid-based preview template was defined for this CType
2072 // and render it via Fluid. Possible option:
2073 // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html
2074 if ($drawItem) {
2075 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod.web_layout.tt_content.preview');
2076 $fluidTemplateFile = '';
2077
2078 if (
2079 $row['CType'] === 'list' && !empty($row['list_type'])
2080 && !empty($tsConfig['properties']['list.'][$row['list_type']])
2081 ) {
2082 $fluidTemplateFile = $tsConfig['properties']['list.'][$row['list_type']];
2083 } elseif (!empty($tsConfig['properties'][$row['CType']])) {
2084 $fluidTemplateFile = $tsConfig['properties'][$row['CType']];
2085 }
2086
2087 if ($fluidTemplateFile) {
2088 $fluidTemplateFile = GeneralUtility::getFileAbsFileName($fluidTemplateFile);
2089 if ($fluidTemplateFile) {
2090 try {
2091 /** @var StandaloneView $view */
2092 $view = GeneralUtility::makeInstance(StandaloneView::class);
2093 $view->setTemplatePathAndFilename($fluidTemplateFile);
2094 $view->assignMultiple($row);
2095 if (!empty($row['pi_flexform'])) {
2096 /** @var FlexFormService $flexFormService */
2097 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
2098 $view->assign('pi_flexform_transformed', $flexFormService->convertFlexFormContentToArray($row['pi_flexform']));
2099 }
2100 $out = $view->render();
2101 $drawItem = false;
2102 } catch (\Exception $e) {
2103 // Catch any exception to avoid breaking the view
2104 }
2105 }
2106 }
2107 }
2108
2109 // Draw preview of the item depending on its CType (if not disabled by previous hook):
2110 if ($drawItem) {
2111 switch ($row['CType']) {
2112 case 'header':
2113 if ($row['subheader']) {
2114 $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
2115 }
2116 break;
2117 case 'bullets':
2118 case 'table':
2119 if ($row['bodytext']) {
2120 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
2121 }
2122 break;
2123 case 'uploads':
2124 if ($row['media']) {
2125 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'media'), $row) . '<br />';
2126 }
2127 break;
2128 case 'menu':
2129 $contentType = $this->CType_labels[$row['CType']];
2130 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
2131 // Add Menu Type
2132 $menuTypeLabel = $this->getLanguageService()->sL(
2133 BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'menu_type', $row['menu_type'])
2134 );
2135 $menuTypeLabel = $menuTypeLabel ?: 'invalid menu type';
2136 $out .= $this->linkEditContent($menuTypeLabel, $row);
2137 if ($row['menu_type'] !== '2' && ($row['pages'] || $row['selected_categories'])) {
2138 // Show pages if menu type is not "Sitemap"
2139 $out .= ':' . $this->linkEditContent($this->generateListForCTypeMenu($row), $row) . '<br />';
2140 }
2141 break;
2142 case 'shortcut':
2143 if (!empty($row['records'])) {
2144 $shortcutContent = [];
2145 $recordList = explode(',', $row['records']);
2146 foreach ($recordList as $recordIdentifier) {
2147 $split = BackendUtility::splitTable_Uid($recordIdentifier);
2148 $tableName = empty($split[0]) ? 'tt_content' : $split[0];
2149 $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]);
2150 if (is_array($shortcutRecord)) {
2151 $icon = $this->iconFactory->getIconForRecord($tableName, $shortcutRecord, Icon::SIZE_SMALL)->render();
2152 $icon = BackendUtility::wrapClickMenuOnIcon(
2153 $icon,
2154 $tableName,
2155 $shortcutRecord['uid']
2156 );
2157 $shortcutContent[] = $icon
2158 . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord));
2159 }
2160 }
2161 $out .= implode('<br />', $shortcutContent) . '<br />';
2162 }
2163 break;
2164 case 'list':
2165 $hookOut = '';
2166 $_params = ['pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr];
2167 foreach (
2168 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']] ??
2169 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'] ??
2170 [] as $_funcRef
2171 ) {
2172 $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2173 }
2174 if ((string)$hookOut !== '') {
2175 $out .= $hookOut;
2176 } elseif (!empty($row['list_type'])) {
2177 $label = BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'list_type', $row['list_type']);
2178 if (!empty($label)) {
2179 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($this->getLanguageService()->sL($label)) . '</strong>', $row) . '<br />';
2180 } else {
2181 $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'), $row['list_type']);
2182 $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>';
2183 }
2184 } else {
2185 $out .= '<strong>' . $this->getLanguageService()->getLL('noPluginSelected') . '</strong>';
2186 }
2187 $out .= htmlspecialchars($this->getLanguageService()->sL(
2188 BackendUtility::getLabelFromItemlist('tt_content', 'pages', $row['pages'])
2189 )) . '<br />';
2190 break;
2191 default:
2192 $contentType = $this->CType_labels[$row['CType']];
2193
2194 if (isset($contentType)) {
2195 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
2196 if ($row['bodytext']) {
2197 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
2198 }
2199 if ($row['image']) {
2200 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'image'), $row) . '<br />';
2201 }
2202 } else {
2203 $message = sprintf(
2204 $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'),
2205 $row['CType']
2206 );
2207 $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>';
2208 }
2209 }
2210 }
2211 // Wrap span-tags:
2212 $out = '
2213 <span class="exampleContent">' . $out . '</span>';
2214 // Add header:
2215 $out = $outHeader . $out;
2216 // Return values:
2217 if ($this->isDisabled('tt_content', $row)) {
2218 return '<span class="text-muted">' . $out . '</span>';
2219 }
2220 return $out;
2221 }
2222
2223 /**
2224 * Generates a list of selected pages or categories for the CType menu
2225 *
2226 * @param array $row row from pages
2227 * @return string
2228 */
2229 protected function generateListForCTypeMenu(array $row)
2230 {
2231 $table = 'pages';
2232 $field = 'pages';
2233 // get categories instead of pages
2234 if (strpos($row['menu_type'], 'categorized_') !== false) {
2235 $table = 'sys_category';
2236 $field = 'selected_categories';
2237 }
2238 if (trim($row[$field]) === '') {
2239 return '';
2240 }
2241 $content = '';
2242 $uidList = explode(',', $row[$field]);
2243 foreach ($uidList as $uid) {
2244 $uid = (int)$uid;
2245 $record = BackendUtility::getRecord($table, $uid, 'title');
2246 $content .= '<br>' . $record['title'] . ' (' . $uid . ')';
2247 }
2248 return $content;
2249 }
2250
2251 /**
2252 * Filters out all tt_content uids which are already translated so only non-translated uids is left.
2253 * Selects across columns, but within in the same PID. Columns are expect to be the same
2254 * for translations and original but this may be a conceptual error (?)
2255 *
2256 * @param array $defaultLanguageUids Numeric array with uids of tt_content elements in the default language
2257 * @param int $id Page pid
2258 * @param int $lP Sys language UID
2259 * @return array Modified $defLanguageCount
2260 */
2261 public function getNonTranslatedTTcontentUids($defaultLanguageUids, $id, $lP)
2262 {
2263 if ($lP && !empty($defaultLanguageUids)) {
2264 // Select all translations here:
2265 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
2266 ->getQueryBuilderForTable('tt_content');
2267 $queryBuilder->getRestrictions()
2268 ->removeAll()
2269 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2270 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class, null, false));
2271 $queryBuilder
2272 ->select('*')
2273 ->from('tt_content')
2274 ->where(
2275 $queryBuilder->expr()->eq(
2276 'sys_language_uid',
2277 $queryBuilder->createNamedParameter($lP, \PDO::PARAM_INT)
2278 ),
2279 $queryBuilder->expr()->in(
2280 'l18n_parent',
2281 $queryBuilder->createNamedParameter($defaultLanguageUids, Connection::PARAM_INT_ARRAY)
2282 )
2283 );
2284
2285 $result = $queryBuilder->execute();
2286
2287 // Flip uids:
2288 $defaultLanguageUids = array_flip($defaultLanguageUids);
2289 // Traverse any selected elements and unset original UID if any:
2290 while ($row = $result->fetch()) {
2291 BackendUtility::workspaceOL('tt_content', $row);
2292 unset($defaultLanguageUids[$row['l18n_parent']]);
2293 }
2294 // Flip again:
2295 $defaultLanguageUids = array_keys($defaultLanguageUids);
2296 }
2297 return $defaultLanguageUids;
2298 }
2299
2300 /**
2301 * Creates button which is used to create copies of records..
2302 *
2303 * @param array $defaultLanguageUids Numeric array with uids of tt_content elements in the default language
2304 * @param int $lP Sys language UID
2305 * @param int $colPos Column position
2306 * @return string "Copy languages" button, if available.
2307 */
2308 public function newLanguageButton($defaultLanguageUids, $lP, $colPos = 0)
2309 {
2310 $lP = (int)$lP;
2311 if (!$this->doEdit || !$lP) {
2312 return '';
2313 }
2314 $theNewButton = '';
2315
2316 $localizationTsConfig = BackendUtility::getModTSconfig($this->id, 'mod.web_layout.localization');
2317 $allowCopy = isset($localizationTsConfig['properties']['enableCopy'])
2318 ? (int)$localizationTsConfig['properties']['enableCopy'] === 1
2319 : true;
2320 $allowTranslate = isset($localizationTsConfig['properties']['enableTranslate'])
2321 ? (int)$localizationTsConfig['properties']['enableTranslate'] === 1
2322 : true;
2323
2324 if (!empty($this->languageHasTranslationsCache[$lP])) {
2325 if (isset($this->languageHasTranslationsCache[$lP]['hasStandAloneContent'])) {
2326 $allowTranslate = false;
2327 }
2328 if (isset($this->languageHasTranslationsCache[$lP]['hasTranslations'])) {
2329 $allowCopy = false;
2330 }
2331 }
2332
2333 if (isset($this->contentElementCache[$lP][$colPos]) && is_array($this->contentElementCache[$lP][$colPos])) {
2334 foreach ($this->contentElementCache[$lP][$colPos] as $record) {
2335 $key = array_search($record['l10n_source'], $defaultLanguageUids);
2336 if ($key !== false) {
2337 unset($defaultLanguageUids[$key]);
2338 }
2339 }
2340 }
2341
2342 if (!empty($defaultLanguageUids)) {
2343 $theNewButton =
2344 '<input'
2345 . ' class="btn btn-default t3js-localize"'
2346 . ' type="button"'
2347 . ' disabled'
2348 . ' value="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_translate')) . '"'
2349 . ' data-has-elements="' . (int)!empty($this->contentElementCache[$lP][$colPos]) . '"'
2350 . ' data-allow-copy="' . (int)$allowCopy . '"'
2351 . ' data-allow-translate="' . (int)$allowTranslate . '"'
2352 . ' data-table="tt_content"'
2353 . ' data-page-id="' . (int)GeneralUtility::_GP('id') . '"'
2354 . ' data-language-id="' . $lP . '"'
2355 . ' data-language-name="' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '"'
2356 . ' data-colpos-id="' . $colPos . '"'
2357 . ' data-colpos-name="' . BackendUtility::getProcessedValue('tt_content', 'colPos', $colPos) . '"'
2358 . '/>';
2359 }
2360
2361 return '<div class="t3-page-lang-copyce">' . $theNewButton . '</div>';
2362 }
2363
2364 /**
2365 * Creates onclick-attribute content for a new content element
2366 *
2367 * @param int $id Page id where to create the element.
2368 * @param int $colPos Preset: Column position value
2369 * @param int $sys_language Preset: Sys langauge value
2370 * @return string String for onclick attribute.
2371 * @see getTable_tt_content()
2372 */
2373 public function newContentElementOnClick($id, $colPos, $sys_language)
2374 {
2375 if ($this->option_newWizard) {
2376 $tsConfig = BackendUtility::getModTSconfig($id, 'mod');
2377 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
2378 ? $tsConfig['properties']['newContentElementWizard.']['override']
2379 : 'new_content_element_wizard';
2380 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl($moduleName) . '&id=' . $id . '&colPos=' . $colPos
2381 . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id
2382 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
2383 } else {
2384 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]='
2385 . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language);
2386 }
2387 return $onClick;
2388 }
2389
2390 /**
2391 * Will create a link on the input string and possibly a big button after the string which links to editing in the RTE.
2392 * Used for content element content displayed so the user can click the content / "Edit in Rich Text Editor" button
2393 *
2394 * @param string $str String to link. Must be prepared for HTML output.
2395 * @param array $row The row.
2396 * @return string If the whole thing was editable ($this->doEdit) $str is return with link around. Otherwise just $str.
2397 * @see getTable_tt_content()
2398 */
2399 public function linkEditContent($str, $row)
2400 {
2401 if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
2402 $urlParameters = [
2403 'edit' => [
2404 'tt_content' => [
2405 $row['uid'] => 'edit'
2406 ]
2407 ],
2408 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid']
2409 ];
2410 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
2411 // Return link
2412 return '<a href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">' . $str . '</a>';
2413 }
2414 return $str;
2415 }
2416
2417 /**
2418 * Make selector box for creating new translation in a language
2419 * Displays only languages which are not yet present for the current page and
2420 * that are not disabled with page TS.
2421 *
2422 * @param int $id Page id for which to create a new translation record of pages
2423 * @return string <select> HTML element (if there were items for the box anyways...)
2424 * @see getTable_tt_content()
2425 */
2426 public function languageSelector($id)
2427 {
2428 if ($this->getBackendUser()->check('tables_modify', 'pages')) {
2429 // First, select all
2430 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
2431 $queryBuilder->getRestrictions()->removeAll();
2432 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
2433 $statement = $queryBuilder->select('uid', 'title')
2434 ->from('sys_language')
2435 ->orderBy('sorting')
2436 ->execute();
2437 $availableTranslations = [];
2438 while ($row = $statement->fetch()) {
2439 if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
2440 $availableTranslations[(int)$row['uid']] = $row['title'];
2441 }
2442 }
2443 // Then, subtract the languages which are already on the page:
2444 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
2445 $queryBuilder->getRestrictions()->removeAll();
2446 $queryBuilder->select('sys_language.uid AS uid', 'sys_language.title AS title')
2447 ->from('sys_language')
2448 ->join(
2449 'sys_language',
2450 'pages',
2451 'pages',
2452 $queryBuilder->expr()->eq('sys_language.uid', $queryBuilder->quoteIdentifier('pages.' . $GLOBALS['TCA']['pages']['ctrl']['languageField']))
2453 )
2454 ->where(
2455 $queryBuilder->expr()->eq(
2456 'pages.deleted',
2457 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
2458 ),
2459 $queryBuilder->expr()->eq(
2460 'pages.' . $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
2461 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
2462 ),
2463 $queryBuilder->expr()->orX(
2464 $queryBuilder->expr()->gte(
2465 'pages.t3ver_state',
2466 $queryBuilder->createNamedParameter(
2467 (string)new VersionState(VersionState::DEFAULT_STATE),
2468 \PDO::PARAM_INT
2469 )
2470 ),
2471 $queryBuilder->expr()->eq(
2472 'pages.t3ver_wsid',
2473 $queryBuilder->createNamedParameter($this->getBackendUser()->workspace, \PDO::PARAM_INT)
2474 )
2475 )
2476 )
2477 ->groupBy(
2478 'pages.' . $GLOBALS['TCA']['pages']['ctrl']['languageField'],
2479 'sys_language.uid',
2480 'sys_language.pid',
2481 'sys_language.tstamp',
2482 'sys_language.hidden',
2483 'sys_language.title',
2484 'sys_language.language_isocode',
2485 'sys_language.static_lang_isocode',
2486 'sys_language.flag',
2487 'sys_language.sorting'
2488 )
2489 ->orderBy('sys_language.sorting');
2490 if (!$this->getBackendUser()->isAdmin()) {
2491 $queryBuilder->andWhere(
2492 $queryBuilder->expr()->eq(
2493 'sys_language.hidden',
2494 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
2495 )
2496 );
2497 }
2498 $statement = $queryBuilder->execute();
2499 while ($row = $statement->fetch()) {
2500 unset($availableTranslations[(int)$row['uid']]);
2501 }
2502 // Remove disallowed languages
2503 if (!empty($availableTranslations)
2504 && !$this->getBackendUser()->isAdmin()
2505 && $this->getBackendUser()->groupData['allowed_languages'] !== ''
2506 ) {
2507 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
2508 if (!empty($allowed_languages)) {
2509 foreach ($availableTranslations as $key => $value) {
2510 if (!isset($allowed_languages[$key]) && $key != 0) {
2511 unset($availableTranslations[$key]);
2512 }
2513 }
2514 }
2515 }
2516 // Remove disabled languages
2517 $modSharedTSconfig = BackendUtility::getModTSconfig($id, 'mod.SHARED');
2518 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
2519 ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true)
2520 : [];
2521 if (!empty($availableTranslations) && !empty($disableLanguages)) {
2522 foreach ($disableLanguages as $language) {
2523 if ($language != 0 && isset($availableTranslations[$language])) {
2524 unset($availableTranslations[$language]);
2525 }
2526 }
2527 }
2528 // If any languages are left, make selector:
2529 if (!empty($availableTranslations)) {
2530 $output = '<option value=""></option>';
2531 foreach ($availableTranslations as $languageUid => $languageTitle) {
2532 // Build localize command URL to DataHandler (tce_db)
2533 // which redirects to FormEngine (record_edit)
2534 // which, when finished editing should return back to the current page (returnUrl)
2535 $parameters = [
2536 'justLocalized' => 'pages:' . $id . ':' . $languageUid,
2537 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
2538 ];
2539 $redirectUrl = BackendUtility::getModuleUrl('record_edit', $parameters);
2540 $targetUrl = BackendUtility::getLinkToDataHandlerAction(
2541 '&cmd[pages][' . $id . '][localize]=' . $languageUid,
2542 $redirectUrl
2543 );
2544
2545 $output .= '<option value="' . htmlspecialchars($targetUrl) . '">' . htmlspecialchars($languageTitle) . '</option>';
2546 }
2547
2548 return '<div class="form-inline form-inline-spaced">'
2549 . '<div class="form-group">'
2550 . '<label for="createNewLanguage">'
2551 . htmlspecialchars($this->getLanguageService()->getLL('new_language'))
2552 . '</label>'
2553 . '<select class="form-control input-sm" name="createNewLanguage" onchange="window.location.href=this.options[this.selectedIndex].value">'
2554 . $output
2555 . '</select></div></div>';
2556 }
2557 }
2558 return '';
2559 }
2560
2561 /**
2562 * Traverse the result pointer given, adding each record to array and setting some internal values at the same time.
2563 *
2564 * @param Statement $result DBAL Statement
2565 * @param string $table Table name defaulting to tt_content
2566 * @return array The selected rows returned in this array.
2567 */
2568 public function getResult(Statement $result, string $table = 'tt_content'): array
2569 {
2570 $output = [];
2571 // Traverse the result:
2572 while ($row = $result->fetch()) {
2573 BackendUtility::workspaceOL($table, $row, -99, true);
2574 if ($row) {
2575 // Add the row to the array:
2576 $output[] = $row;
2577 }
2578 }
2579 $this->generateTtContentDataArray($output);
2580 // Return selected records
2581 return $output;
2582 }
2583
2584 /********************************
2585 *
2586 * Various helper functions
2587 *
2588 ********************************/
2589
2590 /**
2591 * Initializes the clipboard for generating paste links
2592 *
2593 *
2594 * @see \TYPO3\CMS\Recordlist\RecordList::main()
2595 * @see \TYPO3\CMS\Backend\Controller\ContextMenuController::clipboardAction()
2596 * @see \TYPO3\CMS\Filelist\Controller\FileListController::indexAction()
2597 */
2598 protected function initializeClipboard()
2599 {
2600 // Start clipboard
2601 $this->clipboard = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
2602
2603 // Initialize - reads the clipboard content from the user session
2604 $this->clipboard->initializeClipboard();
2605
2606 // This locks the clipboard to the Normal for this request.
2607 $this->clipboard->lockToNormal();
2608
2609 // Clean up pad
2610 $this->clipboard->cleanCurrent();
2611
2612 // Save the clipboard content
2613 $this->clipboard->endClipboard();
2614 }
2615
2616 /**
2617 * Generates the data for previous and next elements which is needed for movements.
2618 *
2619 * @param array $rowArray
2620 */
2621 protected function generateTtContentDataArray(array $rowArray)
2622 {
2623 if (empty($this->tt_contentData)) {
2624 $this->tt_contentData = [
2625 'nextThree' => [],
2626 'next' => [],
2627 'prev' => [],
2628 ];
2629 }
2630 foreach ($rowArray as $key => $value) {
2631 // Create the list of the next three ids (for editing links...)
2632 for ($i = 0; $i < $this->nextThree; $i++) {
2633 if (isset($rowArray[$key - $i])
2634 && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
2635 ) {
2636 $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
2637 }
2638 }
2639
2640 // Create information for next and previous content elements
2641 if (isset($rowArray[$key - 1])) {
2642 if (isset($rowArray[$key - 2])) {
2643 $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
2644 } else {
2645 $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
2646 }
2647 $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
2648 }
2649 }
2650 }
2651
2652 /**
2653 * Counts and returns the number of records on the page with $pid
2654 *
2655 * @param string $table Table name
2656 * @param int $pid Page id
2657 * @return int Number of records.
2658 */
2659 public function numberOfRecords($table, $pid)
2660 {
2661 $count = 0;
2662 if ($GLOBALS['TCA'][$table]) {
2663 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
2664 ->getQueryBuilderForTable($table);
2665 $queryBuilder->getRestrictions()
2666 ->removeAll()
2667 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2668 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
2669 $count = (int)$queryBuilder->count('uid')
2670 ->from($table)
2671 ->where(
2672 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT))
2673 )
2674 ->execute()
2675 ->fetchColumn();
2676 }
2677
2678 return $count;
2679 }
2680
2681 /**
2682 * Processing of larger amounts of text (usually from RTE/bodytext fields) with word wrapping etc.
2683 *
2684 * @param string $input Input string
2685 * @return string Output string
2686 */
2687 public function renderText($input)
2688 {
2689 $input = strip_tags($input);
2690 $input = GeneralUtility::fixed_lgd_cs($input, 1500);
2691 return nl2br(htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8', false));
2692 }
2693
2694 /**
2695 * Creates the icon image tag for record from table and wraps it in a link which will trigger the click menu.
2696 *
2697 * @param string $table Table name
2698 * @param array $row Record array
2699 * @param string $enabledClickMenuItems Passthrough to wrapClickMenuOnIcon
2700 * @return string HTML for the icon
2701 */
2702 public function getIcon($table, $row, $enabledClickMenuItems = '')
2703 {
2704 // Initialization
2705 $toolTip = BackendUtility::getRecordToolTip($row, 'tt_content');
2706 $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
2707 $this->counter++;
2708 // The icon with link
2709 if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) {
2710 $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid']);
2711 }
2712 return $icon;
2713 }
2714
2715 /**
2716 * Creates processed values for all field names in $fieldList based on values from $row array.
2717 * The result is 'returned' through $info which is passed as a reference
2718 *
2719 * @param string $table Table name
2720 * @param string $fieldList Comma separated list of fields.
2721 * @param array $row Record from which to take values for processing.
2722 * @param array $info Array to which the processed values are added.
2723 */
2724 public function getProcessedValue($table, $fieldList, array $row, array &$info)
2725 {
2726 // Splitting values from $fieldList
2727 $fieldArr = explode(',', $fieldList);
2728 // Traverse fields from $fieldList
2729 foreach ($fieldArr as $field) {
2730 if ($row[$field]) {
2731 $info[] = '<strong>' . htmlspecialchars($this->itemLabels[$field]) . '</strong> '
2732 . htmlspecialchars(BackendUtility::getProcessedValue($table, $field, $row[$field]));
2733 }
2734 }
2735 }
2736
2737 /**
2738 * Returns TRUE, if the record given as parameters is NOT visible based on hidden/starttime/endtime (if available)
2739 *
2740 * @param string $table Tablename of table to test
2741 * @param array $row Record row.
2742 * @return bool Returns TRUE, if disabled.
2743 */
2744 public function isDisabled($table, $row)
2745 {
2746 $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
2747 return $enableCols['disabled'] && $row[$enableCols['disabled']]
2748 || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME']
2749 || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME'];
2750 }
2751
2752 /**
2753 * Returns icon for "no-edit" of a record.
2754 * Basically, the point is to signal that this record could have had an edit link if
2755 * the circumstances were right. A placeholder for the regular edit icon...
2756 *
2757 * @param string $label Label key from LOCAL_LANG
2758 * @return string IMG tag for icon.
2759 */
2760 public function noEditIcon($label = 'noEditItems')
2761 {
2762 $title = htmlspecialchars($this->getLanguageService()->getLL($label));
2763 return '<span title="' . $title . '">' . $this->iconFactory->getIcon('status-edit-read-only', Icon::SIZE_SMALL)->render() . '</span>';
2764 }
2765
2766 /*****************************************
2767 *
2768 * External renderings
2769 *
2770 *****************************************/
2771
2772 /**
2773 * Creates a menu of the tables that can be listed by this function
2774 * Only tables which has records on the page will be included.
2775 * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
2776 *
2777 * @param int $id Page id from which we are listing records (the function will look up if there are records on the page)
2778 * @return string HTML output.
2779 */
2780 public function getTableMenu($id)
2781 {
2782 // Initialize:
2783 $this->activeTables = [];
2784 $theTables = ['tt_content'];
2785 // External tables:
2786 if (is_array($this->externalTables)) {
2787 $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2788 }
2789 $out = '';
2790 // Traverse tables to check:
2791 foreach ($theTables as $tName) {
2792 // Check access and whether the proper extensions are loaded:
2793 if ($this->getBackendUser()->check('tables_select', $tName)
2794 && (
2795 isset($this->externalTables[$tName])
2796 || $tName === 'fe_users' || $tName === 'tt_content'
2797 || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName)
2798 )
2799 ) {
2800 // Make query to count records from page:
2801 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
2802 ->getQueryBuilderForTable($tName);
2803 $queryBuilder->getRestrictions()
2804 ->removeAll()
2805 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2806 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
2807 $count = $queryBuilder->count('uid')
2808 ->from($tName)
2809 ->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)))
2810 ->execute()
2811 ->fetchColumn();
2812 // If records were found (or if "tt_content" is the table...):
2813 if ($count || $tName === 'tt_content') {
2814 // Add row to menu:
2815 $out .= '
2816 <td><a href="#' . $tName . '" title="' . htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'])) . '"></a>'
2817 . $this->iconFactory->getIconForRecord($tName, [], Icon::SIZE_SMALL)->render()
2818 . '</td>';
2819 // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2820 $title = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title']))
2821 . ': ' . $count . ' ' . htmlspecialchars($this->getLanguageService()->getLL('records'));
2822 $this->activeTables[$tName] = '<span title="' . $title . '">'
2823 . $this->iconFactory->getIconForRecord($tName, [], Icon::SIZE_SMALL)->render()
2824 . '</span>'
2825 . '&nbsp;' . htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title']));
2826 }
2827 }
2828 }
2829 // Wrap cells in table tags:
2830 $out = '
2831 <!--
2832 Menu of tables on the page (table menu)
2833 -->
2834 <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
2835 <tr>' . $out . '
2836 </tr>
2837 </table>';
2838 // Return the content:
2839 return $out;
2840 }
2841
2842 /**
2843 * Create thumbnail code for record/field but not linked
2844 *
2845 * @param mixed[] $row Record array
2846 * @param string $table Table (record is from)
2847 * @param string $field Field name for which thumbnail are to be rendered.
2848 * @return string HTML for thumbnails, if any.
2849 */
2850 public function getThumbCodeUnlinked($row, $table, $field)
2851 {
2852 return BackendUtility::thumbCode($row, $table, $field, '', '', null, 0, '', '', false);
2853 }
2854
2855 /**
2856 * Checks whether translated Content Elements exist in the desired language
2857 * If so, deny creating new ones via the UI
2858 *
2859 * @param array $contentElements
2860 * @param int $language
2861 * @return bool
2862 */
2863 protected function checkIfTranslationsExistInLanguage(array $contentElements, $language)
2864 {
2865 // If in default language, you may always create new entries
2866 // Also, you may override this strict behavior via user TS Config
2867 // If you do so, you're on your own and cannot rely on any support by the TYPO3 core
2868 // We jump out here since we don't need to do the expensive loop operations
2869 $allowInconsistentLanguageHandling = BackendUtility::getModTSconfig($this->id, 'mod.web_layout.allowInconsistentLanguageHandling');
2870 if ($language === 0 || $allowInconsistentLanguageHandling['value'] === '1') {
2871 return false;
2872 }
2873 /**
2874 * Build up caches
2875 */
2876 if (!isset($this->languageHasTranslationsCache[$language])) {
2877 foreach ($contentElements as $columns) {
2878 foreach ($columns as $contentElement) {
2879 if ((int)$contentElement['l18n_parent'] === 0) {
2880 $this->languageHasTranslationsCache[$language]['hasStandAloneContent'] = true;
2881 }
2882 if ((int)$contentElement['l18n_parent'] > 0) {
2883 $this->languageHasTranslationsCache[$language]['hasTranslations'] = true;
2884 }
2885 }
2886 }
2887 // Check whether we have a mix of both
2888 if ($this->languageHasTranslationsCache[$language]['hasStandAloneContent']
2889 && $this->languageHasTranslationsCache[$language]['hasTranslations']
2890 ) {
2891 $message = GeneralUtility::makeInstance(
2892 FlashMessage::class,
2893 sprintf($this->getLanguageService()->getLL('staleTranslationWarning'), $this->languageIconTitles[$language]['title']),
2894 sprintf($this->getLanguageService()->getLL('staleTranslationWarningTitle'), $this->languageIconTitles[$language]['title']),
2895 FlashMessage::WARNING
2896 );
2897 $service = GeneralUtility::makeInstance(FlashMessageService::class);
2898 $queue = $service->getMessageQueueByIdentifier();
2899 $queue->addMessage($message);
2900 }
2901 }
2902 if ($this->languageHasTranslationsCache[$language]['hasTranslations']) {
2903 return true;
2904 }
2905 return false;
2906 }
2907
2908 /**
2909 * @return BackendLayoutView
2910 */
2911 protected function getBackendLayoutView()