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