[TASK] Merge submodule dbal into core
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Layout.php
1 <?php
2 namespace TYPO3\CMS\Form;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2008-2013 Patrick Broens (patrick@patrickbroens.nl)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Layout class for the form elements
29 *
30 * @author Patrick Broens <patrick@patrickbroens.nl>
31 */
32 class Layout implements \TYPO3\CMS\Core\SingletonInterface {
33
34 /**
35 * Layout array from form configuration
36 *
37 * @var array
38 */
39 protected $layout = array();
40
41 /**
42 * Constructor
43 *
44 * @param $layout array Layout array from form configuration
45 */
46 public function __construct(array $layout = array()) {
47 $this->setLayout($layout);
48 }
49
50 /**
51 * Get the layout of the object
52 * Looks if there is an assigned layout by configuration of the element
53 * otherwise it will look if there is a layout set in the form configuration
54 * If both values are not assigned, take the default one
55 *
56 * @param string $elementName Type of object
57 * @param string $layoutDefault The default layout of the object
58 * @param string $layoutOverride Assigned layout to this object
59 * @return string The new layout if changed
60 */
61 public function getLayoutByObject($elementName, $layoutDefault, $layoutOverride = '') {
62 if (!empty($layoutOverride)) {
63 $layout = $layoutOverride;
64 } elseif (!empty($this->layout[$elementName])) {
65 $layout = $this->layout[$elementName];
66 } else {
67 $layout = $layoutDefault;
68 }
69 return $layout;
70 }
71
72 /**
73 * Overrides the default layout configuration for one or more elements
74 *
75 * @param array $layout The layout array
76 * @return \TYPO3\CMS\Form\Layout
77 */
78 public function setLayout(array $layout = array()) {
79 if (!empty($layout)) {
80 $this->layout = $layout;
81 }
82 return $this;
83 }
84
85 /**
86 * Overrides the default layout configuration for one element
87 * identified by the element name
88 *
89 * @param string $elementName Type of object
90 * @param string $layout XML containing layout for element
91 * @return \TYPO3\CMS\Form\Layout
92 */
93 public function setLayoutByElement($elementName, $layout) {
94 $this->layout[$elementName] = (string) $layout;
95 return $this;
96 }
97
98 }
99
100 ?>