Completed
Push — master ( 83cb67...d32f9d )
by
unknown
20:24
created

AdditionalColumnService::getObjectManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
16
namespace TYPO3\CMS\Workspaces\Service;
17
18
use TYPO3\CMS\Core\SingletonInterface;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Workspaces\ColumnDataProviderInterface;
21
use TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord;
22
23
/**
24
 * Service for additional columns in GridPanel
25
 */
26
class AdditionalColumnService implements SingletonInterface
27
{
28
    /**
29
     * @var array|ColumnDataProviderInterface[]
30
     */
31
    protected $columns = [];
32
33
    /**
34
     * @return AdditionalColumnService
35
     */
36
    public static function getInstance()
37
    {
38
        return GeneralUtility::makeInstance(AdditionalColumnService::class);
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
39
    }
40
41
    /**
42
     * Registers data provider for a particular column name.
43
     *
44
     * @param string $columnName
45
     * @param string|object $dataProviderClassOrObject
46
     * @throws \RuntimeException
47
     */
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
63
    /**
64
     * Gets definition for JavaScript settings.
65
     *
66
     * @return array Column settings
67
     */
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
84
    /**
85
     * Gets JavaScript handler object, e.g.
86
     * TYPO3.Workspaces.Configuration.AdditionalColumn.extension.MyCustomField
87
     *
88
     * @return array Column settings
89
     */
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
99
    /**
100
     * Gets data for grid data.
101
     *
102
     * @param CombinedRecord $combinedRecord
103
     * @return array Record data
104
     */
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
}
118