[BUGFIX] Form localization depending on old class names
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Layout.php
1 <?php
2 namespace TYPO3\CMS\Form;
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
17 /**
18 * Layout class for the form elements
19 *
20 * @author Patrick Broens <patrick@patrickbroens.nl>
21 */
22 class Layout implements \TYPO3\CMS\Core\SingletonInterface {
23
24 /**
25 * Layout array from form configuration
26 *
27 * @var array
28 */
29 protected $layout = array();
30
31 /**
32 * Constructor
33 *
34 * @param $layout array Layout array from form configuration
35 */
36 public function __construct(array $layout = array()) {
37 $this->setLayout($layout);
38 }
39
40 /**
41 * Get the layout of the object
42 * Looks if there is an assigned layout by configuration of the element
43 * otherwise it will look if there is a layout set in the form configuration
44 * If both values are not assigned, take the default one
45 *
46 * @param string $elementName Type of object
47 * @param string $layoutDefault The default layout of the object
48 * @param string $layoutOverride Assigned layout to this object
49 * @return string The new layout if changed
50 */
51 public function getLayoutByObject($elementName, $layoutDefault, $layoutOverride = '') {
52 if (!empty($layoutOverride)) {
53 $layout = $layoutOverride;
54 } elseif (!empty($this->layout[$elementName])) {
55 $layout = $this->layout[$elementName];
56 } else {
57 $layout = $layoutDefault;
58 }
59 return $layout;
60 }
61
62 /**
63 * Overrides the default layout configuration for one or more elements
64 *
65 * @param array $layout The layout array
66 * @return \TYPO3\CMS\Form\Layout
67 */
68 public function setLayout(array $layout = array()) {
69 if (!empty($layout)) {
70 $this->layout = $layout;
71 }
72 return $this;
73 }
74
75 /**
76 * Overrides the default layout configuration for one element
77 * identified by the element name
78 *
79 * @param string $elementName Type of object
80 * @param string $layout XML containing layout for element
81 * @return \TYPO3\CMS\Form\Layout
82 */
83 public function setLayoutByElement($elementName, $layout) {
84 $this->layout[$elementName] = (string)$layout;
85 return $this;
86 }
87
88 }