Fix `MultipleSelectionFormField` save value handling
authorMatthias Schmidt <gravatronics@live.com>
Wed, 9 Oct 2019 17:03:27 +0000 (19:03 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 9 Oct 2019 17:03:27 +0000 (19:03 +0200)
As `MultipleSelectionFormField` works with arrays, it does not return an actual save value for the `data` subarray but must populate an additional entry in the parameters array itself.

wcfsetup/install/files/lib/system/form/builder/field/MultipleSelectionFormField.class.php
wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php

index 484fe87d79ac32fdb6bcfad7b54980d47058b5a1..bb5b5975ec5f21da2d5b49d035f5704590ba8154 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\system\form\builder\field;
+use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\system\form\builder\IFormDocument;
 
 /**
  * Implementation of a form field for selecting multiple values.
@@ -11,10 +13,9 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError;
  * @package    WoltLabSuite\Core\System\Form\Builder\Field
  * @since      5.2
  */
-class MultipleSelectionFormField extends AbstractFormField implements IFilterableSelectionFormField, IImmutableFormField, INullableFormField {
+class MultipleSelectionFormField extends AbstractFormField implements IFilterableSelectionFormField, IImmutableFormField {
        use TFilterableSelectionFormField;
        use TImmutableFormField;
-       use TNullableFormField;
        
        /**
         * @inheritDoc
@@ -26,6 +27,40 @@ class MultipleSelectionFormField extends AbstractFormField implements IFilterabl
         */
        protected $templateName = '__multipleSelectionFormField';
        
+       /**
+        * @inheritDoc
+        */
+       protected $value = [];
+       
+       /**
+        * @inheritDoc
+        */
+       public function hasSaveValue() {
+               return false;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function populate() {
+               parent::populate();
+               
+               $this->getDocument()->getDataHandler()->addProcessor(
+                       new CustomFormDataProcessor(
+                               'multiple',
+                               function(IFormDocument $document, array $parameters) {
+                                       if ($this->checkDependencies() && !empty($this->getValue())) {
+                                               $parameters[$this->getObjectProperty()] = $this->getValue();
+                                       }
+                                       
+                                       return $parameters;
+                               }
+                       )
+               );
+               
+               return $this;
+       }
+       
        /**
         * @inheritDoc
         */
index d0738ff9aff6209d2c9a743aa884a65bf6755ca7..a4831f92f31245802e3fb4503ab4e25b732f9413 100644 (file)
@@ -817,13 +817,13 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                        $form
                );
                
-               if (!empty($data['visibilityExceptions'])) {
+               if (!empty($formData['visibilityExceptions'])) {
                        $box->appendChild($document->createElement('visibleEverywhere', (string)($data['visibleEverywhere'] ?? 0)));
                        
                        $visibilityExceptions = $document->createElement('visibilityExceptions');
                        
-                       sort($data['visibilityExceptions']);
-                       foreach ($data['visibilityExceptions'] as $page) {
+                       sort($formData['visibilityExceptions']);
+                       foreach ($formData['visibilityExceptions'] as $page) {
                                $visibilityExceptions->appendChild($document->createElement('page', $page));
                        }
                        
index 9cd6cf34203128b8ee0ee6ab7fab06cc3532d551..fed23cc0fbdd6c6cc424f82e66042fecc35c3ed8 100644 (file)
@@ -555,10 +555,11 @@ class MenuPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                                }
                        }
                        
-                       if (!empty($formData['data']['boxVisibilityExceptions'])) {
+                       if (!empty($formData['boxVisibilityExceptions'])) {
                                $visibilityExceptions = $box->appendChild($document->createElement('visibilityExceptions'));
                                
-                               foreach ($formData['data']['boxVisibilityExceptions'] as $pageIdentifier) {
+                               sort($formData['boxVisibilityExceptions']);
+                               foreach ($formData['boxVisibilityExceptions'] as $pageIdentifier) {
                                        $visibilityExceptions->appendChild($document->createElement('page', $pageIdentifier));
                                }
                        }