/** * Parse the XML of a view object, * check the node type and name * and add the proper XML part of child tags * to the \DOMDocument of the current tag * * @param \DOMDocument $dom * @param \DOMNode $reference Current XML structure * @param bool $emptyElement * @return bool */ protected function parseXML(\DOMDocument $dom, \DOMNode $reference, $emptyElement = FALSE) { $node = $reference->firstChild; while (!is_null($node)) { $deleteNode = FALSE; $nodeType = $node->nodeType; $nodeName = $node->nodeName; switch ($nodeType) { case XML_TEXT_NODE: break; case XML_ELEMENT_NODE: switch ($nodeName) { case 'containerWrap': $containerWrap = $this->render('containerWrap'); if ($containerWrap) { $this->replaceNodeWithFragment($dom, $node, $containerWrap); } else { $emptyElement = TRUE; } $deleteNode = TRUE; break; case 'elements': $replaceNode = $this->getChildElements($dom); if ($replaceNode) { $node->parentNode->replaceChild($replaceNode, $node); } else { $emptyElement = TRUE; } break; case 'label': if (!strrchr(get_class($this), 'AdditionalElement')) { if ($this->model->additionalIsSet($nodeName)) { $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('label')); } else { $replaceNode = $dom->createTextNode($this->model->getName()); $node->parentNode->insertBefore($replaceNode, $node); } } $deleteNode = TRUE; break; case 'legend': if (!strrchr(get_class($this), 'AdditionalElement')) { if ($this->model->additionalIsSet($nodeName)) { $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('legend')); } $deleteNode = TRUE; } break; case 'inputvalue': if (array_key_exists('checked', $this->model->getAllowedAttributes())) { if (!$this->model->hasAttribute('checked')) { $emptyElement = TRUE; } } elseif (array_key_exists('selected', $this->model->getAllowedAttributes()) && !$this->model->hasAttribute('selected')) { $emptyElement = TRUE; } else { $inputValue = $this->getInputValue(); if ($inputValue != '') { $replaceNode = $dom->createTextNode($this->getInputValue()); $node->parentNode->insertBefore($replaceNode, $node); } } $deleteNode = TRUE; break; case 'labelvalue': case 'legendvalue': $replaceNode = $dom->createTextNode($this->getAdditionalValue()); $node->parentNode->insertBefore($replaceNode, $node); $deleteNode = TRUE; break; } break; } // Parse the child nodes of this node if available if ($node->hasChildNodes()) { $emptyElement = $this->parseXML($dom, $node, $emptyElement); } // Get the current node for deletion if replaced. We need this because nextSibling can be empty $oldNode = $node; // Go to next sibling to parse $node = $node->nextSibling; // Delete the old node. This can only be done after going to the next sibling if ($deleteNode) { $oldNode->parentNode->removeChild($oldNode); } } return $emptyElement; }
/** * Set the attributes * * @param \TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $element Model object * @param array $arguments Arguments * @return void */ public function setAttributes(\TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $element, array $arguments) { if ($element->hasAllowedAttributes()) { $attributes = $element->getAllowedAttributes(); $mandatoryAttributes = $element->getMandatoryAttributes(); foreach ($attributes as $attribute => $value) { if (isset($arguments[$attribute]) || isset($arguments[$attribute . '.']) || in_array($attribute, $mandatoryAttributes) || !empty($value)) { if (!empty($arguments[$attribute])) { $value = $arguments[$attribute]; } elseif (!empty($arguments[$attribute . '.'])) { $value = $arguments[$attribute . '.']; } try { $element->setAttribute($attribute, $value); } catch (\Exception $exception) { throw new \RuntimeException('Cannot call user function for attribute ' . ucfirst($attribute), 1333754904); } } } } else { throw new \InvalidArgumentException('The element with id=' . $element->getElementId() . ' has no default attributes set.', 1333754925); } }