Update TXmlGuiPackageInstallationPlugin::setEntryData() implementation
authorMatthias Schmidt <gravatronics@live.com>
Sun, 24 Jun 2018 08:02:27 +0000 (10:02 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 24 Jun 2018 08:02:27 +0000 (10:02 +0200)
Rely on `TXmlGuiPackageInstallationPlugin::getElementData()`

See #2545

wcfsetup/install/files/lib/system/devtools/pip/TXmlGuiPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/ObjectTypePackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/PIPPackageInstallationPlugin.class.php

index 108fb87a9d8d5126ad6140a90dceb891eaeab9d9..18c9b4abb456a6341f8f00a7344ff3644bcfaf0e 100644 (file)
@@ -315,7 +315,7 @@ XML;
         * Adds the data of the pip entry with the given identifier into the
         * given form and returns `true`. If no entry with the given identifier
         * exists, `false` is returned.
-        *
+        * 
         * @param       string                  $identifier
         * @param       IFormDocument           $document
         * @return      bool
@@ -328,28 +328,23 @@ XML;
                        return false;
                }
                
-               $data = [];
-               /** @var \DOMNode $attribute */
-               foreach ($element->attributes as $attribute) {
-                       $data[$attribute->nodeName] = $attribute->nodeValue;
-               }
-               foreach ($element->childNodes as $childNode) {
-                       if ($childNode instanceof \DOMText) {
-                               $data['__value'] = $childNode->nodeValue;
-                       }
-                       else {
-                               $data[$childNode->nodeName] = $childNode->nodeValue;
-                       }
-               }
+               $data = $this->getElementData($element);
                
                /** @var IFormNode $node */
                foreach ($document->getIterator() as $node) {
                        if ($node instanceof IFormField && $node->isAvailable()) {
-                               $key = $node->getObjectProperty();
+                               $key = $node->getId();
                                
                                if (isset($data[$key])) {
                                        $node->value($data[$key]);
                                }
+                               else if ($node->getObjectProperty() !== $node->getId()) {
+                                       $key = $node->getObjectProperty();
+                                       
+                                       if (isset($data[$key])) {
+                                               $node->value($data[$key]);
+                                       }
+                               }
                        }
                }
                
index f5dce01d705f5a5348d574893ddbb6d97998a1fe..19463ffbf2858671a584e5acef3e7e9137b870e7 100644 (file)
@@ -178,7 +178,7 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                
                $className = $element->getElementsByTagName('classname')->item(0);
                if ($className) {
-                       $data['classname'] = $className->nodeValue;
+                       $data['className'] = $className->nodeValue;
                }
                
                $additionalData = [];
@@ -206,17 +206,16 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                $list->readObjects();
                
                foreach ($list as $definition) {
-                       $this->definitionNames[$definition->definitionName] = $definition->definitionName;
+                       $this->definitionNames[$definition->definitionID] = $definition->definitionName;
                        
                        if ($definition->interfaceName) {
-                               $this->definitionNamesWithInterface[$definition->definitionName] = $definition->interfaceName;
+                               $this->definitionNamesWithInterface[$definition->definitionID] = $definition->interfaceName;
                        }
                }
                
                // add default form fields
                $form->getNodeById('data')->appendChildren([
-                       SingleSelectionFormField::create('definitionName')
-                               ->objectProperty('definitionname')
+                       SingleSelectionFormField::create('definitionID')
                                ->label('wcf.acp.pip.objectType.definitionName')
                                ->description('<!-- will be replaced by JavaScript -->')
                                ->options($this->definitionNames)
@@ -229,10 +228,12 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                                ->required()
                                ->addValidator(self::getObjectTypeAlikeValueValidator('wcf.acp.pip.objectType.objectType'))
                                ->addValidator(new FormFieldValidator('uniqueness', function(TextFormField $formField) {
-                                       $definitionName = $formField->getDocument()->getNodeById('definitionName')->getValue();
-                                       if ($definitionName) {
+                                       $definitionID = $formField->getDocument()->getNodeById('definitionID')->getValue();
+                                       if ($definitionID) {
+                                               $definition = ObjectTypeCache::getInstance()->getDefinition($definitionID);
+                                               
                                                $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
-                                                       ObjectTypeCache::getInstance()->getDefinitionByName($definitionName)->definitionName,
+                                                       $definition->definitionName,
                                                        $formField->getValue()
                                                );
                                                
@@ -242,7 +243,7 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                                                if ($objectType !== null && (
                                                                $formField->getDocument()->getFormMode() === IFormDocument::FORM_MODE_CREATE ||
                                                                $this->editedEntry->getElementsByTagName('name')->item(0)->nodeValue !== $formField->getValue() ||
-                                                               $this->editedEntry->getElementsByTagName('definitionname')->item(0)->nodeValue !== $definitionName
+                                                               $this->editedEntry->getElementsByTagName('definitionname')->item(0)->nodeValue !== $definition->definitionName
                                                        )) {
                                                        $formField->addValidationError(
                                                                new FormFieldValidationError(
@@ -259,9 +260,9 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                                ->description('<!-- will be replaced by JavaScript -->')
                                ->required()
                                ->addValidator(new FormFieldValidator('implementsInterface', function(TextFormField $formField) {
-                                       $definitionName = $formField->getDocument()->getNodeById('definitionName')->getValue();
-                                       if ($definitionName) {
-                                               $definition = ObjectTypeCache::getInstance()->getDefinitionByName($definitionName);
+                                       $definitionID = $formField->getDocument()->getNodeById('definitionID')->getValue();
+                                       if ($definitionID) {
+                                               $definition = ObjectTypeCache::getInstance()->getDefinition($definitionID);
                                                
                                                if (!is_subclass_of($formField->getValue(), $definition->interfaceName)) {
                                                        $formField->addValidationError(
@@ -277,12 +278,12 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                ]);
                
                /** @var SingleSelectionFormField $definitionName */
-               $definitionName = $form->getNodeById('definitionName');
+               $definitionID = $form->getNodeById('definitionID');
                
                // add general field dependencies
                $form->getNodeById('className')->addDependency(
-                       ValueFormFieldDependency::create('definitionName')
-                               ->field($definitionName)
+                       ValueFormFieldDependency::create('definitionID')
+                               ->field($definitionID)
                                ->values(array_keys($this->definitionNamesWithInterface))
                );
                
@@ -646,15 +647,15 @@ XML;
         */
        public function getObjectTypeDefinitionDataContainer(IFormDocument $form, string $definitionName): FormContainer {
                /** @var SingleSelectionFormField $definitionNameField */
-               $definitionNameField = $form->getNodeById('definitionName');
+               $definitionIDField = $form->getNodeById('definitionID');
                
                $definitionPieces = explode('.', $definitionName);
                
                $formContainer = FormContainer::create(lcfirst(implode('', array_map('ucfirst', $definitionPieces))) . 'Fields')
                        ->label('wcf.acp.pip.objectType.' . $definitionName . '.data.title')
                        ->addDependency(
-                               ValueFormFieldDependency::create('definitionName')
-                                       ->field($definitionNameField)
+                               ValueFormFieldDependency::create('definitionID')
+                                       ->field($definitionIDField)
                                        ->values([$definitionName])
                        );
                
@@ -723,6 +724,11 @@ XML;
        protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
                $type = $document->createElement('type');
                foreach ($form->getData()['data'] as $key => $value) {
+                       if ($key === 'definitionID') {
+                               $key = 'definitionname';
+                               $value = ObjectTypeCache::getInstance()->getDefinition($value)->definitionName;
+                       }
+                       
                        if ($value !== '') {
                                if (is_string($value)) {
                                        $type->appendChild($document->createElement($key, $this->getAutoCdataValue($value)));
index 4a79e10a96069d56d36dcb268411d36544ec35d7..45bdc07d6e1b0c87713e7165da6cfce22f0be4d0 100644 (file)
@@ -136,7 +136,6 @@ class PIPPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                                })),
                        
                        ClassNameFormField::create()
-                               ->objectProperty('__value')
                                ->required()
                                ->implementedInterface(IPackageInstallationPlugin::class)
                ]);