Automatic sorting causes problems if PIPs assume that the order in the XML file represents an implicit order in which the elements should be shown.
See #2545
foreach ($this->getProjectXmls() as $xml) {
$document = $xml->getDocument();
- $newElement = $this->writeEntry($document, $form);
+ $newElement = $this->createXmlElement($document, $form);
+ $this->insertNewXmlElement($xml, $newElement);
$this->saveObject($newElement);
- $this->sortDocument($document);
-
// TODO: while creating/testing the gui, write into a temporary file
// $xml->write($this->getXmlFileLocation($project));
$xml->write(substr($xml->getPath(), 0, -4) . '_tmp.xml');
foreach ($this->getProjectXmls() as $xml) {
$document = $xml->getDocument();
- // remove old element
- $element = $this->getElementByIdentifier($xml, $identifier);
- DOMUtil::removeNode($element);
-
// add updated element
- $newEntry = $this->writeEntry($document, $form);
+ $newElement = $this->createXmlElement($document, $form);
- $this->saveObject($newEntry, $element);
+ // replace old element
+ $element = $this->getElementByIdentifier($xml, $identifier);
+ DOMUtil::replaceElement($newElement, $element);
- $this->sortDocument($document);
+ $this->saveObject($newEntry, $element);
// TODO: while creating/testing the gui, write into a temporary file
// $xml->write($this->getXmlFileLocation($project));
$xml = $this->getProjectXml();
$document = $xml->getDocument();
- $newElement = $this->writeEntry($document, $form);
+ $newElement = $this->createXmlElement($document, $form);
+ $this->insertNewXmlElement($xml, $newElement);
$this->saveObject($newElement);
-
- $this->sortDocument($document);
/** @var DevtoolsProject $project */
$project = $this->installation->getProject();
$xml->write($project->path . ($project->getPackage()->package === 'com.woltlab.wcf' ? 'com.woltlab.wcf/' : '') . 'tmp_' . static::getDefaultFilename());
}
+ /**
+ * Creates a new XML element for the given document using the data provided
+ * by the given form and return the new dom element.
+ *
+ * @param \DOMDocument $document
+ * @param IFormDocument $form
+ * @return \DOMElement
+ */
+ abstract protected function createXmlElement(\DOMDocument $document, IFormDocument $form);
+
/**
* Edits the entry of this pip with the given identifier based on the data
* provided by the given form and returns the new identifier of the entry
$xml = $this->getProjectXml();
$document = $xml->getDocument();
- // remove old element
- $element = $this->getElementByIdentifier($xml, $identifier);
- DOMUtil::removeNode($element);
-
// add updated element
- $newEntry = $this->writeEntry($document, $form);
+ $newElement = $this->createXmlElement($document, $form);
- $this->saveObject($newEntry, $element);
+ // replace old element
+ $element = $this->getElementByIdentifier($xml, $identifier);
+ DOMUtil::replaceElement($element, $newElement, false);
- $this->sortDocument($document);
+ $this->saveObject($newElement, $element);
/** @var DevtoolsProject $project */
$project = $this->installation->getProject();
// $xml->write($this->getXmlFileLocation($project));
$xml->write($project->path . ($project->getPackage()->package === 'com.woltlab.wcf' ? 'com.woltlab.wcf/' : '') . 'tmp_' . static::getDefaultFilename());
- return $this->getElementIdentifier($newEntry);
+ return $this->getElementIdentifier($newElement);
}
/**
return $project->path . ($project->getPackage()->package === 'com.woltlab.wcf' ? 'com.woltlab.wcf/' : '') . static::getDefaultFilename();
}
+ /**
+ * Inserts the give new element into the given XML document.
+ *
+ * @param XML $xml XML document to which the element is added
+ * @param \DOMElement $newElement added new element
+ */
+ protected function insertNewXmlElement(XML $xml, \DOMElement $newElement) {
+ $xml->xpath()->query('/ns:data/ns:import')->item(0)->appendChild($newElement);
+ }
+
/**
* Saves an object represented by an XML element in the database by either
* creating a new element (if `$oldElement = null`) or updating an existing
$this->entryType = $entryType;
}
-
- /**
- * Sorts the entries of this pip that are represented by the given dom
- * document to achieve a deterministic order.
- *
- * @param \DOMDocument $document
- */
- abstract protected function sortDocument(\DOMDocument $document);
-
- /**
- * Sorts the given child nodes of all nodes in the given node list by
- * applying the given sort function on the child nodes.
- *
- * Internally, the old child nodes are removed and appended again in
- * the sorted order.
- *
- * @param \DOMNodeList $nodeList
- * @param callable $sortFunction
- */
- protected function sortChildNodes(\DOMNodeList $nodeList, callable $sortFunction) {
- /** @var \DOMElement $node */
- foreach ($nodeList as $node) {
- $childNodes = array_filter(iterator_to_array($node->childNodes), function($element) {
- return $element instanceof \DOMElement;
- });
-
- usort($childNodes, $sortFunction);
-
- // remove old nodes
- while ($node->hasChildNodes()) {
- $node->removeChild($node->firstChild);
- }
-
- // add sorted nodes
- foreach ($childNodes as $childNode) {
- $node->appendChild($childNode);
- }
- }
- }
-
- /**
- * Sorts the standard `import` and `delete` blocks and ensures that the
- * `import` block is before the `delete` block.
- *
- * @param \DOMDocument $document
- */
- protected function sortImportDelete(\DOMDocument $document) {
- switch ($document->documentElement->childNodes->length) {
- case 0:
- throw new \InvalidArgumentException('Empty xml document.');
-
- case 1:
- // nothing to sort
- break;
-
- case 2:
- $firstChild = $document->documentElement->firstChild;
- $lastChild = $document->documentElement->lastChild;
-
- if (!($firstChild->nodeName === 'import' && $lastChild->nodeName === 'delete') && !($firstChild->nodeName === 'delete' && $lastChild->nodeName === 'import')) {
- throw new \InvalidArgumentException('Invalid xml given.');
- }
-
- if ($document->documentElement->firstChild->nodeName !== 'import') {
- $firstChild = $document->documentElement->firstChild;
- $document->documentElement->removeChild($firstChild);
- $document->documentElement->appendChild($firstChild);
- }
- break;
-
- default:
- throw new \InvalidArgumentException('Xml document has more than two direct children.');
- }
- }
-
- /**
- * Writes a new entry into the xml structure represented by the given
- * dom document using the data provided by the given form and return
- * the new dom element.
- *
- * Note: Inserting at the correct position regarding sorting is irrelevant
- * as the dom document will be sorted after adding the entry.
- *
- * @param \DOMDocument $document
- * @param IFormDocument $form
- * @return \DOMElement
- */
- abstract protected function writeEntry(\DOMDocument $document, IFormDocument $form);
-
- /**
- * Returns a sort function for DOM elements using the list of attributes
- * and child elements by whose values the DOM elements are sorted.
- *
- * @param array $sortParameters
- * @return \Closure
- */
- public static function getSortFunction(array $sortParameters) {
- return function(\DOMElement $element1, \DOMElement $element2) use ($sortParameters) {
- foreach ($sortParameters as $sortParameter) {
- if (is_array($sortParameter)) {
- $isAttribute = !empty($sortParameter['isAttribute']);
- $name = $sortParameter['name'];
- $missingLast = !empty($sortParameter['missingLast']);
- }
- else {
- $isAttribute = false;
- $name = $sortParameter;
- $missingLast = true;
- }
-
- $value1 = $value2 = null;
- if ($isAttribute) {
- $value1 = $element1->getAttribute($name);
- $value2 = $element2->getAttribute($name);
- }
- else {
- $value1Node = $element1->getElementsByTagName($name)->item(0);
- if ($value1Node !== null) {
- $value1 = $value1Node->nodeValue;
- }
-
- $value2Node = $element2->getElementsByTagName($name)->item(0);
- if ($value2Node !== null) {
- $value2 = $value2Node->nodeValue;
- }
- }
-
- if ($value1 !== null) {
- if ($value2 !== null) {
- $compare = $value1 <=> $value2;
-
- if ($compare !== 0) {
- return $compare;
- }
- }
- else {
- return $missingLast ? -1 : 1;
- }
- }
- else if ($value2 !== null) {
- return $missingLast ? 1 : -1;
- }
- }
-
- return -1;
- };
- }
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- // do not sort options and categories as their position in the XML
- // file implies the order in which they are shown in the frontend
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData()['data'];
switch ($this->entryType) {
$category->appendChild($document->createElement('objecttype', $formData['objecttype']));
- $import = $document->getElementsByTagName('import')->item(0);
- $categories = $import->getElementsByTagName('categories')->item(0);
- if ($categories === null) {
- $categories = $document->createElement('categories');
- $import->appendChild($categories);
- }
-
- $categories->appendChild($category);
-
return $category;
case 'options':
$option->appendChild($document->createElement('categoryname', $formData['categoryname']));
}
- $import = $document->getElementsByTagName('import')->item(0);
- $options = $import->getElementsByTagName('options')->item(0);
- if ($options === null) {
- $options = $document->createElement('options');
- $import->appendChild($options);
- }
-
- $options->appendChild($option);
-
return $option;
}
* @inheritDoc
* @since 3.2
*/
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData()['data'];
- $menuItem = parent::writeEntry($document, $form);
+ $menuItem = parent::createXmlElement($document, $form);
if (isset($formData['icon'])) {
$menuItem->appendChild($document->createElement('icon', $formData['icon']));
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), function(\DOMElement $element1, \DOMElement $element2) {
- $showOrder1 = PHP_INT_MAX;
- if ($element1->getElementsByTagName('showorder')->length === 1) {
- $showOrder1 = $element1->getElementsByTagName('showorder')->item(0)->nodeValue;
- }
-
- $showOrder2 = PHP_INT_MAX;
- if ($element2->getElementsByTagName('showorder')->length === 1) {
- $showOrder2 = $element2->getElementsByTagName('showorder')->item(0)->nodeValue;
- }
-
- if ($showOrder1 !== $showOrder2) {
- return $showOrder1 > $showOrder2;
- }
-
- return strcmp(
- $element1->getAttribute('name'),
- $element2->getAttribute('name')
- );
- });
- $this->sortChildNodes($document->getElementsByTagName('delete'), function(\DOMElement $element1, \DOMElement $element2) {
- return strcmp(
- $element1->getAttribute('name'),
- $element2->getAttribute('name')
- );
- });
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$acpSearchProvider = $document->createElement($this->tagName);
$acpSearchProvider->appendChild($document->createElement('showorder', (string)$data['showorder']));
}
- $document->getElementsByTagName('import')->item(0)->appendChild($acpSearchProvider);
-
return $acpSearchProvider;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $menuStructureData = $this->getMenuStructureData();
- /** @var ACPMenuItem[][] $menuItemStructure */
- $menuItemStructure = $menuStructureData['structure'];
-
- $this->sortImportDelete($document);
-
- // build array containing the ACP menu items saved in the database
- // in the order as they would be displayed in the ACP
- $buildPositions = function($parent = '') use ($menuItemStructure, &$buildPositions) {
- $positions = [];
- foreach ($menuItemStructure[$parent] as $menuItem) {
- // only consider menu items of the current package for positions
- if ($menuItem->packageID === $this->installation->getPackageID()) {
- $positions[] = $menuItem->menuItem;
- }
-
- if (isset($menuItemStructure[$menuItem->menuItem])) {
- $positions = array_merge($positions, $buildPositions($menuItem->menuItem));
- }
- }
-
- return $positions;
- };
-
- // flip positions array so that the keys are the menu item names
- // and the values become the positions so that the array values
- // can be used in the sort function
- $positions = array_flip($buildPositions());
-
- $compareFunction = function(\DOMElement $element1, \DOMElement $element2) use ($positions) {
- return $positions[$element1->getAttribute('name')] <=> $positions[$element2->getAttribute('name')];
- };
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $compareFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $compareFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData()['data'];
$menuItem = $document->createElement($this->tagName);
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($menuItem);
-
return $menuItem;
}
}
use wcf\system\WCF;
use wcf\util\DirectoryUtil;
use wcf\util\StringUtil;
+use wcf\util\XML;
/**
* Abstract implementation of a package installation plugin for options.
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- // `<categories>` before `<options>`
- $compareFunction = function(\DOMElement $element1, \DOMElement $element2) {
- if ($element1->nodeName === 'categories') {
- return -1;
- }
- else if ($element2->nodeName === 'categories') {
- return 1;
- }
-
- return 0;
- };
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $compareFunction);
-
- $xpath = new \DOMXPath($document);
- $xpath->registerNamespace('ns', $document->documentElement->getAttribute('xmlns'));
-
- // sort categories
- $categoryOrder = array_flip(array_keys($this->getSortedCategories()));
-
- $this->sortChildNodes(
- $xpath->query('/ns:data/ns:import/ns:categories'),
- function(\DOMElement $category1, \DOMElement $category2) use ($categoryOrder) {
- return $categoryOrder[$category1->getAttribute('name')] <=> $categoryOrder[$category2->getAttribute('name')];
- }
- );
-
- // sort options
- $this->sortChildNodes(
- $xpath->query('/ns:data/ns:import/ns:options'),
- function(\DOMElement $option1, \DOMElement $option2) use ($categoryOrder) {
- $category1 = $option1->getElementsByTagName('categoryname')->item(0)->nodeValue;
- $category2 = $option2->getElementsByTagName('categoryname')->item(0)->nodeValue;
-
- if ($category1 !== 'hidden') {
- if ($category2 !== 'hidden') {
- $cmp = $categoryOrder[$category1] <=> $categoryOrder[$category2];
-
- if ($cmp === 0) {
- $showOrder1 = $option1->getElementsByTagName('showorder')->item(0);
- $showOrder2 = $option2->getElementsByTagName('showorder')->item(0);
-
- if ($showOrder1 !== null) {
- if ($showOrder2 !== null) {
- return $showOrder1->nodeValue <=> $showOrder2->nodeValue;
- }
-
- return -1;
- }
- else if ($showOrder2 !== null) {
- return 1;
- }
-
- return strcmp($option1->nodeValue, $option2->nodeValue);
- }
-
- return $cmp;
- }
-
- return -1;
- }
- else if ($category2 !== 'hidden') {
- return 1;
- }
-
- return strcmp($option1->nodeValue, $option2->nodeValue);
- }
- );
-
- // sort deleted elements
- $this->sortChildNodes($document->getElementsByTagName('delete'), function(\DOMElement $element1, \DOMElement $element2) use ($categoryOrder) {
- if ($element1->nodeName === 'optioncategory') {
- if ($element2->nodeName === 'optioncategory') {
- return $categoryOrder[$element1->getAttribute('name')] <=> $categoryOrder[$element2->getAttribute('name')];
- }
- else {
- return -1;
- }
- }
- else if ($element2->nodeName === 'optioncategory') {
- return 1;
- }
-
- // two options
- return strcmp($element1->nodeName, $element2->nodeName);
- });
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData()['data'];
- $xpath = new \DOMXPath($document);
- $xpath->registerNamespace('ns', $document->documentElement->getAttribute('xmlns'));
-
switch ($this->entryType) {
case 'categories':
$category = $document->createElement('category');
}
}
- $xpath->query('/ns:data/ns:import/ns:options')->item(0)->appendChild($option);
-
return $option;
default:
throw new \LogicException('Unreachable');
}
}
+
+ /**
+ * @inheritDoc
+ * @since 3.2
+ */
+ protected function insertNewXmlElement(XML $xml, \DOMElement $newElement) {
+ switch ($this->entryType) {
+ case 'categories':
+ $categories = $xml->xpath()->query('/ns:data/ns:import/ns:categories')->item(0);
+ if ($categories === null) {
+ $categories = $xml->getDocument()->createElement('categories');
+ $xml->xpath()->query('/ns:data/ns:import')->item(0)->appendChild($categories);
+ }
+
+ $categories->appendChild($newElement);
+
+ break;
+
+ case 'options':
+ $options = $xml->xpath()->query('/ns:data/ns:import/ns:options')->item(0);
+ if ($options === null) {
+ $categories = $xml->getDocument()->createElement('options');
+ $xml->xpath()->query('/ns:data/ns:import')->item(0)->appendChild($categories);
+ }
+
+ $options->appendChild($newElement);
+
+ break;
+ }
+ }
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $compareFunction = static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $compareFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $compareFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$bbcode = $document->createElement($this->tagName);
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($bbcode);
-
return $bbcode;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'identifier'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData();
$data = $formData['data'];
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($box);
-
return $box;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction([
- 'actionclassname',
- 'showorder',
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData();
$data = $formData['data'];
$pages->appendChild($document->createElement('page', $page));
}
- $document->getElementsByTagName('import')->item(0)->appendChild($clipboardAction);
-
return $clipboardAction;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction(['objectname']);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$coreObject = $document->createElement($this->tagName);
$coreObject->appendChild($document->createElement('objectname', $data['objectname']));
- $document->getElementsByTagName('import')->item(0)->appendChild($coreObject);
-
return $coreObject;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ],
- 'classname'
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData();
$formData = $form->getData()['data'];
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($cronjob);
-
return $cronjob;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$eventListener = $document->createElement($this->tagName);
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($eventListener);
-
return $eventListener;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $sortFunction = static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]);
-
- $this->sortChildNodes($document->childNodes, $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('category'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$languageCode = $document->documentElement->getAttribute('languagecode');
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$provider = $document->createElement($this->tagName);
$provider->appendChild($document->createElement('className', $data['className']));
}
- $document->getElementsByTagName('import')->item(0)->appendChild($provider);
-
return $provider;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- // do not support imported menu items automatically
-
- $this->sortChildNodes($document->getElementsByTagName('delete'), static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'identifier'
- ]
- ]));
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData();
$data = $formData['data'];
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($menuItem);
-
return $menuItem;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'identifier'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData();
if ($formData['data']['identifier'] === 'com.woltlab.wcf.MainMenu') {
$menu->appendChild($box);
}
- $document->getElementsByTagName('import')->item(0)->appendChild($menu);
-
return $menu;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), static::getSortFunction(['name']));
- $this->sortChildNodes($document->getElementsByTagName('delete'), static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]));
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$definition = $document->createElement($this->tagName);
$definition->appendChild($document->createElement('interfacename', $data['interfacename']));
}
- $import = $document->getElementsByTagName('import')->item(0);
- $import->appendChild($definition);
-
return $definition;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), static::getSortFunction(['definitionname', 'name']));
-
- $this->sortChildNodes($document->getElementsByTagName('import')->item(0)->childNodes, function(\DOMElement $element1, \DOMElement $element2) {
- // force `definitionname` to be at the first position
- if ($element1->nodeName === 'definitionname') {
- return -1;
- }
- else if ($element2->nodeName === 'definitionname') {
- return 1;
- }
- // force `name` to be at the second position
- else if ($element1->nodeName === 'name') {
- return -1;
- }
- else if ($element2->nodeName === 'name') {
- return 1;
- }
- // force `classname` to be at the third position
- else if ($element1->nodeName === 'classname') {
- return -1;
- }
- else if ($element2->nodeName === 'classname') {
- return 1;
- }
- else {
- // the rest is sorted by node name
- return strcmp($element1->nodeName, $element2->nodeName);
- }
- });
-
- $this->sortChildNodes($document->getElementsByTagName('delete'), static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]));
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$type = $document->createElement($this->tagName);
foreach ($form->getData()['data'] as $key => $value) {
if ($key === 'definitionID') {
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($type);
-
return $type;
}
* @since 3.2
*/
protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
- $option = parent::writeEntry($document, $form);
+ $option = parent::createXmlElement($document, $form);
$formData = $form->getData()['data'];
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
+ $data = $form->getData()['data'];
- $sortFunction = static::getSortFunction([
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
- /** @var TextFormField $className */
- $className = $form->getNodeById('className');
- /** @var TextFormField $pluginName */
- $pluginName = $form->getNodeById('pluginName');
-
- $pip = $document->createElement($this->tagName, $className->getSaveValue());
- $pip->setAttribute('name', $pluginName->getSaveValue());
-
- $document->getElementsByTagName('import')->item(0)->appendChild($pip);
+ $pip = $document->createElement($this->tagName, $data['className']);
+ $pip->setAttribute('name', $data['name']);
return $pip;
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = function(\DOMElement $element1, \DOMElement $element2) {
- return strcmp(
- $element1->getAttribute('identifier'),
- $element2->getAttribute('identifier')
- );
- };
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData();
$data = $formData['data'];
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($page);
-
return $page;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $compareFunction = static::getSortFunction([
- 'showOrder',
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $compareFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $compareFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
- $bbcode = $document->createElement($this->tagName);
- $bbcode->setAttribute('name', $data['name']);
+ $smiley = $document->createElement($this->tagName);
+ $smiley->setAttribute('name', $data['name']);
foreach (['title', 'path', 'path2x'] as $element) {
- $bbcode->appendChild($document->createElement($element, $data[$element]));
+ $smiley->appendChild($document->createElement($element, $data[$element]));
}
if ($data['aliases'] !== '') {
$aliases->appendChild($document->createCDATASection(
StringUtil::escapeCDATA(StringUtil::unifyNewlines($data['aliases']))
));
- $bbcode->appendChild($aliases);
+ $smiley->appendChild($aliases);
}
if ($data['showorder'] !== null) {
- $bbcode->appendChild($document->createElement('showorder', $data['showorder']));
+ $smiley->appendChild($document->createElement('showorder', $data['showorder']));
}
- $document->getElementsByTagName('import')->item(0)->appendChild($bbcode);
-
- return $bbcode;
+ return $smiley;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction(['templatename', 'eventname', 'environment']);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$listener = $document->createElement($this->tagName);
$templateCode->appendChild($document->createCDATASection(StringUtil::unifyNewlines(StringUtil::escapeCDATA($data['templatecode']))));
$listener->appendChild($templateCode);
- $document->getElementsByTagName('import')->item(0)->appendChild($listener);
-
return $listener;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
- $option = parent::writeEntry($document, $form);
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
+ $option = parent::createXmlElement($document, $form);
$formData = $form->getData()['data'];
* @inheritDoc
* @since 3.2
*/
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$formData = $form->getData()['data'];
- $menuItem = parent::writeEntry($document, $form);
+ $menuItem = parent::createXmlElement($document, $form);
if (!empty($formData['classname'])) {
$menuItem->appendChild($document->createElement('classname', $formData['classname']));
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction(['objecttype', 'name']);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$event = $document->createElement($this->tagName);
}
}
- $document->getElementsByTagName('import')->item(0)->appendChild($event);
-
return $event;
}
}
* @inheritDoc
* @since 3.2
*/
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
- $option = parent::writeEntry($document, $form);
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
+ $option = parent::createXmlElement($document, $form);
$formData = $form->getData()['data'];
* @inheritDoc
* @since 3.2
*/
- protected function sortDocument(\DOMDocument $document) {
- $this->sortImportDelete($document);
-
- $sortFunction = static::getSortFunction([
- 'showorder',
- [
- 'isAttribute' => 1,
- 'name' => 'name'
- ]
- ]);
-
- $this->sortChildNodes($document->getElementsByTagName('import'), $sortFunction);
- $this->sortChildNodes($document->getElementsByTagName('delete'), $sortFunction);
- }
-
- /**
- * @inheritDoc
- * @since 3.2
- */
- protected function writeEntry(\DOMDocument $document, IFormDocument $form) {
+ protected function createXmlElement(\DOMDocument $document, IFormDocument $form) {
$data = $form->getData()['data'];
$userProfileMenuItem = $document->createElement($this->tagName);
}
}
- $import = $document->getElementsByTagName('import')->item(0);
- $import->appendChild($userProfileMenuItem);
-
return $userProfileMenuItem;
}
}