‪TYPO3CMS  10.4
GridColumn.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 
25 
41 {
45  protected ‪$items = [];
46 
50  protected ‪$columnNumber;
51 
55  protected ‪$columnName = 'default';
56 
60  protected ‪$icon;
61 
65  protected ‪$colSpan = 1;
66 
70  protected ‪$rowSpan = 1;
71 
72  public function ‪__construct(‪PageLayoutContext ‪$context, array $columnDefinition)
73  {
74  parent::__construct(‪$context);
75  $this->columnNumber = isset($columnDefinition['colPos']) ? (int)$columnDefinition['colPos'] : $this->columnNumber;
76  $this->columnName = $columnDefinition['name'] ?? ‪$this->columnName;
77  $this->icon = $columnDefinition['icon'] ?? ‪$this->icon;
78  $this->colSpan = (int)($columnDefinition['colspan'] ?? $this->colSpan);
79  $this->rowSpan = (int)($columnDefinition['rowspan'] ?? $this->rowSpan);
80  }
81 
82  public function ‪isActive(): bool
83  {
84  return $this->columnNumber !== null && in_array($this->columnNumber, $this->context->getDrawingConfiguration()->getActiveColumns());
85  }
86 
87  public function ‪addItem(‪GridColumnItem $item): void
88  {
89  $this->items[] = $item;
90  }
91 
95  public function ‪getItems(): iterable
96  {
97  return ‪$this->items;
98  }
99 
100  public function ‪getColumnNumber(): ?int
101  {
102  return ‪$this->columnNumber;
103  }
104 
105  public function ‪getColumnName(): string
106  {
107  return ‪$this->columnName;
108  }
109 
110  public function ‪getIcon(): ?string
111  {
112  return ‪$this->icon;
113  }
114 
115  public function ‪getColSpan(): int
116  {
117  if ($this->context->getDrawingConfiguration()->getLanguageMode()) {
118  return 1;
119  }
120  return ‪$this->colSpan;
121  }
122 
123  public function ‪getRowSpan(): int
124  {
125  if ($this->context->getDrawingConfiguration()->getLanguageMode()) {
126  return 1;
127  }
129  }
130 
134  public function ‪getAllContainedItemUids(): array
135  {
136  $uids = [];
137  foreach ($this->items as $columnItem) {
138  $uids[] = (int)$columnItem->getRecord()['uid'];
139  }
140  return $uids;
141  }
142 
143  public function ‪getEditUrl(): ?string
144  {
145  if (empty($this->items)) {
146  return null;
147  }
148  $pageRecord = $this->context->getPageRecord();
149  if (!$this->‪getBackendUser()->doesUserHaveAccess($pageRecord, ‪Permission::CONTENT_EDIT)
150  || !$this->‪getBackendUser()->checkLanguageAccess($this->context->getSiteLanguage()->getLanguageId())) {
151  return null;
152  }
153  $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(
154  ‪BackendUtility::getRecordTitle('pages', $pageRecord, true)
155  );
156  $editParam = '&edit[tt_content][' . implode(',', $this->‪getAllContainedItemUids()) . ']=edit' . $pageTitleParamForAltDoc;
157  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
158  return $uriBuilder->buildUriFromRoute('record_edit') . $editParam . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
159  }
160 
161  public function ‪getNewContentUrl(): string
162  {
163  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
164  $pageId = $this->context->getPageId();
165 
166  if ($this->context->getDrawingConfiguration()->getShowNewContentWizard()) {
167  $urlParameters = [
168  'id' => $pageId,
169  'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId(),
170  'colPos' => $this->‪getColumnNumber(),
171  'uid_pid' => $pageId,
172  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
173  ];
174  $routeName = ‪BackendUtility::getPagesTSconfig($pageId)['mod.']['newContentElementWizard.']['override']
175  ?? 'new_content_element_wizard';
176  } else {
177  $urlParameters = [
178  'edit' => [
179  'tt_content' => [
180  $pageId => 'new'
181  ]
182  ],
183  'defVals' => [
184  'tt_content' => [
185  'colPos' => $this->‪getColumnNumber(),
186  'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId()
187  ]
188  ],
189  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
190  ];
191  $routeName = 'record_edit';
192  }
193 
194  return (string)$uriBuilder->buildUriFromRoute($routeName, $urlParameters);
195  }
196 
197  public function ‪getTitle(): string
198  {
200  $colTitle = ‪BackendUtility::getProcessedValue('tt_content', 'colPos', (string)‪$columnNumber) ?? '';
201  foreach ($this->context->getBackendLayout()->getUsedColumns() as $colPos => ‪$title) {
202  if ($colPos === ‪$columnNumber) {
203  $colTitle = (string)$this->‪getLanguageService()->sL(‪$title);
204  }
205  }
206  return $colTitle;
207  }
208 
209  public function ‪getTitleInaccessible(): string
210  {
211  return $this->‪getLanguageService()->sL($this->columnName) . ' (' . $this->‪getLanguageService()->getLL('noAccess') . ')';
212  }
213 
214  public function ‪getTitleUnassigned(): string
215  {
216  return $this->‪getTitle() . ' (' . $this->‪getLanguageService()->getLL('notAssigned') . ')';
217  }
218 
219  public function ‪isUnassigned(): bool
220  {
221  return $this->columnNumber === null;
222  }
223 
224  public function ‪isContentEditable(): bool
225  {
226  if ($this->columnName === 'unused' || $this->columnNumber === null) {
227  return false;
228  }
229  if ($this->‪getBackendUser()->isAdmin()) {
230  return true;
231  }
232  $pageRecord = $this->context->getPageRecord();
233  return !$pageRecord['editlock']
234  && $this->‪getBackendUser()->doesUserHaveAccess($pageRecord, ‪Permission::CONTENT_EDIT)
235  && $this->‪getBackendUser()->checkLanguageAccess($this->context->getSiteLanguage()->getLanguageId());
236  }
237 }
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getRowSpan
‪getRowSpan()
Definition: GridColumn.php:117
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getTitle
‪getTitle()
Definition: GridColumn.php:191
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\addItem
‪addItem(GridColumnItem $item)
Definition: GridColumn.php:81
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getTitleUnassigned
‪getTitleUnassigned()
Definition: GridColumn.php:208
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject
Definition: AbstractGridObject.php:41
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\isActive
‪isActive()
Definition: GridColumn.php:76
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getTitleInaccessible
‪getTitleInaccessible()
Definition: GridColumn.php:203
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$columnName
‪string $columnName
Definition: GridColumn.php:52
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\$context
‪PageLayoutContext $context
Definition: AbstractGridObject.php:44
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\__construct
‪__construct(PageLayoutContext $context, array $columnDefinition)
Definition: GridColumn.php:66
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getColSpan
‪getColSpan()
Definition: GridColumn.php:109
‪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\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id)
Definition: BackendUtility.php:698
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Backend\View\BackendLayout\Grid
Definition: AbstractGridObject.php:18
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getColumnName
‪getColumnName()
Definition: GridColumn.php:99
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn
Definition: GridColumn.php:41
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getEditUrl
‪getEditUrl()
Definition: GridColumn.php:137
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getIcon
‪getIcon()
Definition: GridColumn.php:104
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$rowSpan
‪int $rowSpan
Definition: GridColumn.php:64
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getAllContainedItemUids
‪int[] getAllContainedItemUids()
Definition: GridColumn.php:128
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$items
‪GridColumnItem[] $items
Definition: GridColumn.php:44
‪TYPO3\CMS\Backend\Utility\BackendUtility\getProcessedValue
‪static string null getProcessedValue( $table, $col, $value, $fixed_lgd_chars=0, $defaultPassthrough=false, $noRecordLookup=false, $uid=0, $forceResult=true, $pid=0)
Definition: BackendUtility.php:1664
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getNewContentUrl
‪getNewContentUrl()
Definition: GridColumn.php:155
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$colSpan
‪int $colSpan
Definition: GridColumn.php:60
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:53
‪TYPO3\CMS\Backend\View\PageLayoutContext
Definition: PageLayoutContext.php:43
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$columnNumber
‪int null $columnNumber
Definition: GridColumn.php:48
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\isUnassigned
‪isUnassigned()
Definition: GridColumn.php:213
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$icon
‪string null $icon
Definition: GridColumn.php:56
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getItems
‪GridColumnItem[] getItems()
Definition: GridColumn.php:89
‪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\BackendLayout\$title
‪string $title
Definition: BackendLayout.php:32
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getColumnNumber
‪getColumnNumber()
Definition: GridColumn.php:94
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\getLanguageService
‪getLanguageService()
Definition: AbstractGridObject.php:66
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\isContentEditable
‪isContentEditable()
Definition: GridColumn.php:218