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