‪TYPO3CMS  10.4
AdditionalColumnService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
27 {
31  protected ‪$columns = [];
32 
36  public static function ‪getInstance()
37  {
38  return GeneralUtility::makeInstance(AdditionalColumnService::class);
39  }
40 
48  public function register($columnName, $dataProviderClassOrObject)
49  {
50  if (is_object($dataProviderClassOrObject)) {
51  $dataProvider = $dataProviderClassOrObject;
52  } else {
53  $dataProvider = GeneralUtility::makeInstance($dataProviderClassOrObject);
54  }
55 
56  if (!$dataProvider instanceof ‪ColumnDataProviderInterface) {
57  throw new \RuntimeException('Data provider needs to implement ColumnDataProviderInterface', 1374309323);
58  }
59 
60  $this->columns[$columnName] = $dataProvider;
61  }
62 
68  public function ‪getDefinition()
69  {
70  $columnSettings = [];
71  foreach ($this->columns as $columnName => $dataProvider) {
72  $definition = $dataProvider->getDefinition();
73 
74  if (!is_array($definition)) {
75  $definition = [];
76  }
77 
78  $definition['name'] = $columnName;
79  $columnSettings[] = $definition;
80  }
81  return $columnSettings;
82  }
83 
90  public function ‪getHandler()
91  {
92  $columnSettings = [];
93  foreach ($this->columns as $columnName => $_) {
94  $columnSettings[] = 'TYPO3.Workspaces.extension.AdditionalColumn.' . $columnName;
95  }
96  return $columnSettings;
97  }
98 
105  public function ‪getData(‪CombinedRecord $combinedRecord)
106  {
107  $recordData = [];
108  foreach ($this->columns as $columnName => $dataProvider) {
109  $data = $dataProvider->getData($combinedRecord);
110 
111  if ($data !== null) {
112  $recordData[$columnName] = $data;
113  }
114  }
115  return $recordData;
116  }
117 }
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord
Definition: CombinedRecord.php:24
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getDefinition
‪array getDefinition()
Definition: AdditionalColumnService.php:67
‪TYPO3\CMS\Workspaces\Service
Definition: AdditionalColumnService.php:16
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getHandler
‪array getHandler()
Definition: AdditionalColumnService.php:89
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService
Definition: AdditionalColumnService.php:27
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getData
‪array getData(CombinedRecord $combinedRecord)
Definition: AdditionalColumnService.php:104
‪TYPO3\CMS\Workspaces\ColumnDataProviderInterface
Definition: ColumnDataProviderInterface.php:24
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\$columns
‪array ColumnDataProviderInterface[] $columns
Definition: AdditionalColumnService.php:30
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getInstance
‪static AdditionalColumnService getInstance()
Definition: AdditionalColumnService.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46