ItemListFormField implements IMultipleFormField instead of IMaximumFormField
authorMatthias Schmidt <gravatronics@live.com>
Thu, 22 Aug 2019 15:37:08 +0000 (17:37 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 22 Aug 2019 15:41:12 +0000 (17:41 +0200)
com.woltlab.wcf/templates/__itemListFormField.tpl
wcfsetup/install/files/acp/templates/__itemListFormField.tpl
wcfsetup/install/files/lib/system/form/builder/field/ItemListFormField.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 5d95bdb34f9a7eceb294cfd84b081726b3d68f0c..7c43cc017a172a470e866c9e5fe7ed1f787280ff 100644 (file)
@@ -8,7 +8,7 @@
                        '{@$field->getPrefixedId()}',
                        [{if $field->getValue() !== null && !$field->getValue()|empty}{implode from=$field->getValue() item=item}'{@$item|encodeJS}'{/implode}{/if}],
                        {
-                               maxItems: {if $field->getMaximum() !== null}{@$field->getMaximum()}{else}-1{/if},
+                               maxItems: {if $field->allowsMultiple()}{@$field->getMaximumMultiples()}{else}1{/if},
                                submitFieldName: '{@$field->getPrefixedId()}[]'
                        }
                );
index 5d95bdb34f9a7eceb294cfd84b081726b3d68f0c..7c43cc017a172a470e866c9e5fe7ed1f787280ff 100644 (file)
@@ -8,7 +8,7 @@
                        '{@$field->getPrefixedId()}',
                        [{if $field->getValue() !== null && !$field->getValue()|empty}{implode from=$field->getValue() item=item}'{@$item|encodeJS}'{/implode}{/if}],
                        {
-                               maxItems: {if $field->getMaximum() !== null}{@$field->getMaximum()}{else}-1{/if},
+                               maxItems: {if $field->allowsMultiple()}{@$field->getMaximumMultiples()}{else}1{/if},
                                submitFieldName: '{@$field->getPrefixedId()}[]'
                        }
                );
index a2e598999e33af59a7593cff489ae3f560ce0c94..a82bde0ff4b2050b05c6cc5a8aaeef0670fb59a7 100644 (file)
@@ -14,12 +14,10 @@ use wcf\util\ArrayUtil;
  * @package    WoltLabSuite\Core\System\Form\Builder\Field
  * @since      5.2
  */
-class ItemListFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField, IMaximumFormField {
+class ItemListFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField, IMultipleFormField {
        use TAutoFocusFormField;
        use TImmutableFormField;
-       use TMaximumFormField {
-               maximum as protected traitMaximum;
-       }
+       use TMultipleFormField;
        
        /**
         * @inheritDoc
@@ -64,6 +62,13 @@ class ItemListFormField extends AbstractFormField implements IAutoFocusFormField
         */
        const SAVE_VALUE_TYPE_SSV = 'ssv';
        
+       /**
+        * @inheritDoc
+        */
+       public function __construct() {
+               $this->multiple();
+       }
+       
        /**
         * @inheritDoc
         */
@@ -109,19 +114,6 @@ class ItemListFormField extends AbstractFormField implements IAutoFocusFormField
                return $this->getSaveValueType() !== self::SAVE_VALUE_TYPE_ARRAY;
        }
        
-       /**
-        * @inheritDoc
-        */
-       public function maximum($maximum = null) {
-               $this->traitMaximum($maximum);
-               
-               if ($maximum <= 0) {
-                       throw new \InvalidArgumentException("The maximum number of items has to be positive.");
-               }
-               
-               return $this;
-       }
-       
        /**
         * @inheritDoc
         */
@@ -236,17 +228,25 @@ class ItemListFormField extends AbstractFormField implements IAutoFocusFormField
         */
        public function validate() {
                if (is_array($this->getValue())) {
-                       if ($this->getMaximum() !== null && count($this->getValue()) > $this->getMaximum()) {
+                       if ($this->getMinimumMultiples() > 0 && count($this->getValue()) < $this->getMinimumMultiples()) {
                                $this->addValidationError(new FormFieldValidationError(
-                                       'maximumItems',
-                                       'wcf.form.field.itemList.error.maximumItems',
+                                       'minimumMultiples',
+                                       'wcf.form.field.itemList.error.minimumMultiples',
                                        [
-                                               'items' => count($this->getValue()),
-                                               'maximumItems' => $this->getMaximum()
+                                               'minimumCount' => $this->getMinimumMultiples(),
+                                               'count' => count($this->getValue())
+                                       ]
+                               ));
+                       }
+                       else if ($this->getMaximumMultiples() !== IMultipleFormField::NO_MAXIMUM_MULTIPLES && count($this->getValue()) > $this->getMaximumMultiples()) {
+                               $this->addValidationError(new FormFieldValidationError(
+                                       'maximumMultiples',
+                                       'wcf.form.field.itemList.error.maximumMultiples',
+                                       [
+                                               'maximumCount' => $this->getMaximumMultiples(),
+                                               'count' => count($this->getValue())
                                        ]
                                ));
-                               
-                               return;
                        }
                        
                        $invalidItems = [];
index 34ef2900c9edb46f721975d0b565d739f6ebb431..121d696d32a243ebfd8f9d6b363160b6fee839e3 100644 (file)
@@ -3917,7 +3917,8 @@ Dateianhänge:
                <item name="wcf.form.field.date.error.format"><![CDATA[Der angegebene Wert hat ein ungültiges Format.]]></item>
                <item name="wcf.form.field.date.error.earliestDate"><![CDATA[Der angegebene Wert darf nicht früher sein als {$earliestDate}.]]></item>
                <item name="wcf.form.field.date.error.latestDate"><![CDATA[Der angegebene Wert darf nicht später sein als {$latestDate}.]]></item>
-               <item name="wcf.form.field.itemList.error.maximumItems"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} {#$items} Einträge angegebenen, die Maximalanzahl beträgt jedoch {#$maximumItems}.]]></item>
+               <item name="wcf.form.field.itemList.error.maximumMultiples"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du darfst{else}Sie dürfen{/if} nicht mehr als {#$maximumCount} {if $maximumCount == 1}Eintrag{else}Einträge{/if} angeben, es wurde{if $count != 1}n{/if} aber {#$count} {if $count == 1}Eintrag{else}Einträge{/if} angegeben.]]></item>
+               <item name="wcf.form.field.itemList.error.minimumMultiples"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du musst{else}Sie müssen{/if} zumindest {#$minimumCount} {if $minimumCount == 1}Eintrag{else}Einträge{/if} angeben, es wurde{if $count != 1}n{/if} aber nur {#$count} {if $count == 1}Eintrag{else}Einträge{/if} angegeben.]]></item>
        </category>
        <category name="wcf.image">
                <item name="wcf.image.coverPhoto"><![CDATA[Titelbild]]></item>
index 2714015cc3ef212f56b6483554a8d38b4c5399ca..0501592af818c6e8d8e1aedf62426268e481e249 100644 (file)
@@ -3863,7 +3863,8 @@ Attachments:
                <item name="wcf.form.field.date.error.format"><![CDATA[The format of the entered value is invalid.]]></item>
                <item name="wcf.form.field.date.error.earliestDate"><![CDATA[The entered value may not be earlier than {$earliestDate}.]]></item>
                <item name="wcf.form.field.date.error.latestDate"><![CDATA[The entered value may not be later than {$latestDate}.]]></item>
-               <item name="wcf.form.field.itemList.error.maximumItems"><![CDATA[You have entered {#$items} items but the maximum number of items is {#$maximumItems}.]]></item>
+               <item name="wcf.form.field.itemList.error.maximumMultiples"><![CDATA[You may not enter more than {#$maximumCount} {if $maximumCount == 1}entry{else}entries{/if} but {#$count} {if $count == 1}entry is{else}entries are{/if} given.]]></item>
+               <item name="wcf.form.field.itemList.error.minimumMultiples"><![CDATA[You have to entered at least {#$minimumCount} {if $minimumCount == 1}entry{else}entries{/if} but only {#$count} {if $count == 1}entry is{else}entries are{/if} given.]]></item>
        </category>
        <category name="wcf.image">
                <item name="wcf.image.coverPhoto"><![CDATA[Cover Photo]]></item>