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