b505897bdeb056c53e120233e4e0b6ccefe83f01
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Form / Element / ContainerElementView.php
1 <?php
2 namespace TYPO3\CMS\Form\View\Form\Element;
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 * Abstract class for the form element containers (FORM and FIELDSET) view
19 *
20 * @author Patrick Broens <patrick@patrickbroens.nl>
21 */
22 class ContainerElementView extends \TYPO3\CMS\Form\View\Form\Element\AbstractElementView {
23
24 /**
25 * Default layout of the container
26 *
27 * @var string
28 */
29 protected $containerWrap = '
30 <ol>
31 <elements />
32 </ol>
33 ';
34
35 /**
36 * Get the child objects
37 * and render them as document fragment
38 *
39 * @param \DOMDocument $dom DOMDocument
40 * @return \DOMDocumentFragment
41 */
42 public function getChildElements(\DOMDocument $dom) {
43 $modelChildren = $this->model->getElements();
44 $documentFragment = $dom->createDocumentFragment();
45 foreach ($modelChildren as $key => $modelChild) {
46 $child = $this->createChildElementFromModel($modelChild);
47 if ($child->noWrap() === TRUE) {
48 $childNode = $child->render();
49 } else {
50 $childNode = $child->render('elementWrap');
51 $class = '';
52 if (strlen($childNode->getAttribute('class')) > 0) {
53 $class = $childNode->getAttribute('class') . ' ';
54 }
55 $class .= $child->getElementWraps();
56 $childNode->setAttribute('class', $class);
57 }
58 $importedNode = $dom->importNode($childNode, TRUE);
59 $documentFragment->appendChild($importedNode);
60 }
61 return $documentFragment;
62 }
63
64 /**
65 * Create child object from the classname of the model
66 *
67 * @param object $modelChild The childs model
68 * @return \TYPO3\CMS\Form\View\Form\Element\AbstractElementView
69 */
70 public function createChildElementFromModel($modelChild) {
71 $childElement = NULL;
72 $class = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($modelChild);
73 $className = 'TYPO3\\CMS\\Form\\View\\Form\\Element\\' . ucfirst($class) . 'ElementView';
74 if (class_exists($className)) {
75 $childElement = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $modelChild);
76 }
77 return $childElement;
78 }
79
80 }