TYPO3 CMS  TYPO3_6-2
AdditionalColumnService.php
Go to the documentation of this file.
1 <?php
3 
22 
26  protected $columns = array();
27 
31  static public function getInstance() {
32  return self::getObjectManager()->get('TYPO3\\CMS\\Workspaces\\Service\\AdditionalColumnService');
33  }
34 
38  static public function getObjectManager() {
39  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
40  }
41 
50  public function register($columnName, $dataProviderClassOrObject) {
51  if (is_object($dataProviderClassOrObject)) {
52  $dataProvider = $dataProviderClassOrObject;
53  } else {
54  $dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($dataProviderClassOrObject);
55  }
56 
57  if (!$dataProvider instanceof \TYPO3\CMS\Workspaces\ColumnDataProviderInterface) {
58  throw new \RuntimeException('Data provider needs to implement ColumnDataProviderInterface', 1374309323);
59  }
60 
61  $this->columns[$columnName] = $dataProvider;
62  }
63 
69  public function getDefinition() {
70  $columnSettings = array();
71  foreach ($this->columns as $columnName => $dataProvider) {
72  $definition = $dataProvider->getDefinition();
73 
74  if (!is_array($definition)) {
75  $definition = array();
76  }
77 
78  $definition['name'] = $columnName;
79  $columnSettings[] = $definition;
80  }
81  return $columnSettings;
82  }
83 
90  public function getHandler() {
91  $columnSettings = array();
92  foreach ($this->columns as $columnName => $_) {
93  $columnSettings[] = 'TYPO3.Workspaces.extension.AdditionalColumn.' . $columnName;
94  }
95  return $columnSettings;
96  }
97 
104  public function getData(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $combinedRecord) {
105  $recordData = array();
106  foreach ($this->columns as $columnName => $dataProvider) {
107  $data = $dataProvider->getData($combinedRecord);
108 
109  if ($data !== NULL) {
110  $recordData[$columnName] = $data;
111  }
112  }
113  return $recordData;
114  }
115 }
getData(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $combinedRecord)