[CLEANUP] Improve the @param/@return/@var PHPDoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Mail / Html / Element / ContainerElementView.php
1 <?php
2 namespace TYPO3\CMS\Form\View\Mail\Html\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\View\Mail\Html\Additional\AdditionalElementView;
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\Mail\Html\Element\AbstractElementView {
24
25 /**
26 * Default layout of the container
27 *
28 * @var string
29 */
30 protected $containerWrap = '
31 <tbody>
32 <elements />
33 </tbody>
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 = NULL;
46 foreach ($modelChildren as $key => $modelChild) {
47 $child = $this->createChildElementFromModel($modelChild);
48 if ($child) {
49 if ($child->noWrap() === TRUE) {
50 $childNode = $child->render();
51 } else {
52 $childNode = $child->render('elementWrap');
53 if ($childNode) {
54 $childNode->setAttribute('class', $child->getElementWraps());
55 }
56 }
57 if ($childNode) {
58 $importedNode = $dom->importNode($childNode, TRUE);
59 if (!$documentFragment) {
60 $documentFragment = $dom->createDocumentFragment();
61 }
62 $documentFragment->appendChild($importedNode);
63 }
64 }
65 }
66 return $documentFragment;
67 }
68
69 /**
70 * Create child object from the classname of the model
71 *
72 * @param AdditionalElementView $modelChild The childs model
73 * @return \TYPO3\CMS\Form\View\Mail\Html\Element\AbstractElementView
74 */
75 public function createChildElementFromModel($modelChild) {
76 $childElement = NULL;
77 $class = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($modelChild);
78 $className = 'TYPO3\\CMS\\Form\\View\\Mail\\Html\\Element\\' . ucfirst($class) . 'ElementView';
79 if (class_exists($className)) {
80 $childElement = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $modelChild);
81 }
82 return $childElement;
83 }
84
85 }