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