‪TYPO3CMS  ‪main
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 
20 use Psr\EventDispatcher\EventDispatcherInterface;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
28 
44 {
48  protected array ‪$items = [];
49 
50  protected readonly ?int ‪$columnNumber;
51  protected readonly string ‪$columnName;
52  protected readonly string ‪$icon;
53  protected readonly int ‪$colSpan;
54  protected readonly int ‪$rowSpan;
55  private readonly EventDispatcherInterface ‪$eventDispatcher;
56 
60  public function ‪__construct(
61  protected ‪PageLayoutContext $context,
62  protected readonly array $definition,
63  protected readonly string $table = 'tt_content'
64  ) {
65  parent::__construct($context);
66  $this->columnNumber = isset($definition['colPos']) ? (int)$definition['colPos'] : null;
67  $this->columnName = (string)($definition['name'] ?? 'default');
68  $this->icon = (string)($definition['icon'] ?? '');
69  $this->colSpan = (int)($definition['colspan'] ?? 1);
70  $this->rowSpan = (int)($definition['rowspan'] ?? 1);
71  $this->eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class);
72  }
73 
77  public function getDefinition(): array
78  {
79  return $this->definition;
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()->isLanguageComparisonMode()) {
118  return 1;
119  }
120  return ‪$this->colSpan;
121  }
122 
123  public function ‪getRowSpan(): int
124  {
125  if ($this->context->getDrawingConfiguration()->isLanguageComparisonMode()) {
126  return 1;
127  }
128  return ‪$this->rowSpan;
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())) {
151  return null;
152  }
153  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
154  return (string)$uriBuilder->buildUriFromRoute('record_edit', [
155  'edit' => [
156  $this->table => [
157  implode(',', $this->‪getAllContainedItemUids()) => 'edit',
158  ],
159  ],
160  'recTitle' => rawurlencode(BackendUtility::getRecordTitle('pages', $pageRecord, true)),
161  'returnUrl' => rawurlencode($this->context->getCurrentRequest()->getAttribute('normalizedParams')->getRequestUri()),
162  ]);
163  }
164 
165  public function ‪getNewContentUrl(): string
166  {
167  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
168  $pageId = $this->context->getPageId();
169 
170  return (string)$uriBuilder->buildUriFromRoute('new_content_element_wizard', [
171  'id' => $pageId,
172  'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId(),
173  'colPos' => $this->getColumnNumber(),
174  'uid_pid' => $pageId,
175  'returnUrl' => $this->context->getCurrentRequest()->getAttribute('normalizedParams')->getRequestUri(),
176  ]);
177  }
178 
179  public function ‪getTitle(): string
180  {
182  $colTitle = '';
183  foreach ($this->context->getBackendLayout()->getUsedColumns() as $colPos => ‪$title) {
184  if ($colPos === ‪$columnNumber) {
185  $colTitle = $this->‪getLanguageService()->sL(‪$title);
186  }
187  }
188  return $colTitle;
189  }
190 
191  public function ‪getTitleInaccessible(): string
192  {
193  return $this->‪getLanguageService()->sL($this->columnName) . ' (' . $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:noAccess') . ')';
194  }
195 
196  public function ‪getTitleUnassigned(): string
197  {
198  return $this->‪getLanguageService()->sL($this->columnName) . ' (' . $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:notAssigned') . ')';
199  }
200 
201  public function ‪getBeforeSectionMarkup(): string
202  {
203  $event = new ‪BeforeSectionMarkupGeneratedEvent($this->‪definition, $this->context, $this->getRecords());
204  $this->eventDispatcher->dispatch($event);
205  return $event->getContent();
206  }
207 
208  public function ‪getAfterSectionMarkup(): string
209  {
210  $event = new ‪AfterSectionMarkupGeneratedEvent($this->‪definition, $this->context, $this->getRecords());
211  $this->eventDispatcher->dispatch($event);
212  return $event->getContent();
213  }
214 
215  public function ‪isUnassigned(): bool
216  {
217  return $this->columnName !== 'unused' && $this->columnNumber === null;
218  }
219 
220  public function ‪isUnused(): bool
221  {
222  return $this->columnName === 'unused' && $this->columnNumber === null;
223  }
224 
225  public function ‪isContentEditable(): bool
226  {
227  if ($this->columnName === 'unused' || $this->columnNumber === null) {
228  return false;
229  }
230  if ($this->‪getBackendUser()->isAdmin()) {
231  return true;
232  }
233  $pageRecord = $this->context->getPageRecord();
234  return !$pageRecord['editlock']
235  && $this->‪getBackendUser()->doesUserHaveAccess($pageRecord, ‪Permission::CONTENT_EDIT)
236  && $this->‪getBackendUser()->checkLanguageAccess($this->context->getSiteLanguage());
237  }
238 
244  protected function getRecords(): array
245  {
246  if ($this->items === []) {
247  return [];
248  }
249 
250  ‪$records = [];
251  foreach ($this->items as $item) {
252  ‪$record = $item->getRecord();
254  }
255  return ‪$records;
256  }
257 }
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getRowSpan
‪getRowSpan()
Definition: GridColumn.php:123
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getTitle
‪getTitle()
Definition: GridColumn.php:179
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\isUnused
‪isUnused()
Definition: GridColumn.php:220
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\addItem
‪addItem(GridColumnItem $item)
Definition: GridColumn.php:87
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getTitleUnassigned
‪getTitleUnassigned()
Definition: GridColumn.php:196
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject
Definition: AbstractGridObject.php:40
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\isActive
‪isActive()
Definition: GridColumn.php:82
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getTitleInaccessible
‪getTitleInaccessible()
Definition: GridColumn.php:191
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\definition
‪array< string, function getDefinition():array { return $this-> definition
Definition: GridColumn.php:79
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$items
‪array $items
Definition: GridColumn.php:48
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$columnName
‪readonly string $columnName
Definition: GridColumn.php:51
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$rowSpan
‪readonly int $rowSpan
Definition: GridColumn.php:54
‪TYPO3\CMS\Backend\View\Event\AfterSectionMarkupGeneratedEvent
Definition: AfterSectionMarkupGeneratedEvent.php:24
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getColSpan
‪getColSpan()
Definition: GridColumn.php:115
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$eventDispatcher
‪readonly EventDispatcherInterface $eventDispatcher
Definition: GridColumn.php:55
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\getBackendUser
‪getBackendUser()
Definition: AbstractGridObject.php:58
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$records
‪return $records
Definition: GridColumn.php:255
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$records
‪$records[(int) $record['uid']]
Definition: GridColumn.php:253
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Backend\View\BackendLayout\Grid
Definition: AbstractGridObject.php:18
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$icon
‪readonly string $icon
Definition: GridColumn.php:52
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getColumnName
‪getColumnName()
Definition: GridColumn.php:105
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$columnNumber
‪readonly int $columnNumber
Definition: GridColumn.php:50
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\$colSpan
‪readonly int $colSpan
Definition: GridColumn.php:53
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn
Definition: GridColumn.php:44
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getEditUrl
‪getEditUrl()
Definition: GridColumn.php:143
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getIcon
‪getIcon()
Definition: GridColumn.php:110
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getAllContainedItemUids
‪int[] getAllContainedItemUids()
Definition: GridColumn.php:134
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getNewContentUrl
‪getNewContentUrl()
Definition: GridColumn.php:165
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:55
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getAfterSectionMarkup
‪getAfterSectionMarkup()
Definition: GridColumn.php:208
‪TYPO3\CMS\Backend\View\PageLayoutContext
Definition: PageLayoutContext.php:42
‪TYPO3\CMS\Backend\View\Event\BeforeSectionMarkupGeneratedEvent
Definition: BeforeSectionMarkupGeneratedEvent.php:24
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\isUnassigned
‪isUnassigned()
Definition: GridColumn.php:215
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getBeforeSectionMarkup
‪getBeforeSectionMarkup()
Definition: GridColumn.php:201
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getItems
‪GridColumnItem[] getItems()
Definition: GridColumn.php:95
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem
Definition: GridColumnItem.php:45
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout\$title
‪string $title
Definition: BackendLayout.php:29
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\getColumnNumber
‪getColumnNumber()
Definition: GridColumn.php:100
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\getLanguageService
‪getLanguageService()
Definition: AbstractGridObject.php:53
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\isContentEditable
‪isContentEditable()
Definition: GridColumn.php:225
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn\__construct
‪__construct(protected PageLayoutContext $context, protected readonly array $definition, protected readonly string $table='tt_content')
Definition: GridColumn.php:60