1
|
|
|
<?php |
2
|
|
|
namespace Qbus\Qbtools\Hooks\Options; |
3
|
|
|
|
4
|
|
|
use TYPO3\CMS\Backend\View\BackendLayout\BackendLayout; |
5
|
|
|
use TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection; |
6
|
|
|
use TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @todo deprecate |
10
|
|
|
*/ |
11
|
|
|
class BackendLayoutDataProvider implements \TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param DataProviderContext $dataProviderContext |
15
|
|
|
* @param BackendLayoutCollection $backendLayoutCollection |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
public function addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection) |
19
|
|
|
{ |
20
|
|
|
$BEfunc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Backend\Utility\BackendUtility'); |
21
|
|
|
$pageTSconfig = $BEfunc->getPagesTSconfig(1); |
22
|
|
|
|
23
|
|
|
if (isset($pageTSconfig['tx_qbtools.']['backend_layout.'])) { |
24
|
|
|
foreach ($pageTSconfig['tx_qbtools.']['backend_layout.'] as $id => $layout) { |
25
|
|
|
if (substr($id, -1) != '.') { |
26
|
|
|
continue; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$id = substr($id, 0, -1); |
30
|
|
|
|
31
|
|
|
$backendLayout = $this->createBackendLayout($id, $layout); |
32
|
|
|
$backendLayoutCollection->add($backendLayout); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Gets a backend layout by (regular) identifier. |
39
|
|
|
* |
40
|
|
|
* @param string $identifier |
41
|
|
|
* @param int $pageId |
42
|
|
|
* @return NULL|BackendLayout |
43
|
|
|
*/ |
44
|
|
|
public function getBackendLayout($identifier, $pageId) |
45
|
|
|
{ |
46
|
|
|
$BEfunc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Backend\Utility\BackendUtility'); |
47
|
|
|
$pageTSconfig = $BEfunc->getPagesTSconfig(1); |
48
|
|
|
|
49
|
|
|
if (isset($pageTSconfig['tx_qbtools.']['backend_layout.'][$identifier . '.'])) { |
50
|
|
|
return $this->createBackendLayout($identifier, $pageTSconfig['tx_qbtools.']['backend_layout.'][$identifier . '.']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return null; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function typoscriptToString(array $config) |
57
|
|
|
{ |
58
|
|
|
$str = ''; |
59
|
|
|
|
60
|
|
|
foreach ($config as $key => $value) { |
61
|
|
|
if (is_array($value)) { |
62
|
|
|
$str .= sprintf("%s {\n%s\n}\n", substr($key, 0, -1), $this->typoscriptToString($value)); |
63
|
|
|
} else { |
64
|
|
|
$str .= sprintf("%s = %s\n", $key, $value); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $str; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Creates a new backend layout using the given record data. |
73
|
|
|
* |
74
|
|
|
* @param string $id |
75
|
|
|
* @param array $data |
76
|
|
|
* @return BackendLayout |
77
|
|
|
*/ |
78
|
|
|
protected function createBackendLayout($id, $layout) |
79
|
|
|
{ |
80
|
|
|
$layout['uid'] = $id; |
81
|
|
|
|
82
|
|
|
if (isset($layout['config.'])) { |
83
|
|
|
$layout['config'] = array('backend_layout.' => $layout['config.']); |
84
|
|
|
unset($layout['config.']); |
85
|
|
|
|
86
|
|
|
$layout['config'] = $this->typoscriptToString($layout['config']); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if (!isset($layout['title'])) { |
90
|
|
|
$layout['title'] = 'Untitled'; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$layout['icon'] = $this->getIconPath($layout['icon']); |
94
|
|
|
|
95
|
|
|
$backendLayout = BackendLayout::create($layout['uid'], $layout['title'], $layout['config']); |
96
|
|
|
$backendLayout->setIconPath($this->getIconPath($layout['icon'])); |
97
|
|
|
$backendLayout->setData($layout); |
98
|
|
|
|
99
|
|
|
return $backendLayout; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Gets and sanitizes the icon path. |
104
|
|
|
* |
105
|
|
|
* @param string $icon Name of the icon file |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
protected function getIconPath($icon) |
109
|
|
|
{ |
110
|
|
|
$iconPath = ''; |
111
|
|
|
if (!empty($icon)) { |
112
|
|
|
$iconPath = $icon; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $iconPath; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|