*}type="checkbox" {*
*}name="{@$field->getPrefixedId()}[]" {*
*}value="{$__fieldNestedOption[value]}"{*
- *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue()} checked{/if}{*
- *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue() && $__fieldNestedOption[isSelectable]} checked{/if}{*
+ *}{if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}{*
*}> {@$__fieldNestedOption[label]}</label>
</li>
{/foreach}
<input type="checkbox" {*
*}name="{@$field->getPrefixedId()}[]" {*
*}value="{$__fieldNestedOption[value]}"{*
- *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue()} checked{/if}{*
- *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue() && $__fieldNestedOption[isSelectable]} checked{/if}{*
+ *}{if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}{*
*}> {@$__fieldNestedOption[label]}
</label>
{/foreach}
*}type="radio" {*
*}name="{@$field->getPrefixedId()}" {*
*}value="{$__fieldNestedOption[value]}"{*
- *}{if $field->getValue() == $__fieldNestedOption[value]} checked{/if}{*
- *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getValue() == $__fieldNestedOption[value] && $__fieldNestedOption[isSelectable]} checked{/if}{*
+ *}{if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}{*
*}> {@$__fieldNestedOption[label]}</label>
</li>
{/foreach}
<option {*
*}name="{@$field->getPrefixedId()}" {*
*}value="{$__fieldNestedOption[value]}"{*
- *}{if $field->getValue() == $__fieldNestedOption[value]} selected{/if}{*
- *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getValue() == $__fieldNestedOption[value] && $__fieldNestedOption[isSelectable]} selected{/if}{*
+ *}{if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}{*
*}>{@' '|str_repeat:$__fieldNestedOption[depth] * 4}{@$__fieldNestedOption[label]}</option>
{/foreach}
</select>
*}type="checkbox" {*
*}name="{@$field->getPrefixedId()}[]" {*
*}value="{$__fieldNestedOption[value]}"{*
- *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue()} checked{/if}{*
- *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue() && $__fieldNestedOption[isSelectable]} checked{/if}{*
+ *}{if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}{*
*}> {@$__fieldNestedOption[label]}</label>
</li>
{/foreach}
<input type="checkbox" {*
*}name="{@$field->getPrefixedId()}[]" {*
*}value="{$__fieldNestedOption[value]}"{*
- *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue()} checked{/if}{*
- *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue() && $__fieldNestedOption[isSelectable]} checked{/if}{*
+ *}{if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}{*
*}> {@$__fieldNestedOption[label]}
</label>
{/foreach}
*}type="radio" {*
*}name="{@$field->getPrefixedId()}" {*
*}value="{$__fieldNestedOption[value]}"{*
- *}{if $field->getValue() == $__fieldNestedOption[value]} checked{/if}{*
- *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getValue() == $__fieldNestedOption[value] && $__fieldNestedOption[isSelectable]} checked{/if}{*
+ *}{if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}{*
*}> {@$__fieldNestedOption[label]}</label>
</li>
{/foreach}
<option {*
*}name="{@$field->getPrefixedId()}" {*
*}value="{$__fieldNestedOption[value]}"{*
- *}{if $field->getValue() == $__fieldNestedOption[value]} selected{/if}{*
- *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getValue() == $__fieldNestedOption[value] && $__fieldNestedOption[isSelectable]} selected{/if}{*
+ *}{if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}{*
*}>{@' '|str_repeat:$__fieldNestedOption[depth] * 4}{@$__fieldNestedOption[label]}</option>
{/foreach}
</select>
}
/**
- * Returns the possible options of this field.
+ * Returns the selectable options of this field.
*
* @return array
*
$collectedOptions[] = [
'depth' => $object->getDepth() - 1,
+ 'isSelectable' => true,
'label' => $object,
'value' => $object->getObjectID()
];
if (!is_array($option)) {
throw new \InvalidArgumentException("Nested option with key '{$key}' has is no array.");
}
- if (count($option) !== 3) {
- throw new \InvalidArgumentException("Nested option with key '{$key}' does not contain three elements.");
- }
// check if all required elements exist
foreach (['label', 'value', 'depth'] as $entry) {
throw new \InvalidArgumentException("Options values must be unique, but '{$option['value']}' appears at least twice as value.");
}
- // save value
- $this->options[$option['value']] = $option['label'];
-
// validate depth
if (!is_int($option['depth'])) {
throw new \InvalidArgumentException("Depth of nested option with key '{$key}' is no integer, " . gettype($options) . " given.");
if ($option['depth'] < 0) {
throw new \InvalidArgumentException("Depth of nested option with key '{$key}' is negative.");
}
+
+ // set default value of `isSelectable`
+ $option['isSelectable'] = $option['isSelectable'] ?? true;
+
+ // save value
+ if ($option['isSelectable']) {
+ $this->options[$option['value']] = $option['label'];
+ }
}
unset($option);
foreach ($this->options as $value => $label) {
$this->nestedOptions[] = [
'depth' => 0,
+ 'isSelectable' => true,
'label' => $label,
'value' => $value
];