‪TYPO3CMS  9.5
PageTsBackendLayoutDataProvider.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
66 {
72  protected ‪$backendLayouts = [];
73 
79  protected ‪$pageTsConfig = [];
80 
86  protected ‪$pageId = 0;
87 
93  protected function ‪setPageTsConfig(array ‪$pageTsConfig)
94  {
95  $this->pageTsConfig = ‪$pageTsConfig;
96  }
97 
103  protected function ‪getPageTsConfig()
104  {
105  return ‪$this->pageTsConfig;
106  }
107 
113  protected function ‪setPageId(‪$pageId)
114  {
115  $this->pageId = (int)‪$pageId;
116  }
117 
123  protected function ‪getPageId()
124  {
125  return (int)‪$this->pageId;
126  }
127 
134  protected function ‪generatePageTsConfig($dataProviderContext = null)
135  {
136  if ($dataProviderContext === null) {
137  ‪$pageId = $this->‪getPageId();
138  ‪$pageId = ‪$pageId > 0 ? ‪$pageId : (int)GeneralUtility::_GP('id');
140  } else {
141  ‪$pageTsConfig = $dataProviderContext->getPageTsConfig();
142  }
143  $this->‪setPageTsConfig($pageTsConfig);
144  }
145 
151  protected function ‪generateBackendLayouts($dataProviderContext = null)
152  {
153  $this->‪generatePageTsConfig($dataProviderContext);
155  if (!empty(‪$pageTsConfig['mod.']['web_layout.']['BackendLayouts.'])) {
156  ‪$backendLayouts = (array)‪$pageTsConfig['mod.']['web_layout.']['BackendLayouts.'];
157  foreach (‪$backendLayouts as $identifier => $data) {
158  $backendLayout = $this->‪generateBackendLayoutFromTsConfig($identifier, $data);
159  $this->‪attachBackendLayout($backendLayout);
160  }
161  }
162  }
163 
171  protected function ‪generateBackendLayoutFromTsConfig($identifier, $data)
172  {
173  if (!empty($data['config.']['backend_layout.']) && is_array($data['config.']['backend_layout.'])) {
174  $backendLayout['uid'] = substr($identifier, 0, -1);
175  $backendLayout['title'] = $data['title'] ? $data['title'] : $backendLayout['uid'];
176  $backendLayout['icon'] = $data['icon'] ?: '';
177  // Convert PHP array back to plain TypoScript so it can be procecced
178  $config = ‪\TYPO3\CMS\Core\Utility\ArrayUtility::flatten($data['config.']);
179  $backendLayout['config'] = '';
180  foreach ($config as $row => $value) {
181  $backendLayout['config'] .= $row . ' = ' . $value . "\r\n";
182  }
183  return $backendLayout;
184  }
185  return null;
186  }
187 
193  protected function ‪attachBackendLayout($backendLayout = null)
194  {
195  if ($backendLayout) {
196  $this->backendLayouts[$backendLayout['uid']] = $backendLayout;
197  }
198  }
199 
204  public function ‪addBackendLayouts(‪DataProviderContext $dataProviderContext, ‪BackendLayoutCollection $backendLayoutCollection)
205  {
206  $this->‪generateBackendLayouts($dataProviderContext);
207  foreach ($this->backendLayouts as $backendLayoutConfig) {
208  $backendLayout = $this->‪createBackendLayout($backendLayoutConfig);
209  $backendLayoutCollection->‪add($backendLayout);
210  }
211  }
212 
220  public function ‪getBackendLayout($identifier, ‪$pageId)
221  {
222  $this->‪setPageId(‪$pageId);
223  $this->‪generateBackendLayouts();
224  $backendLayout = null;
225  if (array_key_exists($identifier, $this->backendLayouts)) {
226  return $this->‪createBackendLayout($this->backendLayouts[$identifier]);
227  }
228  return $backendLayout;
229  }
230 
237  protected function ‪createBackendLayout(array $data)
238  {
239  $backendLayout = ‪BackendLayout::create($data['uid'], $data['title'], $data['config']);
240  $backendLayout->setIconPath($this->‪getIconPath($data['icon']));
241  $backendLayout->setData($data);
242  return $backendLayout;
243  }
244 
251  protected function ‪getIconPath($icon)
252  {
253  $iconPath = '';
254  if (!empty($icon)) {
255  $iconPath = $icon;
256  }
257  return $iconPath;
258  }
259 }
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection
Definition: BackendLayoutCollection.php:21
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\setPageTsConfig
‪setPageTsConfig(array $pageTsConfig)
Definition: PageTsBackendLayoutDataProvider.php:90
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\generateBackendLayouts
‪generateBackendLayouts($dataProviderContext=null)
Definition: PageTsBackendLayoutDataProvider.php:148
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface
Definition: DataProviderInterface.php:22
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection\add
‪add(BackendLayout $backendLayout)
Definition: BackendLayoutCollection.php:68
‪TYPO3\CMS\Backend\Provider
Definition: PageTsBackendLayoutDataProvider.php:2
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\setPageId
‪setPageId($pageId)
Definition: PageTsBackendLayoutDataProvider.php:110
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\generatePageTsConfig
‪generatePageTsConfig($dataProviderContext=null)
Definition: PageTsBackendLayoutDataProvider.php:131
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\generateBackendLayoutFromTsConfig
‪mixed generateBackendLayoutFromTsConfig($identifier, $data)
Definition: PageTsBackendLayoutDataProvider.php:168
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\addBackendLayouts
‪addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
Definition: PageTsBackendLayoutDataProvider.php:201
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider
Definition: PageTsBackendLayoutDataProvider.php:66
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\$backendLayouts
‪array $backendLayouts
Definition: PageTsBackendLayoutDataProvider.php:71
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\$pageId
‪int $pageId
Definition: PageTsBackendLayoutDataProvider.php:83
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\attachBackendLayout
‪attachBackendLayout($backendLayout=null)
Definition: PageTsBackendLayoutDataProvider.php:190
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout\create
‪static BackendLayout create($identifier, $title, $configuration)
Definition: BackendLayout.php:52
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\getBackendLayout
‪BackendLayout null getBackendLayout($identifier, $pageId)
Definition: PageTsBackendLayoutDataProvider.php:217
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\getIconPath
‪string getIconPath($icon)
Definition: PageTsBackendLayoutDataProvider.php:248
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
Definition: BackendUtility.php:864
‪TYPO3\CMS\Core\Utility\ArrayUtility\flatten
‪static array flatten(array $array, $prefix='')
Definition: ArrayUtility.php:479
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\getPageTsConfig
‪array getPageTsConfig()
Definition: PageTsBackendLayoutDataProvider.php:100
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\createBackendLayout
‪BackendLayout createBackendLayout(array $data)
Definition: PageTsBackendLayoutDataProvider.php:234
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:21
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\getPageId
‪int getPageId()
Definition: PageTsBackendLayoutDataProvider.php:120
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Provider\PageTsBackendLayoutDataProvider\$pageTsConfig
‪array $pageTsConfig
Definition: PageTsBackendLayoutDataProvider.php:77
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext
Definition: DataProviderContext.php:21