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