TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AdditionalColumnService.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Workspaces\Service;
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 
51  public function register($columnName, $dataProviderClassOrObject)
52  {
53  if (is_object($dataProviderClassOrObject)) {
54  $dataProvider = $dataProviderClassOrObject;
55  } else {
56  $dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($dataProviderClassOrObject);
57  }
58 
59  if (!$dataProvider instanceof \TYPO3\CMS\Workspaces\ColumnDataProviderInterface) {
60  throw new \RuntimeException('Data provider needs to implement ColumnDataProviderInterface', 1374309323);
61  }
62 
63  $this->columns[$columnName] = $dataProvider;
64  }
65 
71  public function getDefinition()
72  {
73  $columnSettings = [];
74  foreach ($this->columns as $columnName => $dataProvider) {
75  $definition = $dataProvider->getDefinition();
76 
77  if (!is_array($definition)) {
78  $definition = [];
79  }
80 
81  $definition['name'] = $columnName;
82  $columnSettings[] = $definition;
83  }
84  return $columnSettings;
85  }
86 
93  public function getHandler()
94  {
95  $columnSettings = [];
96  foreach ($this->columns as $columnName => $_) {
97  $columnSettings[] = 'TYPO3.Workspaces.extension.AdditionalColumn.' . $columnName;
98  }
99  return $columnSettings;
100  }
101 
108  public function getData(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $combinedRecord)
109  {
110  $recordData = [];
111  foreach ($this->columns as $columnName => $dataProvider) {
112  $data = $dataProvider->getData($combinedRecord);
113 
114  if ($data !== null) {
115  $recordData[$columnName] = $data;
116  }
117  }
118  return $recordData;
119  }
120 }
getData(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $combinedRecord)
static makeInstance($className,...$constructorArguments)