TYPO3 CMS  TYPO3_8-7
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 
21 {
25  protected $columns = [];
26 
30  public static function getInstance()
31  {
32  return self::getObjectManager()->get(\TYPO3\CMS\Workspaces\Service\AdditionalColumnService::class);
33  }
34 
38  public static function getObjectManager()
39  {
40  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
41  }
42 
50  public function register($columnName, $dataProviderClassOrObject)
51  {
52  if (is_object($dataProviderClassOrObject)) {
53  $dataProvider = $dataProviderClassOrObject;
54  } else {
55  $dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($dataProviderClassOrObject);
56  }
57 
58  if (!$dataProvider instanceof \TYPO3\CMS\Workspaces\ColumnDataProviderInterface) {
59  throw new \RuntimeException('Data provider needs to implement ColumnDataProviderInterface', 1374309323);
60  }
61 
62  $this->columns[$columnName] = $dataProvider;
63  }
64 
70  public function getDefinition()
71  {
72  $columnSettings = [];
73  foreach ($this->columns as $columnName => $dataProvider) {
74  $definition = $dataProvider->getDefinition();
75 
76  if (!is_array($definition)) {
77  $definition = [];
78  }
79 
80  $definition['name'] = $columnName;
81  $columnSettings[] = $definition;
82  }
83  return $columnSettings;
84  }
85 
92  public function getHandler()
93  {
94  $columnSettings = [];
95  foreach ($this->columns as $columnName => $_) {
96  $columnSettings[] = 'TYPO3.Workspaces.extension.AdditionalColumn.' . $columnName;
97  }
98  return $columnSettings;
99  }
100 
107  public function getData(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $combinedRecord)
108  {
109  $recordData = [];
110  foreach ($this->columns as $columnName => $dataProvider) {
111  $data = $dataProvider->getData($combinedRecord);
112 
113  if ($data !== null) {
114  $recordData[$columnName] = $data;
115  }
116  }
117  return $recordData;
118  }
119 }
getData(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $combinedRecord)
static makeInstance($className,... $constructorArguments)