Commit a5697586 authored by Oliver Hader's avatar Oliver Hader Committed by Oliver Hader
Browse files

[FEATURE] Introduce backend layout data providers

Backend layouts are currently stored in the database as
regular records. Since extension cannot ship their specific
backend layout definitions, data providers become handy in
providing the accordant information taken from e.g. static
files in the file system.

Data providers can be registered like shown in the follow and
need to be implement DataProviderInterface of the namespace
TYPO3\CMS\Backend\View\BackendLayout:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']
	['BackendLayoutDataProvider'][$_EXTKEY] = 'Classname';

A DataProviderContext object is used to transport submitted
data (e.g. table or field name) to the accordant data providers.

Change-Id: I2e3d39e720c6d1bffa9a586148f0eea4cab0210e
Resolves: #37208
Documentation: #52809
Releases: 6.2
Reviewed-on: https://review.typo3.org/11804
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
parent f58a27c8
......@@ -199,11 +199,12 @@ class MoveElementController {
// SHARED page-TSconfig settings.
$modTSconfig_SHARED = BackendUtility::getModTSconfig($this->page_id, 'mod.SHARED');
$colPosArray = GeneralUtility::callUserFunction('TYPO3\\CMS\\Backend\\View\\BackendLayoutView->getColPosListItemsParsed', $this->page_id, $this);
$colPosIds = array();
foreach ($colPosArray as $colPos) {
$colPosList .= $colPosList != '' ? ',' . $colPos[1] : $colPos[1];
$colPosIds[] = $colPos[1];
}
// Removing duplicates, if any
$colPosList = implode(',', array_unique(GeneralUtility::intExplode(',', $colPosList)));
$colPosList = implode(',', array_unique($colPosIds));
// Adding parent page-header and the content element columns from position-map:
$code = $hline . '<br />';
$code .= $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
......
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/***************************************************************
* Copyright notice
*
* (c) 2013 Oliver Hader <oliver.hader@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Class to represent a backend layout.
*
* @author Oliver Hader <oliver.hader@typo3.org>
*/
class BackendLayout {
/**
* @var string
*/
protected $identifier;
/**
* @var string
*/
protected $title;
/**
* @var string
*/
protected $description;
/**
* @var string
*/
protected $iconPath;
/**
* @var string
*/
protected $configuration;
/**
* @var array
*/
protected $data;
/**
* @param string $identifier
* @param string $title
* @param string $configuration
* @return BackendLayout
*/
static public function create($identifier, $title, $configuration) {
return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Backend\\View\\BackendLayout\\BackendLayout',
$identifier,
$title,
$configuration
);
}
/**
* @param string $identifier
* @param string $title
* @param string $configuration
*/
public function __construct($identifier, $title, $configuration) {
$this->setIdentifier($identifier);
$this->setTitle($title);
$this->setConfiguration($configuration);
}
/**
* @return string
*/
public function getIdentifier() {
return $this->identifier;
}
/**
* @param string $identifier
* @throws \UnexpectedValueException
*/
public function setIdentifier($identifier) {
if (strpos($identifier, '__') !== FALSE) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597630
);
}
$this->identifier = $identifier;
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* @return string
*/
public function getDescription() {
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description) {
$this->description = $description;
}
/**
* @return string
*/
public function getIconPath() {
return $this->iconPath;
}
/**
* @param string $iconPath
*/
public function setIconPath($iconPath) {
$this->iconPath = $iconPath;
}
/**
* @return string
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* @param string $configuration
*/
public function setConfiguration($configuration) {
$this->configuration = $configuration;
}
/**
* @return array
*/
public function getData() {
return $this->data;
}
/**
* @param array $data
*/
public function setData(array $data) {
$this->data = $data;
}
}
\ No newline at end of file
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/***************************************************************
* Copyright notice
*
* (c) 2013 Oliver Hader <oliver.hader@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Collection of backend layouts.
*
* @author Oliver Hader <oliver.hader@typo3.org>
*/
class BackendLayoutCollection {
/**
* @var string
*/
protected $identifier;
/**
* @var array|BackendLayout[]
*/
protected $backendLayouts = array();
/**
* @param string $identifier
*/
public function __construct($identifier) {
$this->setIdentifier($identifier);
}
/**
* @return string
*/
public function getIdentifier() {
return $this->identifier;
}
/**
* @param string $identifier
* @throws \UnexpectedValueException
*/
public function setIdentifier($identifier) {
if (strpos($identifier, '__') !== FALSE) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597631
);
}
$this->identifier = $identifier;
}
/**
* Adds a backend layout to this collection.
*
* @param BackendLayout $backendLayout
* @throws \LogicException
*/
public function add(BackendLayout $backendLayout) {
$identifier = $backendLayout->getIdentifier();
if (strpos($identifier, '__') !== FALSE) {
throw new \UnexpectedValueException(
'BackendLayout Identifier "' . $identifier . '" must not contain "__"',
1381597628
);
}
if (isset($this->backendLayouts[$identifier])) {
throw new \LogicException(
'Backend Layout ' . $identifier . ' is already defined',
1381559376
);
}
$this->backendLayouts[$identifier] = $backendLayout;
}
/**
* Gets a backend layout by (regular) identifier.
*
* @param string $identifier
* @return NULL|BackendLayout
*/
public function get($identifier) {
$backendLayout = NULL;
if (isset($this->backendLayouts[$identifier])) {
$backendLayout = $this->backendLayouts[$identifier];
}
return $backendLayout;
}
/**
* Gets all backend layouts in this collection.
*
* @return array|BackendLayout[]
*/
public function getAll() {
return $this->backendLayouts;
}
}
\ No newline at end of file
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/***************************************************************
* Copyright notice
*
* (c) 2013 Oliver Hader <oliver.hader@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Collection of backend layout data providers.
*
* @author Oliver Hader <oliver.hader@typo3.org>
*/
class DataProviderCollection implements \TYPO3\CMS\Core\SingletonInterface {
/**
* @var array|DataProviderInterface[]
*/
protected $dataProviders = array();
/**
* @var array
*/
protected $results = array();
/**
* Adds a data provider to this collection.
*
* @param string $identifier
* @param string|object $classNameOrObject
* @throws \UnexpectedValueException
* @throws \LogicException
*/
public function add($identifier, $classNameOrObject) {
if (strpos($identifier, '__') !== FALSE) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597629
);
}
if (is_object($classNameOrObject)) {
$className = get_class($classNameOrObject);
$dataProvider = $classNameOrObject;
} else {
$className = $classNameOrObject;
$dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($classNameOrObject);
}
if (!$dataProvider instanceof DataProviderInterface) {
throw new \LogicException(
$className . ' must implement interface TYPO3\\CMS\\Backend\\View\\BackendLayout\\DataProviderInterface',
1381269811
);
}
$this->dataProviders[$identifier] = $dataProvider;
}
/**
* Gets all backend layout collections and thus, all
* backend layouts. Each data provider returns its own
* backend layout collection.
*
* @param DataProviderContext $dataProviderContext
* @return array|BackendLayoutCollection[]
*/
public function getBackendLayoutCollections(DataProviderContext $dataProviderContext) {
$result = array();
foreach ($this->dataProviders as $identifier => $dataProvider) {
$backendLayoutCollection = $this->createBackendLayoutCollection($identifier);
$dataProvider->addBackendLayouts($dataProviderContext, $backendLayoutCollection);
$result[$identifier] = $backendLayoutCollection;
}
return $result;
}
/**
* Gets a backend layout by a combined identifier, which is
* e.g. "myextension_regular" and "myextension" is the identifier
* of the accordant data provider and "regular" the identifier of
* the accordant backend layout.
*
* @param string $combinedIdentifier
* @return NULL|BackendLayout
*/
public function getBackendLayout($combinedIdentifier) {
$backendLayout = NULL;
if (strpos($combinedIdentifier, '__') === FALSE) {
$dataProviderIdentifier = 'default';
$backendLayoutIdentifier = $combinedIdentifier;
} else {
list($dataProviderIdentifier, $backendLayoutIdentifier) = explode('__', $combinedIdentifier, 2);
}
if (isset($this->dataProviders[$dataProviderIdentifier])) {
$backendLayout = $this->dataProviders[$dataProviderIdentifier]->getBackendLayout($backendLayoutIdentifier);
}
return $backendLayout;
}
/**
* Creates a new backend layout collection.
*
* @param string $identifier
* @return BackendLayoutCollection
*/
protected function createBackendLayoutCollection($identifier) {
return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Backend\\View\\BackendLayout\\BackendLayoutCollection', $identifier
);
}
}
\ No newline at end of file
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/***************************************************************
* Copyright notice
*
* (c) 2013 Oliver Hader <oliver.hader@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Context that is forwared to backend layout data providers.
*
* @author Oliver Hader <oliver.hader@typo3.org>
*/
class DataProviderContext implements \TYPO3\CMS\Core\SingletonInterface {
/**
* @var integer
*/
protected $pageId;
/**
* @var string
*/
protected $tableName;
/**
* @var string
*/
protected $fieldName;
/**
* @var array
*/
protected $data;
/**
* @var array
*/
protected $pageTsConfig;
/**
* @return integer
*/
public function getPageId() {
return $this->pageId;
}
/**
* @param integer $pageId
* @return DataProviderContext
*/
public function setPageId($pageId) {
$this->pageId = $pageId;
return $this;
}
/**
* @return string
*/
public function getTableName() {
return $this->tableName;
}
/**
* @param string $tableName
* @return DataProviderContext
*/
public function setTableName($tableName) {
$this->tableName = $tableName;
return $this;
}
/**
* @return string
*/
public function getFieldName() {
return $this->fieldName;
}
/**
* @param string $fieldName
* @return DataProviderContext
*/
public function setFieldName($fieldName) {
$this->field = $fieldName;
return $this;
}
/**
* @return array
*/
public function getData() {
return $this->data;
}
/**
* @param array $data
* @return DataProviderContext
*/
public function setData(array $data) {
$this->data = $data;
return $this;