‪TYPO3CMS  10.4
PageTsBackendLayoutDataProvider.php
Go to the documentation of this file.
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 
17 
25 
68 {
74  protected ‪$backendLayouts = [];
75 
81  protected ‪$pageTsConfig = [];
82 
88  protected ‪$pageId = 0;
89 
95  protected function ‪setPageTsConfig(array ‪$pageTsConfig)
96  {
97  $this->pageTsConfig = ‪$pageTsConfig;
98  }
99 
105  protected function ‪getPageTsConfig()
106  {
107  return ‪$this->pageTsConfig;
108  }
109 
115  protected function ‪setPageId(‪$pageId)
116  {
117  $this->pageId = (int)‪$pageId;
118  }
119 
125  protected function ‪getPageId()
126  {
127  return (int)‪$this->pageId;
128  }
129 
136  protected function ‪generatePageTsConfig($dataProviderContext = null)
137  {
138  if ($dataProviderContext === null) {
139  ‪$pageId = $this->‪getPageId();
140  ‪$pageId = ‪$pageId > 0 ? ‪$pageId : (int)GeneralUtility::_GP('id');
142  } else {
143  ‪$pageTsConfig = $dataProviderContext->getPageTsConfig();
144  }
145  $this->‪setPageTsConfig($pageTsConfig);
146  }
147 
153  protected function ‪generateBackendLayouts($dataProviderContext = null)
154  {
155  $this->‪generatePageTsConfig($dataProviderContext);
157  if (!empty(‪$pageTsConfig['mod.']['web_layout.']['BackendLayouts.'])) {
158  ‪$backendLayouts = (array)‪$pageTsConfig['mod.']['web_layout.']['BackendLayouts.'];
159  foreach (‪$backendLayouts as $identifier => $data) {
160  $backendLayout = $this->‪generateBackendLayoutFromTsConfig($identifier, $data);
161  $this->‪attachBackendLayout($backendLayout);
162  }
163  }
164  }
165 
173  protected function ‪generateBackendLayoutFromTsConfig($identifier, $data)
174  {
175  $backendLayout = [];
176  if (!empty($data['config.']['backend_layout.']) && is_array($data['config.']['backend_layout.'])) {
177  $backendLayout['uid'] = substr($identifier, 0, -1);
178  $backendLayout['title'] = $data['title'] ?: $backendLayout['uid'];
179  $backendLayout['icon'] = $data['icon'] ?: '';
180  // Convert PHP array back to plain TypoScript so it can be processed
181  $config = ‪ArrayUtility::flatten($data['config.']);
182  $backendLayout['config'] = '';
183  foreach ($config as $row => $value) {
184  $backendLayout['config'] .= $row . ' = ' . $value . "\r\n";
185  }
186  return $backendLayout;
187  }
188  return null;
189  }
190 
196  protected function ‪attachBackendLayout($backendLayout = null)
197  {
198  if ($backendLayout) {
199  $this->backendLayouts[$backendLayout['uid']] = $backendLayout;
200  }
201  }
202 
207  public function ‪addBackendLayouts(‪DataProviderContext $dataProviderContext, ‪BackendLayoutCollection $backendLayoutCollection)
208  {
209  $this->‪generateBackendLayouts($dataProviderContext);
210  foreach ($this->backendLayouts as $backendLayoutConfig) {
211  $backendLayout = $this->‪createBackendLayout($backendLayoutConfig);
212  $backendLayoutCollection->‪add($backendLayout);
213  }
214  }
215 
223  public function ‪getBackendLayout($identifier, ‪$pageId)
224  {
225  $this->‪setPageId(‪$pageId);
226  $this->‪generateBackendLayouts();
227  $backendLayout = null;
228  if (array_key_exists($identifier, $this->backendLayouts)) {
229  return $this->‪createBackendLayout($this->backendLayouts[$identifier]);
230  }
231  return $backendLayout;
232  }
233 
240  protected function ‪createBackendLayout(array $data)
241  {
242  $backendLayout = ‪BackendLayout::create($data['uid'], $data['title'], $data['config']);
243  $backendLayout->setIconPath($this->‪getIconPath($data['icon']));
244  $backendLayout->setData($data);
245  return $backendLayout;
246  }
247 
254  protected function ‪getIconPath($icon)
255  {
256  $iconPath = '';
257  if (!empty($icon)) {
258  $iconPath = $icon;
259  }
260  return $iconPath;
261  }
262 }
‪TYPO3\CMS\Core\Utility\ArrayUtility\flatten
‪static array flatten(array $array, $prefix='', bool $keepDots=false)
Definition: ArrayUtility.php:486
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection
Definition: BackendLayoutCollection.php:22
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\setPageTsConfig
‪setPageTsConfig(array $pageTsConfig)
Definition: PageTsBackendLayoutDataProvider.php:92
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\generateBackendLayouts
‪generateBackendLayouts($dataProviderContext=null)
Definition: PageTsBackendLayoutDataProvider.php:150
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface
Definition: DataProviderInterface.php:23
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection\add
‪add(BackendLayout $backendLayout)
Definition: BackendLayoutCollection.php:69
‪TYPO3\CMS\Backend\Provider
Definition: PageTsBackendLayoutDataProvider.php:16
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\setPageId
‪setPageId($pageId)
Definition: PageTsBackendLayoutDataProvider.php:112
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\generatePageTsConfig
‪generatePageTsConfig($dataProviderContext=null)
Definition: PageTsBackendLayoutDataProvider.php:133
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\generateBackendLayoutFromTsConfig
‪mixed generateBackendLayoutFromTsConfig($identifier, $data)
Definition: PageTsBackendLayoutDataProvider.php:170
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\addBackendLayouts
‪addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
Definition: PageTsBackendLayoutDataProvider.php:204
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider
Definition: PageTsBackendLayoutDataProvider.php:68
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\$backendLayouts
‪array $backendLayouts
Definition: PageTsBackendLayoutDataProvider.php:73
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\$pageId
‪int $pageId
Definition: PageTsBackendLayoutDataProvider.php:85
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\attachBackendLayout
‪attachBackendLayout($backendLayout=null)
Definition: PageTsBackendLayoutDataProvider.php:193
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout\create
‪static BackendLayout create($identifier, $title, $configuration)
Definition: BackendLayout.php:62
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\getBackendLayout
‪BackendLayout null getBackendLayout($identifier, $pageId)
Definition: PageTsBackendLayoutDataProvider.php:220
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id)
Definition: BackendUtility.php:698
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\getIconPath
‪string getIconPath($icon)
Definition: PageTsBackendLayoutDataProvider.php:251
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\getPageTsConfig
‪array getPageTsConfig()
Definition: PageTsBackendLayoutDataProvider.php:102
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\createBackendLayout
‪BackendLayout createBackendLayout(array $data)
Definition: PageTsBackendLayoutDataProvider.php:237
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:25
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\getPageId
‪int getPageId()
Definition: PageTsBackendLayoutDataProvider.php:122
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\$pageTsConfig
‪array $pageTsConfig
Definition: PageTsBackendLayoutDataProvider.php:79
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext
Definition: DataProviderContext.php:24