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