‪TYPO3CMS  9.5
AdditionalColumnService.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
27 {
31  protected ‪$columns = [];
32 
36  public static function ‪getInstance()
37  {
38  return ‪self::getObjectManager()->‪get(AdditionalColumnService::class);
39  }
40 
44  public static function ‪getObjectManager()
45  {
46  return GeneralUtility::makeInstance(ObjectManager::class);
47  }
48 
56  public function register($columnName, $dataProviderClassOrObject)
57  {
58  if (is_object($dataProviderClassOrObject)) {
59  $dataProvider = $dataProviderClassOrObject;
60  } else {
61  $dataProvider = GeneralUtility::makeInstance($dataProviderClassOrObject);
62  }
63 
64  if (!$dataProvider instanceof ‪ColumnDataProviderInterface) {
65  throw new \RuntimeException('Data provider needs to implement ColumnDataProviderInterface', 1374309323);
66  }
67 
68  $this->columns[$columnName] = $dataProvider;
69  }
70 
76  public function ‪getDefinition()
77  {
78  $columnSettings = [];
79  foreach ($this->columns as $columnName => $dataProvider) {
80  $definition = $dataProvider->getDefinition();
81 
82  if (!is_array($definition)) {
83  $definition = [];
84  }
85 
86  $definition['name'] = $columnName;
87  $columnSettings[] = $definition;
88  }
89  return $columnSettings;
90  }
91 
98  public function ‪getHandler()
99  {
100  $columnSettings = [];
101  foreach ($this->columns as $columnName => $_) {
102  $columnSettings[] = 'TYPO3.Workspaces.extension.AdditionalColumn.' . $columnName;
103  }
104  return $columnSettings;
105  }
106 
113  public function ‪getData(‪CombinedRecord $combinedRecord)
114  {
115  $recordData = [];
116  foreach ($this->columns as $columnName => $dataProvider) {
117  $data = $dataProvider->getData($combinedRecord);
118 
119  if ($data !== null) {
120  $recordData[$columnName] = $data;
121  }
122  }
123  return $recordData;
124  }
125 }
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord
Definition: CombinedRecord.php:23
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getDefinition
‪array getDefinition()
Definition: AdditionalColumnService.php:75
‪TYPO3\CMS\Workspaces\Service
Definition: AdditionalColumnService.php:2
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getHandler
‪array getHandler()
Definition: AdditionalColumnService.php:97
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService
Definition: AdditionalColumnService.php:27
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getData
‪array getData(CombinedRecord $combinedRecord)
Definition: AdditionalColumnService.php:112
‪TYPO3\CMS\Workspaces\ColumnDataProviderInterface
Definition: ColumnDataProviderInterface.php:21
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Extbase\Object\ObjectManager\get
‪object &T get($objectName,... $constructorArguments)
Definition: ObjectManager.php:94
‪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:45
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Workspaces\Service\AdditionalColumnService\getObjectManager
‪static ObjectManager getObjectManager()
Definition: AdditionalColumnService.php:43