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