‪TYPO3CMS  10.4
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 
28 
42 {
46  protected ‪$record = [];
47 
51  protected ‪$column;
52 
56  protected ‪$translations = [];
57 
59  {
60  parent::__construct(‪$context);
61  $this->column = ‪$column;
62  $this->record = ‪$record;
63  }
64 
65  public function ‪isVersioned(): bool
66  {
67  return $this->record['_ORIG_uid'] > 0;
68  }
69 
70  public function ‪getPreview(): string
71  {
72  ‪$record = $this->‪getRecord();
73  $previewRenderer = GeneralUtility::makeInstance(StandardPreviewRendererResolver::class)
74  ->resolveRendererFor(
75  'tt_content',
76  ‪$record,
77  $this->context->getPageId()
78  );
79  $previewHeader = $previewRenderer->renderPageModulePreviewHeader($this);
80  $previewContent = $previewRenderer->renderPageModulePreviewContent($this);
81  return $previewRenderer->wrapPageModulePreview($previewHeader, $previewContent, $this);
82  }
83 
84  public function ‪getWrapperClassName(): string
85  {
86  $wrapperClassNames = [];
87  if ($this->‪isDisabled()) {
88  $wrapperClassNames[] = 't3-page-ce-hidden t3js-hidden-record';
89  } elseif (!in_array($this->record['colPos'], $this->context->getBackendLayout()->getColumnPositionNumbers())) {
90  $wrapperClassNames[] = 't3-page-ce-warning';
91  }
92  if ($this->‪isInconsistentLanguage()) {
93  $wrapperClassNames[] = 't3-page-ce-danger';
94  }
95 
96  return implode(' ', $wrapperClassNames);
97  }
98 
99  public function ‪isDelible(): bool
100  {
101  $backendUser = $this->‪getBackendUser();
102  if (!$backendUser->doesUserHaveAccess($this->context->getPageRecord(), ‪Permission::CONTENT_EDIT)) {
103  return false;
104  }
105  return !(bool)($backendUser->getTSConfig()['options.']['disableDelete.']['tt_content'] ?? $backendUser->getTSConfig()['options.']['disableDelete'] ?? false);
106  }
107 
108  public function ‪getDeleteUrl(): string
109  {
110  $params = '&cmd[tt_content][' . $this->record['uid'] . '][delete]=1';
112  }
113 
114  public function ‪getDeleteTitle(): string
115  {
116  return $this->‪getLanguageService()->getLL('deleteItem');
117  }
118 
119  public function ‪getDeleteConfirmText(): string
120  {
121  return $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.title');
122  }
123 
124  public function ‪getDeleteCancelText(): string
125  {
126  return $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:cancel');
127  }
128 
129  public function ‪getFooterInfo(): string
130  {
131  ‪$record = $this->‪getRecord();
132  $previewRenderer = GeneralUtility::makeInstance(StandardPreviewRendererResolver::class)
133  ->resolveRendererFor(
134  'tt_content',
135  ‪$record,
136  $this->context->getPageId()
137  );
138  return $previewRenderer->renderPageModulePreviewFooter($this);
139  }
140 
147  protected function ‪renderLanguageFlag(‪SiteLanguage $language)
148  {
149  ‪$title = htmlspecialchars($language->‪getTitle());
150  if ($language->‪getFlagIdentifier()) {
151  $icon = $this->iconFactory->getIcon(
152  $language->‪getFlagIdentifier(),
154  )->render();
155  return '<span title="' . ‪$title . '" class="t3js-flag">' . $icon . '</span>&nbsp;<span class="t3js-language-title">' . ‪$title . '</span>';
156  }
157  return ‪$title;
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  $siteLanguage = $this->context->getSiteLanguage((int)$row['sys_language_uid']);
173  if ($siteLanguage instanceof ‪SiteLanguage) {
174  ‪$icons[] = $this->‪renderLanguageFlag($siteLanguage);
175  }
176 
177  if ($lockInfo = ‪BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
178  ‪$icons[] = '<a href="#" data-toggle="tooltip" data-title="' . htmlspecialchars($lockInfo['msg']) . '">'
179  . $this->iconFactory->getIcon('warning-in-use', ‪Icon::SIZE_SMALL)->render() . '</a>';
180  }
181 
182  $_params = ['tt_content', $row['uid'], &$row];
183  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] ?? [] as $_funcRef) {
184  ‪$icons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
185  }
186  return implode(' ', ‪$icons);
187  }
188 
189  public function ‪getRecord(): array
190  {
192  }
193 
194  public function ‪setRecord(array ‪$record): void
195  {
196  $this->record = ‪$record;
197  }
198 
199  public function ‪getColumn(): ‪GridColumn
200  {
202  }
203 
204  public function ‪getTranslations(): array
205  {
207  }
208 
209  public function ‪addTranslation(int $languageId, ‪GridColumnItem $translation): ‪GridColumnItem
210  {
211  $this->translations[$languageId] = $translation;
212  return $this;
213  }
214 
215  public function ‪isDisabled(): bool
216  {
217  $table = 'tt_content';
218  $row = $this->‪getRecord();
219  $enableCols = ‪$GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
220  return $enableCols['disabled'] && $row[$enableCols['disabled']]
221  || $enableCols['starttime'] && $row[$enableCols['starttime']] > ‪$GLOBALS['EXEC_TIME']
222  || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < ‪$GLOBALS['EXEC_TIME'];
223  }
224 
225  public function ‪isEditable(): bool
226  {
227  $backendUser = $this->‪getBackendUser();
228  if ($backendUser->isAdmin()) {
229  return true;
230  }
231  $pageRecord = $this->context->getPageRecord();
232  return !(bool)($pageRecord['editlock'] ?? false)
233  && $backendUser->doesUserHaveAccess($pageRecord, ‪Permission::CONTENT_EDIT)
234  && $backendUser->recordEditAccessInternals('tt_content', $this->record);
235  }
236 
237  public function ‪isDragAndDropAllowed(): bool
238  {
239  $pageRecord = $this->context->getPageRecord();
240  return (int)$this->record['l18n_parent'] === 0 &&
241  (
242  $this->‪getBackendUser()->isAdmin()
243  || ((int)$this->record['editlock'] === 0 && (int)$pageRecord['editlock'] === 0)
244  && $this->‪getBackendUser()->doesUserHaveAccess($pageRecord, ‪Permission::CONTENT_EDIT)
245  && $this->‪getBackendUser()->checkAuthMode('tt_content', 'CType', $this->record['CType'], ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'])
246  )
247  ;
248  }
249 
250  public function ‪getNewContentAfterLinkTitle(): string
251  {
252  return $this->‪getLanguageService()->getLL('newContentElement');
253  }
254 
255  public function ‪getNewContentAfterTitle(): string
256  {
257  return $this->‪getLanguageService()->getLL('content');
258  }
259 
260  protected function ‪isInconsistentLanguage(): bool
261  {
262  $allowInconsistentLanguageHandling = (bool)(‪BackendUtility::getPagesTSconfig($this->‪getContext()->getPageId())['mod.']['web_layout.']['allowInconsistentLanguageHandling'] ?? false);
263  return !$allowInconsistentLanguageHandling
264  && $this->context->getSiteLanguage()->getLanguageId() !== 0
265  && $this->‪getContext()->getLanguageModeIdentifier() === 'mixed'
266  && (int)$this->record['l18n_parent'] === 0;
267  }
268 
269  public function ‪getNewContentAfterUrl(): string
270  {
271  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
272  $pageId = $this->context->getPageId();
273 
274  if ($this->context->getDrawingConfiguration()->getShowNewContentWizard()) {
275  $urlParameters = [
276  'id' => $pageId,
277  'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId(),
278  'colPos' => $this->column->getColumnNumber(),
279  'uid_pid' => -$this->record['uid'],
280  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
281  ];
282  $routeName = ‪BackendUtility::getPagesTSconfig($pageId)['mod.']['newContentElementWizard.']['override']
283  ?? 'new_content_element_wizard';
284  } else {
285  $urlParameters = [
286  'edit' => [
287  'tt_content' => [
288  -$this->record['uid'] => 'new'
289  ]
290  ],
291  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
292  ];
293  $routeName = 'record_edit';
294  }
295 
296  return (string)$uriBuilder->buildUriFromRoute($routeName, $urlParameters);
297  }
298 
299  public function ‪getVisibilityToggleUrl(): string
300  {
301  $hiddenField = ‪$GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
302  if ($this->record[$hiddenField]) {
303  $value = 0;
304  } else {
305  $value = 1;
306  }
307  $params = '&data[tt_content][' . ($this->record['_ORIG_uid'] ?: $this->record['uid'])
308  . '][' . $hiddenField . ']=' . $value;
309  return ‪BackendUtility::getLinkToDataHandlerAction($params) . '#element-tt_content-' . $this->record['uid'];
310  }
311 
312  public function ‪getVisibilityToggleTitle(): string
313  {
314  $hiddenField = ‪$GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
315  return $this->‪getLanguageService()->getLL($this->record[$hiddenField] ? 'unhide' : 'hide');
316  }
317 
318  public function ‪getVisibilityToggleIconName(): string
319  {
320  $hiddenField = ‪$GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
321  return $this->record[$hiddenField] ? 'unhide' : 'hide';
322  }
323 
324  public function ‪isVisibilityToggling(): bool
325  {
326  $hiddenField = ‪$GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
327  return $hiddenField && ‪$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
328  && (
329  !‪$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
330  || $this->‪getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField)
331  )
332  ;
333  }
334 
335  public function ‪getEditUrl(): string
336  {
337  $urlParameters = [
338  'edit' => [
339  'tt_content' => [
340  $this->record['uid'] => 'edit',
341  ]
342  ],
343  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $this->record['uid'],
344  ];
345  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
346  return (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters) . '#element-tt_content-' . $this->record['uid'];
347  }
348 }
‪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:62
‪TYPO3\CMS\Backend\Utility\BackendUtility\getLinkToDataHandlerAction
‪static string getLinkToDataHandlerAction($parameters, $redirectUrl='')
Definition: BackendUtility.php:2539
‪TYPO3\CMS\Backend\Preview\StandardPreviewRendererResolver
Definition: StandardPreviewRendererResolver.php:35
‪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:45
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isVisibilityToggling
‪isVisibilityToggling()
Definition: GridColumnItem.php:321
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getEditUrl
‪getEditUrl()
Definition: GridColumnItem.php:332
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getTitle
‪string getTitle()
Definition: SiteLanguage.php:222
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isDelible
‪isDelible()
Definition: GridColumnItem.php:96
‪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:55
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getFooterInfo
‪getFooterInfo()
Definition: GridColumnItem.php:126
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getNewContentAfterLinkTitle
‪getNewContentAfterLinkTitle()
Definition: GridColumnItem.php:247
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\setRecord
‪setRecord(array $record)
Definition: GridColumnItem.php:191
‪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:81
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\$translations
‪GridColumnItem[] $translations
Definition: GridColumnItem.php:53
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getNewContentAfterUrl
‪getNewContentAfterUrl()
Definition: GridColumnItem.php:266
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\addTranslation
‪addTranslation(int $languageId, GridColumnItem $translation)
Definition: GridColumnItem.php:206
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getNewContentAfterTitle
‪getNewContentAfterTitle()
Definition: GridColumnItem.php:252
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:26
‪TYPO3\CMS\Backend\Utility\BackendUtility\wrapClickMenuOnIcon
‪static string wrapClickMenuOnIcon( $content, $table, $uid=0, $context='', $_addParams='', $_enDisItems='', $returnTagParameters=false)
Definition: BackendUtility.php:2510
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getDeleteCancelText
‪getDeleteCancelText()
Definition: GridColumnItem.php:121
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getRecord
‪getRecord()
Definition: GridColumnItem.php:186
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getVisibilityToggleTitle
‪getVisibilityToggleTitle()
Definition: GridColumnItem.php:309
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getPreview
‪getPreview()
Definition: GridColumnItem.php:67
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getFlagIdentifier
‪string getFlagIdentifier()
Definition: SiteLanguage.php:246
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getVisibilityToggleUrl
‪getVisibilityToggleUrl()
Definition: GridColumnItem.php:296
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\getBackendUser
‪getBackendUser()
Definition: AbstractGridObject.php:71
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getColumn
‪getColumn()
Definition: GridColumnItem.php:196
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id)
Definition: BackendUtility.php:698
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordToolTip
‪static string getRecordToolTip(array $row, $table='pages')
Definition: BackendUtility.php:1339
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getDeleteUrl
‪getDeleteUrl()
Definition: GridColumnItem.php:105
‪TYPO3\CMS\Backend\View\BackendLayout\Grid
Definition: AbstractGridObject.php:18
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn
Definition: GridColumn.php:41
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isEditable
‪isEditable()
Definition: GridColumnItem.php:222
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getDeleteConfirmText
‪getDeleteConfirmText()
Definition: GridColumnItem.php:116
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:53
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\View\PageLayoutContext
Definition: PageLayoutContext.php:43
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getTranslations
‪getTranslations()
Definition: GridColumnItem.php:201
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getDeleteTitle
‪getDeleteTitle()
Definition: GridColumnItem.php:111
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getVisibilityToggleIconName
‪getVisibilityToggleIconName()
Definition: GridColumnItem.php:315
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem
Definition: GridColumnItem.php:42
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isInconsistentLanguage
‪isInconsistentLanguage()
Definition: GridColumnItem.php:257
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout\$title
‪string $title
Definition: BackendLayout.php:32
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\isDragAndDropAllowed
‪isDragAndDropAllowed()
Definition: GridColumnItem.php:234
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\$column
‪GridColumn $column
Definition: GridColumnItem.php:49
‪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:212
‪$icons
‪$icons
Definition: ext_localconf.php:54
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\renderLanguageFlag
‪string renderLanguageFlag(SiteLanguage $language)
Definition: GridColumnItem.php:144
‪TYPO3\CMS\Backend\Utility\BackendUtility\isRecordLocked
‪static array bool isRecordLocked($table, $uid)
Definition: BackendUtility.php:3011