mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
Allow ArrayByElementPosition modifier to filter by key name
Fix double brackets Allow ArrayByElementPosition modifier to filter by key name Fix double brackets
This commit is contained in:
parent
e871ba4d4e
commit
0dfa6a7ba3
@ -30,16 +30,17 @@ class PropertyModifierArrayElementByPosition extends PropertyModifierHook
|
|||||||
'label' => $form->translate('Position Type'),
|
'label' => $form->translate('Position Type'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'multiOptions' => $form->optionalEnum([
|
'multiOptions' => $form->optionalEnum([
|
||||||
'first' => $form->translate('First Element'),
|
'first' => $form->translate('First Element'),
|
||||||
'last' => $form->translate('Last Element'),
|
'last' => $form->translate('Last Element'),
|
||||||
'fixed' => $form->translate('Specific Element (by position)'),
|
'fixed' => $form->translate('Specific Element (by position)'),
|
||||||
|
'keyname' => $form->translate('Specific Element (by key name)'),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$form->addElement('text', 'position', [
|
$form->addElement('text', 'position', [
|
||||||
'label' => $form->translate('Position'),
|
'label' => $form->translate('Position'),
|
||||||
'description' => $form->translate(
|
'description' => $form->translate(
|
||||||
'Numeric position'
|
'Numeric position or key name'
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -99,6 +100,21 @@ class PropertyModifierArrayElementByPosition extends PropertyModifierHook
|
|||||||
}
|
}
|
||||||
$pos = (int) $pos;
|
$pos = (int) $pos;
|
||||||
|
|
||||||
|
if (array_key_exists($pos, $value)) {
|
||||||
|
return $value[$pos];
|
||||||
|
} else {
|
||||||
|
return $this->emptyValue($value);
|
||||||
|
}
|
||||||
|
// https://github.com/squizlabs/PHP_CodeSniffer/pull/1363
|
||||||
|
case 'keyname':
|
||||||
|
$pos = $this->getSetting('position');
|
||||||
|
if (! is_string($pos)) {
|
||||||
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'"%s" is not a valid array key name',
|
||||||
|
$pos
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists($pos, $value)) {
|
if (array_key_exists($pos, $value)) {
|
||||||
return $value[$pos];
|
return $value[$pos];
|
||||||
} else {
|
} else {
|
||||||
@ -126,6 +142,8 @@ class PropertyModifierArrayElementByPosition extends PropertyModifierHook
|
|||||||
return 'last';
|
return 'last';
|
||||||
case 'fixed':
|
case 'fixed':
|
||||||
return '#' . $this->getSetting('position');
|
return '#' . $this->getSetting('position');
|
||||||
|
case 'keyname':
|
||||||
|
return '#' . $this->getSetting('position');
|
||||||
default:
|
default:
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
'"%s" is not a valid array position_type',
|
'"%s" is not a valid array position_type',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user