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