Completed
Push — master ( cb9863...be434f )
by
unknown
40:07 queued 25:06
created

BackendLayout::getLanguageModeIdentifier()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
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\Backend\View\BackendLayout;
17
18
use TYPO3\CMS\Backend\View\BackendLayoutView;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21
/**
22
 * Class to represent a backend layout.
23
 */
24
class BackendLayout
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $identifier;
30
31
    /**
32
     * @var string
33
     */
34
    protected $title;
35
36
    /**
37
     * @var string
38
     */
39
    protected $description;
40
41
    /**
42
     * @var string
43
     */
44
    protected $iconPath;
45
46
    /**
47
     * @var string
48
     */
49
    protected $configuration;
50
51
    /**
52
     * The structured data of the configuration represented as array.
53
     *
54
     * @var array
55
     */
56
    protected $structure = [];
57
58
    /**
59
     * @var array
60
     */
61
    protected $data;
62
63
    /**
64
     * @param string $identifier
65
     * @param string $title
66
     * @param string|array $configuration
67
     * @return BackendLayout
68
     */
69
    public static function create($identifier, $title, $configuration)
70
    {
71
        return GeneralUtility::makeInstance(
72
            static::class,
73
            $identifier,
74
            $title,
75
            $configuration
76
        );
77
    }
78
79
    /**
80
     * @param string $identifier
81
     * @param string $title
82
     * @param string|array $configuration
83
     */
84
    public function __construct($identifier, $title, $configuration)
85
    {
86
        $this->setIdentifier($identifier);
87
        $this->setTitle($title);
88
        if (is_array($configuration)) {
89
            $this->structure = $configuration;
90
            $this->configuration = $configuration['config'] ?? '';
91
        } else {
92
            $this->setConfiguration($configuration);
93
        }
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getIdentifier()
100
    {
101
        return $this->identifier;
102
    }
103
104
    /**
105
     * @param string $identifier
106
     * @throws \UnexpectedValueException
107
     */
108
    public function setIdentifier($identifier)
109
    {
110
        if (strpos($identifier, '__') !== false) {
111
            throw new \UnexpectedValueException(
112
                'Identifier "' . $identifier . '" must not contain "__"',
113
                1381597630
114
            );
115
        }
116
117
        $this->identifier = $identifier;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getTitle()
124
    {
125
        return $this->title;
126
    }
127
128
    /**
129
     * @param string $title
130
     */
131
    public function setTitle($title)
132
    {
133
        $this->title = $title;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getDescription()
140
    {
141
        return $this->description;
142
    }
143
144
    /**
145
     * @param string $description
146
     */
147
    public function setDescription($description)
148
    {
149
        $this->description = $description;
150
    }
151
152
    /**
153
     * @return string
154
     */
155
    public function getIconPath()
156
    {
157
        return $this->iconPath;
158
    }
159
160
    /**
161
     * @param string $iconPath
162
     */
163
    public function setIconPath($iconPath)
164
    {
165
        $this->iconPath = $iconPath;
166
    }
167
168
    /**
169
     * @return string
170
     */
171
    public function getConfiguration()
172
    {
173
        return $this->configuration;
174
    }
175
176
    /**
177
     * @param string $configuration
178
     */
179
    public function setConfiguration($configuration)
180
    {
181
        $this->configuration = $configuration;
182
        $this->structure = GeneralUtility::makeInstance(BackendLayoutView::class)->parseStructure($this);
183
    }
184
185
    /**
186
     * Returns the columns registered for this layout as $key => $value pair where the key is the colPos
187
     * and the value is the title.
188
     * "1" => "Left" etc.
189
     * Please note that the title can contain LLL references ready for translation.
190
     * @return array
191
     */
192
    public function getUsedColumns(): array
193
    {
194
        return $this->structure['usedColumns'] ?? [];
195
    }
196
197
    /**
198
     * @return array
199
     */
200
    public function getData()
201
    {
202
        return $this->data;
203
    }
204
205
    /**
206
     * @param array $data
207
     */
208
    public function setData(array $data)
209
    {
210
        $this->data = $data;
211
    }
212
213
    public function setStructure(array $structure)
214
    {
215
        $this->structure = $structure;
216
    }
217
218
    public function getStructure(): array
219
    {
220
        return $this->structure;
221
    }
222
223
    public function getColumnPositionNumbers(): array
224
    {
225
        return $this->structure['__colPosList'];
226
    }
227
}
228