/** * 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 * @return void */ protected function parseXML(\DOMDocument $dom, \DOMNode $reference) { $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': $this->replaceNodeWithFragment($dom, $node, $this->render('containerWrap')); $deleteNode = TRUE; break; case 'elements': $replaceNode = $this->getChildElements($dom); $node->parentNode->replaceChild($replaceNode, $node); break; case 'button': case 'fieldset': case 'form': case 'input': case 'optgroup': case 'select': $this->setAttributes($node); break; case 'label': if (!strstr(get_class($this), '_Additional_')) { if ($this->model->additionalIsSet($nodeName)) { $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('label')); } $deleteNode = TRUE; } else { if ($this->model->additionalIsSet($nodeName)) { $this->setAttributeWithValueofOtherAttribute($node, 'for', 'id'); } else { $deleteNode = TRUE; } } break; case 'legend': if (!strstr(get_class($this), '_Additional_')) { if ($this->model->additionalIsSet($nodeName)) { $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('legend')); } $deleteNode = TRUE; } break; case 'textarea': case 'option': $this->setAttributes($node); $appendNode = $dom->createTextNode($this->getElementData()); $node->appendChild($appendNode); break; case 'errorvalue': case 'labelvalue': case 'legendvalue': case 'mandatoryvalue': $replaceNode = $dom->createTextNode($this->getAdditionalValue()); $node->parentNode->insertBefore($replaceNode, $node); $deleteNode = TRUE; break; case 'mandatory': case 'error': if ($this->model->additionalIsSet($nodeName)) { $this->replaceNodeWithFragment($dom, $node, $this->getAdditional($nodeName)); } $deleteNode = TRUE; break; case 'content': case 'header': case 'textblock': $replaceNode = $dom->createTextNode($this->getElementData(FALSE)); $node->parentNode->insertBefore($replaceNode, $node); $deleteNode = TRUE; break; } break; } // Parse the child nodes of this node if available if ($node->hasChildNodes()) { $this->parseXML($dom, $node); } // 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); } } }
/** * 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 additionals from Element Typoscript configuration * * @param \TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $element Model object * @param array $arguments Arguments * @return void */ public function setAdditionals(\TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $element, array $arguments) { if (!empty($arguments)) { if ($element->hasAllowedAdditionals()) { $additionals = $element->getAllowedAdditionals(); foreach ($additionals as $additional) { if (isset($arguments[$additional . '.']) || isset($arguments[$additional])) { if (isset($arguments[$additional]) && isset($arguments[$additional . '.'])) { $value = $arguments[$additional . '.']; $type = $arguments[$additional]; } elseif (isset($arguments[$additional . '.'])) { $value = $arguments[$additional . '.']; $type = 'TEXT'; } else { $value['value'] = $arguments[$additional]; $type = 'TEXT'; } try { $element->setAdditional($additional, $type, $value); } catch (\Exception $exception) { throw new \RuntimeException('Cannot call user function for additional ' . ucfirst($additional), 1333754941); } } if (isset($arguments['layout.'][$additional]) && $element->additionalIsSet($additional)) { $layout = $arguments['layout.'][$additional]; $element->setAdditionalLayout($additional, $layout); } } } else { throw new \InvalidArgumentException('The element with id=' . $element->getElementId() . ' has no additionals set.', 1333754962); } } }