*/
const SAVE_VALUE_TYPE_CSV = 'csv';
+ /**
+ * save value return type so that newline-separated list with the item values
+ * will be returned
+ * @var string
+ */
+ const SAVE_VALUE_TYPE_NSV = 'nsv';
+
/**
* save value return type so that space-separated list with the item values
* will be returned
case self::SAVE_VALUE_TYPE_CSV:
return implode(',', $this->getValue() ?: []);
+ case self::SAVE_VALUE_TYPE_NSV:
+ return implode("\n", $this->getValue() ?: []);
+
case self::SAVE_VALUE_TYPE_SSV:
return implode(' ', $this->getValue() ?: []);
throw new \BadMethodCallException("Save value type has already been set.");
}
- if ($saveValueType !== self::SAVE_VALUE_TYPE_ARRAY && $saveValueType !== self::SAVE_VALUE_TYPE_CSV && $saveValueType !== self::SAVE_VALUE_TYPE_SSV) {
+ if (!in_array($saveValueType, [self::SAVE_VALUE_TYPE_ARRAY, self::SAVE_VALUE_TYPE_CSV, self::SAVE_VALUE_TYPE_NSV, self::SAVE_VALUE_TYPE_SSV])) {
throw new \InvalidArgumentException("Unknown save value type '{$saveValueType}'.");
}
break;
+ case self::SAVE_VALUE_TYPE_NSV:
+ if (is_string($value)) {
+ $this->__value = explode("\n", $value);
+ }
+ else {
+ throw new \InvalidArgumentException("Given value is no string, '" . gettype($value) . "' given.");
+ }
+
+ break;
+
case self::SAVE_VALUE_TYPE_SSV:
if (is_string($value)) {
$this->__value = explode(' ', $value);
break;
+ case self::SAVE_VALUE_TYPE_NSV:
+ if (strpos($item, "\n") !== false) {
+ $invalidItems[] = $item;
+ }
+
+ break;
+
case self::SAVE_VALUE_TYPE_SSV:
if (strpos($item, ' ') !== false) {
$invalidItems[] = $item;
}
if (!empty($invalidItems)) {
+ $separator = '';
+ switch ($this->getSaveValue()) {
+ case self::SAVE_VALUE_TYPE_CSV:
+ $separator = ',';
+ break;
+
+ case self::SAVE_VALUE_TYPE_NSV:
+ $separator = "\n";
+ break;
+
+ case self::SAVE_VALUE_TYPE_SSV:
+ $separator = ' ';
+ break;
+ }
+
$this->addValidationError(new FormFieldValidationError(
'separator',
'wcf.form.field.itemList.error.separator',
[
'invalidItems' => $invalidItems,
- 'separator' => $this->getSaveValueType() === self::SAVE_VALUE_TYPE_CSV ? ',' : ' '
+ 'separator' => $separator
]
));
}
<item name="wcf.form.field.className.error.leadingBackslash"><![CDATA[The entered class name{if $language|isset} ({$language}){/if} must not have a leading backslash.]]></item>
<item name="wcf.form.field.className.error.nonExistent"><![CDATA[The entered class{if $language|isset} ({$language}){/if} does not exist.]]></item>
<item name="wcf.form.field.className.error.parentClass"><![CDATA[The entered class{if $language|isset} ({$language}){/if} does not extend <code>{$parentClass}</code>.]]></item>
- <item name="wcf.form.field.itemList.error.separator"><![CDATA[The following items may contain no {if $separator === ','}comma{else}space{/if}: {implode from=$invalidItems item=item}“{$item}”{/implode}.]]></item>
+ <item name="wcf.form.field.itemList.error.separator"><![CDATA[The following items may contain no {if $separator === ','}comma{else if $separator === "\n"}newline{else}space{/if}: {implode from=$invalidItems item=item}“{$item}”{/implode}.]]></item>
<item name="wcf.form.field.numeric.error.maximum"><![CDATA[The entered value may not be less than {#$maximum}.]]></item>
<item name="wcf.form.field.numeric.error.minimum"><![CDATA[The entered value may not be greater than {#$minimum}.]]></item>
<item name="wcf.form.field.showOrder"><![CDATA[Position]]></item>