528a02288b02bd8bd3425c742cd81ad3efe714db
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Confirmation / Element / ContainerElementView.php
1 <?php
2 namespace TYPO3\CMS\Form\View\Confirmation\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\Confirmation\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 = NULL;
45 foreach ($modelChildren as $key => $modelChild) {
46 $child = $this->createChildElementFromModel($modelChild);
47 if ($child) {
48 if ($child->noWrap() === TRUE) {
49 $childNode = $child->render();
50 } else {
51 $childNode = $child->render('elementWrap');
52 if ($childNode) {
53 $childNode->setAttribute('class', $child->getElementWraps());
54 }
55 }
56 if ($childNode) {
57 $importedNode = $dom->importNode($childNode, TRUE);
58 if (!$documentFragment) {
59 $documentFragment = $dom->createDocumentFragment();
60 }
61 $documentFragment->appendChild($importedNode);
62 }
63 }
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 \TYPO3\CMS\Form\View\Confirmation\Element\AbstractElementView
73 */
74 public function createChildElementFromModel($modelChild) {
75 $childElement = NULL;
76 $class = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($modelChild);
77 $className = 'TYPO3\\CMS\\Form\\View\\Confirmation\\Element\\' . ucfirst($class) . 'ElementView';
78 if (class_exists($className)) {
79 $childElement = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $modelChild);
80 }
81 return $childElement;
82 }
83
84 }