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