‪TYPO3CMS  11.5
GridColumnItem.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
30 
44 {
48  protected ‪$record = [];
49 
53  protected ‪$column;
54 
58  protected ‪$translations = [];
59 
61  {
62  parent::__construct(‪$context);
63  $this->column = ‪$column;
64  $this->record = ‪$record;
65  }
66 
67  public function ‪isVersioned(): bool
68  {
69  return ($this->record['_ORIG_uid'] ?? 0) > 0 || (int)($this->record['t3ver_state'] ?? 0) !== 0;
70  }
71 
72  public function ‪getPreview(): string
73  {
74  ‪$record = $this->‪getRecord();
75  $previewRenderer = GeneralUtility::makeInstance(StandardPreviewRendererResolver::class)
76  ->resolveRendererFor(
77  'tt_content',
78  ‪$record,
79  $this->context->getPageId()
80  );
81  $previewHeader = $previewRenderer->renderPageModulePreviewHeader($this);
82 
83  $drawItem = true;
84  $previewContent = '';
85  // Hook: Render an own preview of a record
86  if (!empty(‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'])) {
88  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'] ?? [] as $className) {
89  $hookObject = GeneralUtility::makeInstance($className);
90  if (!$hookObject instanceof ‪PageLayoutViewDrawItemHookInterface) {
91  throw new \UnexpectedValueException($className . ' must implement interface ' . PageLayoutViewDrawItemHookInterface::class, 1582574553);
92  }
93  $hookObject->preProcess($pageLayoutView, $drawItem, $previewHeader, $previewContent, ‪$record);
94  }
95  $this->‪setRecord($record);
96  }
97 
98  if ($drawItem) {
99  $previewContent = $previewRenderer->renderPageModulePreviewContent($this);
100  }
101 
102  return $previewRenderer->wrapPageModulePreview($previewHeader, $previewContent, $this);
103  }
104 
105  public function ‪getWrapperClassName(): string
106  {
107  $wrapperClassNames = [];
108  if ($this->‪isDisabled()) {
109  $wrapperClassNames[] = 't3-page-ce-hidden t3js-hidden-record';
110  }
111  if ($this->‪isInconsistentLanguage()) {
112  $wrapperClassNames[] = 't3-page-ce-warning';
113  }
114 
115  return implode(' ', $wrapperClassNames);
116  }
117 
118  public function ‪isDelible(): bool
119  {
120  $backendUser = $this->‪getBackendUser();
121  if (!$backendUser->doesUserHaveAccess($this->context->getPageRecord(), ‪Permission::CONTENT_EDIT)) {
122  return false;
123  }
124  return !(bool)($backendUser->getTSConfig()['options.']['disableDelete.']['tt_content'] ?? $backendUser->getTSConfig()['options.']['disableDelete'] ?? false);
125  }
126 
127  public function ‪getDeleteUrl(): string
128  {
129  $params = '&cmd[tt_content][' . $this->record['uid'] . '][delete]=1';
130  return BackendUtility::getLinkToDataHandlerAction($params);
131  }
132 
133  public function ‪getDeleteMessage(): string
134  {
135  $refCountMsg = BackendUtility::referenceCount(
136  'tt_content',
137  $this->record['uid'],
138  LF . $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.referencesToRecord')
139  ) . BackendUtility::translationCount(
140  'tt_content',
141  $this->record['uid'],
142  LF . $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.translationsOfRecord')
143  );
144 
145  return $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:deleteWarning') . $refCountMsg;
146  }
147 
148  public function ‪getFooterInfo(): string
149  {
150  ‪$record = $this->‪getRecord();
151  $previewRenderer = GeneralUtility::makeInstance(StandardPreviewRendererResolver::class)
152  ->resolveRendererFor(
153  'tt_content',
154  ‪$record,
155  $this->context->getPageId()
156  );
157  return $previewRenderer->renderPageModulePreviewFooter($this);
158  }
159 
160  public function ‪getIcons(): string
161  {
162  $table = 'tt_content';
163  $row = ‪$this->record;
164  $icons = [];
165 
166  $toolTip = BackendUtility::getRecordToolTip($row, $table);
167  $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord($table, $row, ‪Icon::SIZE_SMALL)->render() . '</span>';
168  if ($this->‪getBackendUser()->recordEditAccessInternals($table, $row)) {
169  $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid']);
170  }
171  $icons[] = $icon;
172 
173  if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
174  $icons[] = '<a href="#" data-bs-toggle="tooltip" title="' . htmlspecialchars($lockInfo['msg']) . '">'
175  . $this->iconFactory->getIcon('warning-in-use', ‪Icon::SIZE_SMALL)->render() . '</a>';
176  }
177 
178  $_params = ['tt_content', $row['uid'], &$row];
179  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] ?? [] as $_funcRef) {
180  $icons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
181  }
182  return implode(' ', $icons);
183  }
184 
185  public function ‪getSiteLanguage(): ‪SiteLanguage
186  {
187  return $this->context->getSiteLanguage((int)$this->‪getRecord()['sys_language_uid']);
188  }
189 
190  public function ‪getRecord(): array
191  {
193  }
194 
195  public function ‪setRecord(array ‪$record): void
196  {
197  $this->record = ‪$record;
198  }
199 
200  public function ‪getColumn(): ‪GridColumn
201  {
203  }
204 
205  public function ‪getTranslations(): array
206  {
208  }
209 
210  public function ‪addTranslation(int $languageId, ‪GridColumnItem $translation): ‪GridColumnItem
211  {
212  $this->translations[$languageId] = $translation;
213  return $this;
214  }
215 
216  public function ‪isDisabled(): bool
217  {
218  $table = 'tt_content';
219  $row = $this->‪getRecord();
220  $enableCols = ‪$GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
221  return $enableCols['disabled'] && $row[$enableCols['disabled']]
222  || $enableCols['starttime'] && $row[$enableCols['starttime']] > ‪$GLOBALS['EXEC_TIME']
223  || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < ‪$GLOBALS['EXEC_TIME'];
224  }
225 
226  public function ‪isEditable(): bool
227  {
228  $backendUser = $this->‪getBackendUser();
229  if ($backendUser->isAdmin()) {
230  return true;
231  }
232  $pageRecord = $this->context->getPageRecord();
233  return !(bool)($pageRecord['editlock'] ?? false)
234  && $backendUser->doesUserHaveAccess($pageRecord, ‪Permission::CONTENT_EDIT)
235  && $backendUser->recordEditAccessInternals('tt_content', $this->record);
236  }
237 
238  public function ‪isDragAndDropAllowed(): bool
239  {
240  $pageRecord = $this->context->getPageRecord();
241  return (int)$this->record['l18n_parent'] === 0 &&
242  (
243  $this->‪getBackendUser()->isAdmin()
244  || ((int)$this->record['editlock'] === 0 && (int)$pageRecord['editlock'] === 0)
245  && $this->‪getBackendUser()->doesUserHaveAccess($pageRecord, ‪Permission::CONTENT_EDIT)
246  && $this->‪getBackendUser()->checkAuthMode('tt_content', 'CType', $this->record['CType'], ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'])
247  )
248  ;
249  }
250 
251  protected function ‪isInconsistentLanguage(): bool
252  {
253  $allowInconsistentLanguageHandling = (bool)(BackendUtility::getPagesTSconfig($this->‪getContext()->getPageId())['mod.']['web_layout.']['allowInconsistentLanguageHandling'] ?? false);
254  return !$allowInconsistentLanguageHandling
255  && $this->‪getSiteLanguage()->getLanguageId() !== 0
256  && $this->‪getContext()->getLanguageModeIdentifier() === 'mixed'
257  && (int)$this->record['l18n_parent'] === 0;
258  }
259 
260  public function ‪getNewContentAfterUrl(): string
261  {
262  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
263  $pageId = $this->context->getPageId();
264 
265  if ($this->context->getDrawingConfiguration()->getShowNewContentWizard()) {
266  $urlParameters = [
267  'id' => $pageId,
268  'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId(),
269  'colPos' => $this->column->getColumnNumber(),
270  'uid_pid' => -$this->record['uid'],
271  'returnUrl' => ‪$GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri(),
272  ];
273  $routeName = BackendUtility::getPagesTSconfig($pageId)['mod.']['newContentElementWizard.']['override']
274  ?? 'new_content_element_wizard';
275  } else {
276  $urlParameters = [
277  'edit' => [
278  'tt_content' => [
279  -$this->record['uid'] => 'new',
280  ],
281  ],
282  'returnUrl' => ‪$GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri(),
283  ];
284  $routeName = 'record_edit';
285  }
286 
287  return (string)$uriBuilder->buildUriFromRoute($routeName, $urlParameters);
288  }
289 
290  public function ‪getVisibilityToggleUrl(): string
291  {
292  $hiddenField = ‪$GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
293  if ($this->record[$hiddenField]) {
294  $value = 0;
295  } else {
296  $value = 1;
297  }
298  $params = '&data[tt_content][' . (($this->record['_ORIG_uid'] ?? false) ?: ($this->record['uid'] ?? 0))
299  . '][' . $hiddenField . ']=' . $value;
300  return BackendUtility::getLinkToDataHandlerAction($params) . '#element-tt_content-' . $this->record['uid'];
301  }
302 
303  public function ‪getVisibilityToggleTitle(): string
304  {
305  $hiddenField = ‪$GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
306  return $this->‪getLanguageService()->getLL($this->record[$hiddenField] ? 'unhide' : 'hide');
307  }
308 
309  public function ‪getVisibilityToggleIconName(): string
310  {
311  $hiddenField = ‪$GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
312  return $this->record[$hiddenField] ? 'unhide' : 'hide';
313  }
314 
315  public function ‪isVisibilityToggling(): bool
316  {
317  $hiddenField = ‪$GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
318  return $hiddenField && ‪$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
319  && (
320  !(‪$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude'] ?? false)
321  || $this->‪getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField)
322  )
323  ;
324  }
325 
326  public function ‪getEditUrl(): string
327  {
328  $urlParameters = [
329  'edit' => [
330  'tt_content' => [
331  $this->record['uid'] => 'edit',
332  ],
333  ],
334  'returnUrl' => ‪$GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri() . '#element-tt_content-' . $this->record['uid'],
335  ];
336  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
337  return (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters) . '#element-tt_content-' . $this->record['uid'];
338  }
339 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isVersioned
‪isVersioned()
Definition: GridColumnItem.php:64
‪TYPO3\CMS\Backend\View\PageLayoutView\createFromPageLayoutContext
‪static PageLayoutView createFromPageLayoutContext(PageLayoutContext $context)
Definition: PageLayoutView.php:184
‪TYPO3\CMS\Backend\Preview\StandardPreviewRendererResolver
Definition: StandardPreviewRendererResolver.php:35
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getDeleteMessage
‪getDeleteMessage()
Definition: GridColumnItem.php:130
‪TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
Definition: PageLayoutViewDrawItemHookInterface.php:23
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\getContext
‪getContext()
Definition: AbstractGridObject.php:61
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject
Definition: AbstractGridObject.php:41
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\$record
‪mixed[] $record
Definition: GridColumnItem.php:47
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isVisibilityToggling
‪isVisibilityToggling()
Definition: GridColumnItem.php:312
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getEditUrl
‪getEditUrl()
Definition: GridColumnItem.php:323
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isDelible
‪isDelible()
Definition: GridColumnItem.php:115
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getIcons
‪getIcons()
Definition: GridColumnItem.php:157
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\__construct
‪__construct(PageLayoutContext $context, GridColumn $column, array $record)
Definition: GridColumnItem.php:57
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getFooterInfo
‪getFooterInfo()
Definition: GridColumnItem.php:145
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\setRecord
‪setRecord(array $record)
Definition: GridColumnItem.php:192
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\$context
‪PageLayoutContext $context
Definition: AbstractGridObject.php:44
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getWrapperClassName
‪getWrapperClassName()
Definition: GridColumnItem.php:102
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\$translations
‪GridColumnItem[] $translations
Definition: GridColumnItem.php:55
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getNewContentAfterUrl
‪getNewContentAfterUrl()
Definition: GridColumnItem.php:257
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\addTranslation
‪addTranslation(int $languageId, GridColumnItem $translation)
Definition: GridColumnItem.php:207
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:26
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getRecord
‪getRecord()
Definition: GridColumnItem.php:187
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getVisibilityToggleTitle
‪getVisibilityToggleTitle()
Definition: GridColumnItem.php:300
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getSiteLanguage
‪getSiteLanguage()
Definition: GridColumnItem.php:182
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getPreview
‪getPreview()
Definition: GridColumnItem.php:69
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getVisibilityToggleUrl
‪getVisibilityToggleUrl()
Definition: GridColumnItem.php:287
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\getBackendUser
‪getBackendUser()
Definition: AbstractGridObject.php:71
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getColumn
‪getColumn()
Definition: GridColumnItem.php:197
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getDeleteUrl
‪getDeleteUrl()
Definition: GridColumnItem.php:124
‪TYPO3\CMS\Backend\View\BackendLayout\Grid
Definition: AbstractGridObject.php:18
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn
Definition: GridColumn.php:45
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isEditable
‪isEditable()
Definition: GridColumnItem.php:223
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:55
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\View\PageLayoutContext
Definition: PageLayoutContext.php:43
‪TYPO3\CMS\Backend\View\PageLayoutView
Definition: PageLayoutView.php:58
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getTranslations
‪getTranslations()
Definition: GridColumnItem.php:202
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getVisibilityToggleIconName
‪getVisibilityToggleIconName()
Definition: GridColumnItem.php:306
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem
Definition: GridColumnItem.php:44
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isInconsistentLanguage
‪isInconsistentLanguage()
Definition: GridColumnItem.php:248
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isDragAndDropAllowed
‪isDragAndDropAllowed()
Definition: GridColumnItem.php:235
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\$column
‪GridColumn $column
Definition: GridColumnItem.php:51
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\getLanguageService
‪getLanguageService()
Definition: AbstractGridObject.php:66
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isDisabled
‪isDisabled()
Definition: GridColumnItem.php:213