Improve code for better IDE code analysis
authorMatthias Schmidt <gravatronics@live.com>
Fri, 13 Jul 2018 07:32:41 +0000 (09:32 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 13 Jul 2018 07:32:41 +0000 (09:32 +0200)
See #2545

12 files changed:
wcfsetup/install/files/lib/system/devtools/pip/TXmlGuiPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/ACLOptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/ACPSearchProviderPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/CoreObjectPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/MediaProviderPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/ObjectTypeDefinitionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/ObjectTypePackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/TemplateListenerPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/UserProfileMenuPackageInstallationPlugin.class.php

index eaf339118fd8cad737a981837c3bcc3bcf38cdd6..9012bbfe8579de07617f034ffcee6d54ae6000cc 100644 (file)
@@ -21,6 +21,8 @@ use wcf\util\XML;
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    WoltLabSuite\Core\System\Devtools\Pip
  * @since      3.2
+ * 
+ * @property   PackageInstallationDispatcher|DevtoolsPackageInstallationDispatcher     $installation
  */
 trait TXmlGuiPackageInstallationPlugin {
        /**
index 1113d20b62feeb087c07589431923aef7a21659b..ec9d39875576a2bf7f71a865b0dd329e1c451d7e 100644 (file)
@@ -12,6 +12,7 @@ use wcf\system\devtools\pip\IDevtoolsPipEntryList;
 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
 use wcf\system\exception\SystemException;
+use wcf\system\form\builder\container\FormContainer;
 use wcf\system\form\builder\field\dependency\ValueFormFieldDependency;
 use wcf\system\form\builder\field\SingleSelectionFormField;
 use wcf\system\form\builder\field\TextFormField;
@@ -422,7 +423,10 @@ class ACLOptionPackageInstallationPlugin extends AbstractOptionPackageInstallati
                                }
                        }));
                
-               $form->getNodeById('data')->appendChildren([$nameFormField, $objectTypeFormField]);
+               /** @var FormContainer $dataContainer */
+               $dataContainer = $form->getNodeById('data');
+               
+               $dataContainer->appendChildren([$nameFormField, $objectTypeFormField]);
                
                if ($this->entryType === 'options') {
                        $categoryList = new ACLOptionCategoryList();
@@ -455,7 +459,7 @@ class ACLOptionPackageInstallationPlugin extends AbstractOptionPackageInstallati
                                                        ->values([$objectType])
                                        );
                                        
-                                       $form->getNodeById('data')->appendChild($categoryNameField);
+                                       $dataContainer->appendChild($categoryNameField);
                                }
                        }
                }
index 0ae3fb86c5cd250dfcb21e3156b7e7a95df89bda..f8a3a3f135e41b832295635692ae7a004b78ee76 100644 (file)
@@ -235,14 +235,15 @@ class ACPSearchProviderPackageInstallationPlugin extends AbstractXMLPackageInsta
         * @since       3.2
         */
        protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
+               $data = $form->getData()['data'];
+               
                $acpSearchProvider = $document->createElement('acpsearchprovider');
-               $acpSearchProvider->setAttribute('name', $form->getNodeById('providerName')->getSaveValue());
-               $acpSearchProvider->appendChild($document->createElement('classname', $form->getNodeById('className')->getSaveValue()));
+               $acpSearchProvider->setAttribute('name', $data['providerName']);
+               $acpSearchProvider->appendChild($document->createElement('classname', $data['classname']));
                
                /** @var IntegerFormField $showOrder */
-               $showOrder = $form->getNodeById('showOrder');
-               if ($showOrder->getSaveValue()) {
-                       $acpSearchProvider->appendChild($document->createElement('showorder', (string) $showOrder->getSaveValue()));
+               if (!empty($data['showOrder'])) {
+                       $acpSearchProvider->appendChild($document->createElement('showorder', (string) $data['showorder']));
                }
                
                $document->getElementsByTagName('import')->item(0)->appendChild($acpSearchProvider);
index aa62c244660fc412bcc62f678d75c85b11b8b10e..f9f82c5c84c82f915935d54c9ed2563074a8b41a 100644 (file)
@@ -165,9 +165,11 @@ class CoreObjectPackageInstallationPlugin extends AbstractXMLPackageInstallation
         * @since       3.2
         */
        protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
+               $data = $form->getData()['data'];
+               
                $coreObject = $document->createElement($this->tagName);
                
-               $coreObject->appendChild($document->createElement('objectname', $form->getNodeById('objectName')->getSaveValue()));
+               $coreObject->appendChild($document->createElement('objectname', $data['objectname']));
                
                $document->getElementsByTagName('import')->item(0)->appendChild($coreObject);
                
index bb8ab37279b06515e90a2cc129810b52429b9bfd..6a9be2a007c2c07e8e014567580198df719ecafb 100644 (file)
@@ -7,6 +7,7 @@ use wcf\system\cache\builder\BBCodeMediaProviderCacheBuilder;
 use wcf\system\devtools\pip\IDevtoolsPipEntryList;
 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
+use wcf\system\form\builder\container\FormContainer;
 use wcf\system\form\builder\field\ClassNameFormField;
 use wcf\system\form\builder\field\MultilineTextFormField;
 use wcf\system\form\builder\field\TextFormField;
@@ -108,7 +109,10 @@ class MediaProviderPackageInstallationPlugin extends AbstractXMLPackageInstallat
         * @since       3.2
         */
        public function addFormFields(IFormDocument $form) {
-               $form->getNodeById('data')->appendChildren([
+               /** @var FormContainer $dataContainer */
+               $dataContainer = $form->getNodeById('data');
+               
+               $dataContainer->appendChildren([
                        TextFormField::create('name')
                                ->label('wcf.acp.pip.mediaProvider.name')
                                ->description('wcf.acp.pip.mediaProvider.name.description')
@@ -159,7 +163,10 @@ class MediaProviderPackageInstallationPlugin extends AbstractXMLPackageInstallat
                                ->label('wcf.acp.pip.mediaProvider.html')
                                ->description('wcf.acp.pip.mediaProvider.html.description')
                                ->addValidator(new FormFieldValidator('noClassName', function(MultilineTextFormField $formField) {
-                                       if ($formField->getSaveValue() && $formField->getDocument()->getNodeById('className')->getSaveValue()) {
+                                       /** @var ClassNameFormField $className */
+                                       $className = $formField->getDocument()->getNodeById('className');
+                                       
+                                       if ($formField->getSaveValue() && $className->getSaveValue()) {
                                                $formField->addValidationError(
                                                        new FormFieldValidationError(
                                                                'className',
@@ -238,27 +245,27 @@ class MediaProviderPackageInstallationPlugin extends AbstractXMLPackageInstallat
         * @since       3.2
         */
        protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
+               $data = $form->getData()['data'];
+               
                $provider = $document->createElement($this->tagName);
-               $provider->setAttribute('name', $form->getNodeById('name')->getSaveValue());
+               $provider->setAttribute('name', $data['name']);
                
-               $provider->appendChild($document->createElement('title', $form->getNodeById('title')->getSaveValue()));
+               $provider->appendChild($document->createElement('title', $data['title']));
                
                $regex = $document->createElement('regex');
                $regex->appendChild($document->createCDATASection(
-                       StringUtil::escapeCDATA(StringUtil::unifyNewlines($form->getNodeById('regex')->getSaveValue()))
+                       StringUtil::escapeCDATA(StringUtil::unifyNewlines($data['regex']))
                ));
                $provider->appendChild($regex);
                
-               $html = $form->getNodeById('html')->getSaveValue();
-               if ($html) {
-                       $htmlElement = $document->createElement('regex');
-                       $htmlElement->appendChild($document->createCDATASection(StringUtil::escapeCDATA($html)));
+               if (!empty($data['html'])) {
+                       $htmlElement = $document->createElement('html');
+                       $htmlElement->appendChild($document->createCDATASection(StringUtil::escapeCDATA($data['html'])));
                        $provider->appendChild($htmlElement);
                }
                
-               $className = $form->getNodeById('className')->getSaveValue();
-               if ($className) {
-                       $provider->appendChild($document->createElement('className', $className));
+               if (!empty($data['className'])) {
+                       $provider->appendChild($document->createElement('className', $data['className']));
                }
                
                $document->getElementsByTagName('import')->item(0)->appendChild($provider);
index 7a972d0de5ef362a6b04796b3db084d072e3b2bc..c4161426b22e6c7ab2688cfa060e51855f0f1ca7 100644 (file)
@@ -13,6 +13,7 @@ use wcf\system\devtools\pip\IDevtoolsPipEntryList;
 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
 use wcf\system\exception\SystemException;
+use wcf\system\form\builder\container\FormContainer;
 use wcf\system\form\builder\field\BooleanFormField;
 use wcf\system\form\builder\field\dependency\NonEmptyFormFieldDependency;
 use wcf\system\form\builder\field\dependency\ValueFormFieldDependency;
@@ -306,7 +307,10 @@ class MenuPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
         * @since       3.2
         */
        public function addFormFields(IFormDocument $form) {
-               $form->getNodeById('data')->appendChildren([
+               /** @var FormContainer $dataContainer */
+               $dataContainer = $form->getNodeById('data');
+               
+               $dataContainer->appendChildren([
                        TextFormField::create('identifier')
                                ->label('wcf.acp.pip.menu.identifier')
                                ->description('wcf.acp.pip.menu.identifier.description')
index f2f05fa30ff2b07ec921ac92620ac35927329c81..d84a522550e673328b234f4230023d0143dfa257 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\object\type\ObjectTypeCache;
 use wcf\system\devtools\pip\IDevtoolsPipEntryList;
 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
+use wcf\system\form\builder\container\FormContainer;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
 use wcf\system\form\builder\field\validation\FormFieldValidator;
 use wcf\system\form\builder\field\TextFormField;
@@ -88,7 +89,10 @@ class ObjectTypeDefinitionPackageInstallationPlugin extends AbstractXMLPackageIn
         * @since       3.2
         */
        public function addFormFields(IFormDocument $form) {
-               $form->getNodeById('data')->appendChildren([
+               /** @var FormContainer $dataContainer */
+               $dataContainer = $form->getNodeById('data');
+               
+               $dataContainer->appendChildren([
                        TextFormField::create('name')
                                ->label('wcf.acp.pip.objectTypeDefinition.definitionName')
                                ->description('wcf.acp.pip.objectTypeDefinition.definitionName.description', ['project' => $this->installation->getProject()])
@@ -228,13 +232,13 @@ class ObjectTypeDefinitionPackageInstallationPlugin extends AbstractXMLPackageIn
         * @since       3.2
         */
        protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
+               $data = $form->getData()['data'];
+               
                $definition = $document->createElement('definition');
-               $definition->appendChild($document->createElement('name', $form->getNodeById('name')->getSaveValue()));
+               $definition->appendChild($document->createElement('name', $data['name']));
                
-               /** @var TextFormField $interfaceName */
-               $interfaceName = $form->getNodeById('interfaceName');
-               if ($interfaceName->getSaveValue()) {
-                       $definition->appendChild($document->createElement('interfacename', $interfaceName->getSaveValue()));
+               if (!empty($data['interfacename'])) {
+                       $definition->appendChild($document->createElement('interfacename', $data['interfacename']));
                }
                
                $import = $document->getElementsByTagName('import')->item(0);
index 1e5970e401f6330e644067498a28e685946be905..73f03c694f53ab2d4f6fe2bafa2baa2228af94b6 100644 (file)
@@ -219,7 +219,10 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                }
                
                // add default form fields
-               $form->getNodeById('data')->appendChildren([
+               /** @var FormContainer $dataContainer */
+               $dataContainer = $form->getNodeById('data');
+               
+               $dataContainer->appendChildren([
                        SingleSelectionFormField::create('definitionID')
                                ->label('wcf.acp.pip.objectType.definitionName')
                                ->description('<!-- will be replaced by JavaScript -->')
@@ -233,7 +236,10 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                                ->required()
                                ->addValidator(self::getObjectTypeAlikeValueValidator('wcf.acp.pip.objectType.objectType'))
                                ->addValidator(new FormFieldValidator('uniqueness', function(TextFormField $formField) {
-                                       $definitionID = $formField->getDocument()->getNodeById('definitionID')->getValue();
+                                       /** @var SingleSelectionFormField $definitionIDField */
+                                       $definitionIDField = $formField->getDocument()->getNodeById('definitionID');
+                                       
+                                       $definitionID = $definitionIDField->getSaveValue();
                                        if ($definitionID) {
                                                $definition = ObjectTypeCache::getInstance()->getDefinition($definitionID);
                                                
@@ -265,7 +271,10 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                                ->description('<!-- will be replaced by JavaScript -->')
                                ->required()
                                ->addValidator(new FormFieldValidator('implementsInterface', function(TextFormField $formField) {
-                                       $definitionID = $formField->getDocument()->getNodeById('definitionID')->getValue();
+                                       /** @var SingleSelectionFormField $definitionIDField */
+                                       $definitionIDField = $formField->getDocument()->getNodeById('definitionID');
+                                       
+                                       $definitionID = $definitionIDField->getSaveValue();
                                        if ($definitionID) {
                                                $definition = ObjectTypeCache::getInstance()->getDefinition($definitionID);
                                                
index 91d98929be7d5a4401116382b72e5485c84fc66b..8873e1882a5153201645585a1b735b3900016027 100644 (file)
@@ -526,7 +526,10 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                                        return $nestedOptions;
                                }, true)
                                ->addValidator(new FormFieldValidator('selfParent', function(SingleSelectionFormField $formField) {
-                                       if ($formField->getDocument()->getNodeById('identifier')->getValue() === $formField->getValue()) {
+                                       /** @var TextFormField $identifier */
+                                       $identifier = $formField->getDocument()->getNodeById('identifier');
+                                       
+                                       if ($identifier->getSaveValue() === $formField->getValue()) {
                                                $formField->addValidationError(
                                                        new FormFieldValidationError(
                                                                'selfParent',
@@ -647,7 +650,7 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                        'metaKeywords' => []
                ];
                
-               /** @var \DOMElement $title */
+               /** @var \DOMElement $name */
                foreach ($element->getElementsByTagName('name') as $name) {
                        $data['name'][LanguageFactory::getInstance()->getLanguageByCode($name->getAttribute('language'))->languageID] = $name->nodeValue;
                }
index 6c212a17030023b5701b3116ba877d36d3aa3fb0..37d8e9058dee483ed64a1ab418fa1e2dddf5ee2a 100644 (file)
@@ -11,6 +11,7 @@ use wcf\system\cache\builder\TemplateListenerCodeCacheBuilder;
 use wcf\system\devtools\pip\IDevtoolsPipEntryList;
 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
+use wcf\system\form\builder\container\FormContainer;
 use wcf\system\form\builder\field\dependency\ValueFormFieldDependency;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
 use wcf\system\form\builder\field\validation\FormFieldValidator;
@@ -178,7 +179,10 @@ class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstal
                
                $acpTemplateEvents = $getEvents($acpTemplateList);
                
-               $form->getNodeById('data')->appendChildren([
+               /** @var FormContainer $dataContainer */
+               $dataContainer = $form->getNodeById('data');
+               
+               $dataContainer->appendChildren([
                        TextFormField::create('name')
                                ->label('wcf.acp.pip.templateListener.name')
                                ->description('wcf.acp.pip.templateListener.name.description')
@@ -212,7 +216,7 @@ class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstal
                ]);
                
                foreach ($templateEvents as $templateName => $events) {
-                       $form->getNodeById('data')->appendChild(
+                       $dataContainer->appendChild(
                                SingleSelectionFormField::create($templateName . '_eventName')
                                        ->objectProperty('eventname')
                                        ->label('wcf.acp.pip.templateListener.eventName')
@@ -228,7 +232,7 @@ class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstal
                }
                
                foreach ($acpTemplateEvents as $templateName => $events) {
-                       $form->getNodeById('data')->appendChild(
+                       $dataContainer->appendChild(
                                SingleSelectionFormField::create('acp_' . $templateName . '_eventName')
                                        ->objectProperty('eventname')
                                        ->label('wcf.acp.pip.templateListener.eventName')
@@ -243,7 +247,7 @@ class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstal
                        );
                }
                
-               $form->getNodeById('data')->appendChildren([
+               $dataContainer->appendChildren([
                        SingleSelectionFormField::create('environment')
                                ->label('wcf.acp.pip.templateListener.environment')
                                ->description('wcf.acp.pip.templateListener.environment.description')
@@ -254,28 +258,40 @@ class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstal
                                ])
                                ->value('user')
                                ->addValidator(new FormFieldValidator('uniqueness', function(SingleSelectionFormField $formField) {
+                                       /** @var TextFormField $nameField */
+                                       $nameField = $formField->getDocument()->getNodeById('name');
+                                       
                                        $listenerList = new TemplateListenerList();
                                        $listenerList->getConditionBuilder()->add(
                                                'name = ?',
-                                               [$formField->getDocument()->getNodeById('name')->getSaveValue()]
+                                               [$nameField->getSaveValue()]
                                        );
                                        
                                        if ($formField->getSaveValue() === 'admin') {
-                                               $templateName = $formField->getDocument()->getNodeById('acpTemplateName')->getSaveValue();
-                                               $eventName = $formField->getDocument()->getNodeById('acp_' . $templateName . '_eventName')->getSaveValue();
+                                               /** @var SingleSelectionFormField $templateNameField */
+                                               $templateNameField = $formField->getDocument()->getNodeById('acpTemplateName');
+                                               
+                                               /** @var SingleSelectionFormField $eventNameField */
+                                               $eventNameField = $formField->getDocument()->getNodeById('acp_' . $templateNameField->getSaveValue() . '_eventName');
                                        }
                                        else {
-                                               $templateName = $formField->getDocument()->getNodeById('templateName')->getSaveValue();
-                                               $eventName = $formField->getDocument()->getNodeById($templateName . '_eventName')->getSaveValue();
+                                               /** @var SingleSelectionFormField $templateNameField */
+                                               $templateNameField = $formField->getDocument()->getNodeById('templateName');
+                                               
+                                               /** @var SingleSelectionFormField $eventNameField */
+                                               $eventNameField = $formField->getDocument()->getNodeById($templateNameField->getSaveValue() . '_eventName');
                                        }
                                        
+                                       $templateName = $templateNameField->getSaveValue();
+                                       $eventName = $eventNameField->getSaveValue();
+                                       
                                        $listenerList->getConditionBuilder()->add('templateName = ?', [$templateName]);
                                        
                                        $listenerList->getConditionBuilder()->add('eventName = ?', [$eventName]);
                                        $listenerList->getConditionBuilder()->add('environment = ?', [$formField->getSaveValue()]);
                                        
                                        if ($listenerList->countObjects() > 0) {
-                                               $formField->getDocument()->getNodeById('name')->addValidationError(
+                                               $nameField->addValidationError(
                                                        new FormFieldValidationError(
                                                                'notUnique',
                                                                'wcf.acp.pip.templateListener.name.error.notUnique'
@@ -382,24 +398,30 @@ class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstal
         * @since       3.2
         */
        protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
+               $data = $form->getData()['data'];
+               
                $listener = $document->createElement($this->tagName);
-               $listener->setAttribute('name', $form->getNodeById('name')->getSaveValue());
+               $listener->setAttribute('name', $data['name']);
                
-               $environment = $form->getNodeById('environment')->getSaveValue();
-               if ($environment === 'user') {
-                       $templateName = $form->getNodeById('templateName')->getSaveValue();
+               if ($data['environment'] === 'user') {
+                       $templateName = $data['templateName'];
                        
                        $listener->appendChild($document->createElement('templatename', $templateName));
-                       $listener->appendChild($document->createElement('eventname', $form->getNodeById($templateName . '_eventName')->getSaveValue()));
+                       $listener->appendChild($document->createElement('eventname', $data[$templateName . '_eventName']));
                }
                else {
-                       $templateName = $form->getNodeById('acpTemplateName')->getSaveValue();
+                       $templateName = $data['acpTemplateName'];
                        
                        $listener->appendChild($document->createElement('templatename', $templateName));
-                       $listener->appendChild($document->createElement('eventname', $form->getNodeById('acp_' . $templateName . '_eventName')->getSaveValue()));
+                       $listener->appendChild($document->createElement('eventname', $data['acp_' . $templateName . '_eventName']));
                }
-               $listener->appendChild($document->createElement('templatecode', '<![CDATA[' . StringUtil::unifyNewlines(StringUtil::escapeCDATA($form->getNodeById('templateCode')->getSaveValue())) . ']]>'));
-               $listener->appendChild($document->createElement('environment', $environment));
+               $listener->appendChild(
+                       $document->createElement(
+                               'templatecode',
+                               '<![CDATA[' . StringUtil::unifyNewlines(StringUtil::escapeCDATA($data['templatecode'])) . ']]>'
+                       )
+               );
+               $listener->appendChild($document->createElement('environment', $data['environment']));
                
                $document->getElementsByTagName('import')->item(0)->appendChild($listener);
                
index 00d1d5d26975dcf4ec069fd6663b57d2c8cb075a..8cea9da1b79b13f3be35984003d68f18393ae4b7 100644 (file)
@@ -9,6 +9,7 @@ use wcf\system\devtools\pip\IDevtoolsPipEntryList;
 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
 use wcf\system\exception\SystemException;
+use wcf\system\form\builder\container\FormContainer;
 use wcf\system\form\builder\field\OptionFormField;
 use wcf\system\form\builder\field\UserGroupOptionFormField;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
@@ -181,7 +182,10 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
         * @since       3.2
         */
        public function addFormFields(IFormDocument $form) {
-               $form->getNodeById('data')->appendChildren([
+               /** @var FormContainer $dataContainer */
+               $dataContainer = $form->getNodeById('data');
+               
+               $dataContainer->appendChildren([
                        TextFormField::create('name')
                                ->label('wcf.acp.pip.userNotificationEvent.name')
                                ->description('wcf.acp.pip.userNotificationEvent.name.description')
@@ -360,34 +364,28 @@ class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageI
         * @since       3.2
         */
        protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
-               $event = $document->createElement($this->tagName);
-               
-               $event->appendChild($document->createElement('name', $form->getNodeById('name')->getSaveValue()));
-               $event->appendChild($document->createElement('objecttype', $form->getNodeById('objectType')->getSaveValue()));
-               $event->appendChild($document->createElement('classname', $form->getNodeById('className')->getSaveValue()));
-               
-               /** @var ItemListFormField $options */
-               $options = $form->getNodeById('options');
-               if ($options->getSaveValue()) {
-                       $event->appendChild($document->createElement('options', $options->getSaveValue()));
-               }
+               $data = $form->getData()['data'];
                
-               /** @var ItemListFormField $permissions */
-               $permissions = $form->getNodeById('permissions');
-               if ($permissions->getSaveValue()) {
-                       $event->appendChild($document->createElement('permissions', $permissions->getSaveValue()));
-               }
+               $event = $document->createElement($this->tagName);
                
-               /** @var BooleanFormField $permissions */
-               $preset = $form->getNodeById('preset');
-               if ($preset->getSaveValue()) {
-                       $event->appendChild($document->createElement('preset', '1'));
+               foreach (['name', 'objecttype', 'classname'] as $element) {
+                       $event->appendChild(
+                               $document->createElement(
+                                       $element,
+                                       (string)$data[$element]
+                               )
+                       );
                }
                
-               /** @var BooleanFormField $permissions */
-               $presetMailNotificationType = $form->getNodeById('presetMailNotificationType');
-               if ($presetMailNotificationType->getSaveValue()) {
-                       $event->appendChild($document->createElement('presetmailnotificationtype', $presetMailNotificationType->getSaveValue()));
+               foreach (['options', 'permissions', 'preset', 'presetmailnotificationtype'] as $optionalElement) {
+                       if (!empty($data[$optionalElement])) {
+                               $event->appendChild(
+                                       $document->createElement(
+                                               $optionalElement,
+                                               (string)$data[$optionalElement]
+                                       )
+                               );
+                       }
                }
                
                $document->getElementsByTagName('import')->item(0)->appendChild($event);
index 4176df0a6a5af4c960ffffe173d953c3fa6930de..2532a3fa9d94de82de22cb669c7d1a83b1acb779 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\user\profile\menu\item\UserProfileMenuItemList;
 use wcf\system\devtools\pip\IDevtoolsPipEntryList;
 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
+use wcf\system\form\builder\container\FormContainer;
 use wcf\system\form\builder\field\OptionFormField;
 use wcf\system\form\builder\field\UserGroupOptionFormField;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
@@ -111,7 +112,10 @@ class UserProfileMenuPackageInstallationPlugin extends AbstractXMLPackageInstall
         * @since       3.2
         */
        public function addFormFields(IFormDocument $form) {
-               $form->getNodeById('data')->appendChildren([
+               /** @var FormContainer $dataContainer */
+               $dataContainer = $form->getNodeById('data');
+               
+               $dataContainer->appendChildren([
                        TextFormField::create('name')
                                ->label('wcf.acp.pip.userProfileMenu.name')
                                ->description('wcf.acp.pip.userProfileMenu.name.description')
@@ -258,26 +262,21 @@ class UserProfileMenuPackageInstallationPlugin extends AbstractXMLPackageInstall
         * @since       3.2
         */
        protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
-               $userProfileMenuItem = $document->createElement('userprofilemenuitem');
-               $userProfileMenuItem->setAttribute('name', $form->getNodeById('name')->getSaveValue());
-               $userProfileMenuItem->appendChild($document->createElement('classname', $form->getNodeById('className')->getSaveValue()));
-               
-               /** @var ItemListFormField $options */
-               $options = $form->getNodeById('options');
-               if ($options->getSaveValue()) {
-                       $userProfileMenuItem->appendChild($document->createElement('options', $options->getSaveValue()));
-               }
+               $data = $form->getData()['data'];
                
-               /** @var ItemListFormField $permissions */
-               $permissions = $form->getNodeById('permissions');
-               if ($permissions->getSaveValue()) {
-                       $userProfileMenuItem->appendChild($document->createElement('permissions', $permissions->getSaveValue()));
-               }
+               $userProfileMenuItem = $document->createElement('userprofilemenuitem');
+               $userProfileMenuItem->setAttribute('name', $data['name']);
+               $userProfileMenuItem->appendChild($document->createElement('classname', $data['className']));
                
-               /** @var IntegerFormField $showOrder */
-               $showOrder = $form->getNodeById('showOrder');
-               if ($showOrder->getSaveValue()) {
-                       $userProfileMenuItem->appendChild($document->createElement('showorder', (string) $showOrder->getSaveValue()));
+               foreach (['options', 'permissions', 'showorder'] as $optionalElement) {
+                       if (!empty($data[$optionalElement])) {
+                               $userProfileMenuItem->appendChild(
+                                       $document->createElement(
+                                               $optionalElement,
+                                               (string)$data[$optionalElement]
+                                       )
+                               );
+                       }
                }
                
                $import = $document->getElementsByTagName('import')->item(0);