1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/*************************************************************** |
4
|
|
|
* Copyright notice |
5
|
|
|
* |
6
|
|
|
* All rights reserved |
7
|
|
|
* |
8
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
9
|
|
|
* free software; you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU General Public License as published by |
11
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* The GNU General Public License can be found at |
15
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
16
|
|
|
* |
17
|
|
|
* This script is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
23
|
|
|
***************************************************************/ |
24
|
|
|
|
25
|
|
|
namespace SourceBroker\Hugo\Service; |
26
|
|
|
|
27
|
|
|
use SourceBroker\Hugo\Utility\RootlineUtility; |
28
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
29
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
30
|
|
|
use TYPO3\CMS\Core\TypoScript\TypoScriptService; |
31
|
|
|
use TYPO3\CMS\Core\Utility\StringUtility; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class Typo3UrlService |
35
|
|
|
* |
36
|
|
|
*/ |
37
|
|
|
class BackendLayoutService extends AbstractService implements SingletonInterface |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
protected static $localIdentifierCache = []; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected static $localCache = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param int $pageUid |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getIdentifierByPage(int $pageUid): string |
55
|
|
|
{ |
56
|
|
|
if (!isset(self::$localIdentifierCache[$pageUid])) { |
57
|
|
|
$rootLine = ($this->objectManager->get(RootlineUtility::class, $pageUid))->get(); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$identifier = ''; |
60
|
|
|
|
61
|
|
|
krsort($rootLine); |
62
|
|
|
foreach ($rootLine as $key => $page) { |
63
|
|
|
if ($pageUid == $page['uid'] && !empty($page['backend_layout'])) { |
64
|
|
|
$identifier = $page['backend_layout']; |
65
|
|
|
break; |
66
|
|
|
} |
67
|
|
|
if (!empty($page['backend_layout_next_level'])) { |
68
|
|
|
$identifier = $page['backend_layout_next_level']; |
69
|
|
|
break; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
self::$localIdentifierCache[$pageUid] = $identifier; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return self::$localIdentifierCache[$pageUid]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param int $pageUid |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function getByPage(int $pageUid): array |
85
|
|
|
{ |
86
|
|
|
if (!isset(self::$localCache[$pageUid])) { |
87
|
|
|
$identifier = $this->getIdentifierByPage($pageUid); |
88
|
|
|
|
89
|
|
|
if (!StringUtility::beginsWith($identifier, 'pagets__')) { |
90
|
|
|
throw new \InvalidArgumentException('Only backend layouts from PageTSConfig are supported at the moment.', 1534620796); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$pageTsConfig = $this->objectManager->get(TypoScriptService::class) |
94
|
|
|
->convertTypoScriptArrayToPlainArray(BackendUtility::getPagesTSconfig($pageUid)); |
95
|
|
|
|
96
|
|
|
$pageTsConfigIdentifier = str_replace('pagets__', '', $identifier); |
97
|
|
|
|
98
|
|
|
self::$localCache[$pageUid] = $pageTsConfig['mod']['web_layout']['BackendLayouts'][$pageTsConfigIdentifier] ?? []; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return self::$localCache[$pageUid]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param int $pageUid |
106
|
|
|
* |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
|
|
public function getColPosesByPage(int $pageUid) |
110
|
|
|
{ |
111
|
|
|
return array_unique( |
112
|
|
|
array_map('intval', array_column($this->getColumnsByPage($pageUid), 'colPos')) |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param int $pageUid |
118
|
|
|
* @param int $slideLevel |
119
|
|
|
* |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
|
public function getColPosesByPageAndSlideLevel(int $pageUid, int $slideLevel) |
123
|
|
|
{ |
124
|
|
|
$colPoses = []; |
125
|
|
|
|
126
|
|
|
foreach ($this->getColumnsByPage($pageUid) as $col) { |
127
|
|
|
$hugoSlideLevel = (int)($col['txHugoSlide'] ?? 0); |
128
|
|
|
|
129
|
|
|
if (isset($col['colPos']) && ($hugoSlideLevel === -1 || $hugoSlideLevel >= $slideLevel)) { |
130
|
|
|
$colPoses[] = (int)$col['colPos']; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $colPoses; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param int $pageUid |
139
|
|
|
* |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
protected function getColumnsByPage(int $pageUid): array |
143
|
|
|
{ |
144
|
|
|
$backendLayout = $this->getByPage($pageUid); |
145
|
|
|
$rows = $backendLayout['config']['backend_layout']['rows'] ?? []; |
146
|
|
|
$columns = []; |
147
|
|
|
|
148
|
|
|
foreach ($rows as $row) { |
149
|
|
|
$columns = array_merge($columns, ($row['columns'] ?? [])); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $columns; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.