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