[BUGFIX] Form: Add more more semantic classes for elements
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Form / Element / Container.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 Patrick Broens (patrick@patrickbroens.nl)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Abstract class for the form element containers (FORM and FIELDSET) view
27 *
28 * @author Patrick Broens <patrick@patrickbroens.nl>
29 * @package TYPO3
30 * @subpackage form
31 */
32 class tx_form_View_Form_Element_Container extends tx_form_View_Form_Element_Abstract {
33 /**
34 * Default layout of the container
35 *
36 * @var string
37 */
38 protected $containerWrap = '
39 <ol>
40 <elements />
41 </ol>
42 ';
43
44 /**
45 * Get the child objects
46 * and render them as document fragment
47 *
48 * @param DOMDocument $dom DOMDocument
49 * @return DOMDocumentFragment
50 */
51 public function getChildElements(DOMDocument $dom) {
52 $modelChildren = $this->model->getElements();
53 $documentFragment = $dom->createDocumentFragment();
54 foreach ($modelChildren as $key => $modelChild) {
55 $child = $this->createChildElementFromModel($modelChild);
56 if ($child->noWrap() === TRUE) {
57 $childNode = $child->render();
58 } else {
59 $childNode = $child->render('elementWrap');
60 $childNode->setAttribute('class', $child->getElementWraps());
61 }
62 $importedNode = $dom->importNode($childNode, TRUE);
63 $documentFragment->appendChild($importedNode);
64 }
65 return $documentFragment;
66 }
67
68 /**
69 * Create child object from the classname of the model
70 *
71 * @param object $modelChild The childs model
72 * @return tx_form_View_Form_Element_Abstract
73 */
74 public function createChildElementFromModel($modelChild) {
75 $childElement = NULL;
76
77 $class = tx_form_Common::getInstance()->getLastPartOfClassName($modelChild);
78 $className = 'tx_form_View_Form_Element_' . ucfirst($class);
79
80 if (class_exists($className)) {
81 $childElement = t3lib_div::makeInstance($className, $modelChild);
82 }
83
84 return $childElement;
85 }
86 }
87 ?>