f6b3586b725a9d7ea37b9757090dd90d60456879
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Confirmation / Element / Container.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Patrick Broens (patrick@patrickbroens.nl)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Abstract class for the form element containers (FORM and FIELDSET) view
27 *
28 * @author Patrick Broens <patrick@patrickbroens.nl>
29 * @package TYPO3
30 * @subpackage form
31 */
32 class tx_form_View_Confirmation_Element_Container extends tx_form_View_Confirmation_Element_Abstract {
33
34 /**
35 * Default layout of the container
36 *
37 * @var string
38 */
39 protected $containerWrap = '
40 <ol>
41 <elements />
42 </ol>
43 ';
44
45 /**
46 * Constructor
47 *
48 * @param object $model Model for this element
49 * @return void
50 */
51 public function __construct($model) {
52 parent::__construct($model);
53 }
54
55 /**
56 * Get the child objects
57 * and render them as document fragment
58 *
59 * @param DOMDocument $dom DOMDocument
60 * @return DOMDocumentFragment
61 */
62 public function getChildElements(DOMDocument $dom) {
63 $modelChildren = $this->model->getElements();
64 $documentFragment = NULL;
65 foreach ($modelChildren as $key => $modelChild) {
66 $child = $this->createChildElementFromModel($modelChild);
67
68 if ($child) {
69 if ($child->noWrap() === TRUE) {
70 $childNode = $child->render();
71 } else {
72 $childNode = $child->render('elementWrap');
73 if ($childNode) {
74 $childNode->setAttribute('class', $child->getElementWrapId());
75 }
76 }
77 if ($childNode) {
78 $importedNode = $dom->importNode($childNode, TRUE);
79 if (!$documentFragment) {
80 $documentFragment = $dom->createDocumentFragment();
81 }
82 $documentFragment->appendChild($importedNode);
83 }
84 }
85 }
86 return $documentFragment;
87 }
88
89 /**
90 * Create child object from the classname of the model
91 *
92 * @param object $modelChild The childs model
93 * @return object
94 */
95 public function createChildElementFromModel($modelChild) {
96 $childElement = NULL;
97
98 $class = tx_form_Common::getInstance()->getLastPartOfClassName($modelChild);
99 $className = 'tx_form_View_Confirmation_Element_' . ucfirst($class);
100
101 if (class_exists($className)) {
102 $childElement = t3lib_div::makeInstance($className, $modelChild);
103 }
104
105 return $childElement;
106 }
107 }
108 ?>