'{@$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},
submitFieldName: '{@$field->getPrefixedId()}[]'
}
);
'{@$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},
submitFieldName: '{@$field->getPrefixedId()}[]'
}
);
* @package WoltLabSuite\Core\System\Form\Builder\Field
* @since 5.2
*/
-class ItemListFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField {
+class ItemListFormField extends AbstractFormField implements IAutoFocusFormField, IImmutableFormField, IMaximumFormField {
use TAutoFocusFormField;
use TImmutableFormField;
+ use TMaximumFormField {
+ maximum as protected traitMaximum;
+ }
/**
* @inheritDoc
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
*/
*/
public function validate() {
if (is_array($this->getValue())) {
+ if ($this->getMaximum() !== null && count($this->getValue()) > $this->getMaximum()) {
+ $this->addValidationError(new FormFieldValidationError(
+ 'maximumItems',
+ 'wcf.form.field.itemList.error.maximumItems',
+ [
+ 'items' => count($this->getValue()),
+ 'maximumItems' => $this->getMaximum()
+ ]
+ ));
+
+ return;
+ }
+
$invalidItems = [];
foreach ($this->getValue() as $item) {
switch ($this->getSaveValueType()) {
// com.woltlab.wcf.message
$this->getObjectTypeDefinitionDataContainer($form, 'com.woltlab.wcf.message')
->appendChildren([
- // TODO: maximum of one item (see https://github.com/WoltLab/WCF/issues/3040)
UserGroupOptionFormField::create('messageObjectDisallowedBBCodesPermission')
->objectProperty('disallowedBBCodesPermission')
->label('wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission')
->description('wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission.description')
+ ->maximum(1)
->addValidator(new FormFieldValidator('optionType', function(UserGroupOptionFormField $formField) {
$value = $formField->getValue();
if (empty($value)) return;
<item name="wcf.form.field.className.error.leadingBackslash"><![CDATA[Die angegebene Klasse{if $language|isset} ({$language}){/if} darf keinen führenden Backslash besitzen.]]></item>
<item name="wcf.form.field.className.error.nonExistent"><![CDATA[Die angegebene Klasse{if $language|isset} ({$language}){/if} existiert nicht.]]></item>
<item name="wcf.form.field.className.error.parentClass"><![CDATA[Die angegebene Klasse{if $language|isset} ({$language}){/if} erbt nicht von <kbd>{$parentClass}</kbd>.]]></item>
- <item name="wcf.form.field.itemList.error.separator"><![CDATA[Die folgenden Elemente dürfen kein {if $separator === ','}Komma{else}Leerzeichen{/if} enthalten: {implode from=$invalidItems item=item}„{$item}“{/implode}.]]></item>
+ <item name="wcf.form.field.itemList.error.separator"><![CDATA[Die folgenden Einträge dürfen kein {if $separator === ','}Komma{else}Leerzeichen{/if} enthalten: {implode from=$invalidItems item=item}„{$item}“{/implode}.]]></item>
<item name="wcf.form.field.numeric.error.maximum"><![CDATA[Der angegebene Wert darf nicht kleiner als {#$maximum} sein.]]></item>
<item name="wcf.form.field.numeric.error.minimum"><![CDATA[Der angegebene Wert darf nicht größer als {#$minimum} sein.]]></item>
<item name="wcf.form.field.option"><![CDATA[Einstellungen]]></item>
<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[Die haben {#$items} Einträge angegebenen, die Maximalanzahl beträgt jedoch jedoch {#$maximumItems}.]]></item>
</category>
<category name="wcf.image">
<item name="wcf.image.coverPhoto"><![CDATA[Titelbild]]></item>
<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>
</category>
<category name="wcf.image">
<item name="wcf.image.coverPhoto"><![CDATA[Cover Photo]]></item>