mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
IcingaObjectFieldForm: move back getFilterFields()
This commit is contained in:
parent
d97bbc0526
commit
7aa7f51929
@ -4,9 +4,12 @@ namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Field\FormFieldSuggestion;
|
||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Objects\DirectorDatafield;
|
||||
use Icinga\Module\Director\Objects\IcingaService;
|
||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||
use Icinga\Module\Director\Web\Form\IcingaObjectFieldLoader;
|
||||
|
||||
class IcingaObjectFieldForm extends DirectorObjectForm
|
||||
{
|
||||
@ -107,7 +110,7 @@ class IcingaObjectFieldForm extends DirectorObjectForm
|
||||
]
|
||||
]);
|
||||
|
||||
if ($filterFields = $this->formFieldSuggestion->getFilterFields($object)) {
|
||||
if ($filterFields = $this->getFilterFields($object)) {
|
||||
$this->addFilterElement('var_filter', [
|
||||
'description' => $this->translate(
|
||||
'You might want to show this field only when certain conditions are met.'
|
||||
@ -160,4 +163,26 @@ class IcingaObjectFieldForm extends DirectorObjectForm
|
||||
$this->object()->set('var_filter', $this->getValue('var_filter'));
|
||||
parent::onSuccess();
|
||||
}
|
||||
|
||||
protected static function getFilterFields(IcingaObject $object): array
|
||||
{
|
||||
$filterFields = [];
|
||||
$prefix = null;
|
||||
if ($object instanceof IcingaHost) {
|
||||
$prefix = 'host.vars.';
|
||||
} elseif ($object instanceof IcingaService) {
|
||||
$prefix = 'service.vars.';
|
||||
}
|
||||
|
||||
if ($prefix) {
|
||||
$loader = new IcingaObjectFieldLoader($object);
|
||||
$fields = $loader->getFields();
|
||||
|
||||
foreach ($fields as $varName => $field) {
|
||||
$filterFields[$prefix . $field->get('varname')] = $field->get('caption');
|
||||
}
|
||||
}
|
||||
|
||||
return $filterFields;
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,6 @@ namespace Icinga\Module\Director\Field;
|
||||
|
||||
use gipfl\Translation\TranslationHelper;
|
||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Objects\IcingaService;
|
||||
use Icinga\Module\Director\Web\Form\IcingaObjectFieldLoader;
|
||||
|
||||
class FormFieldSuggestion
|
||||
{
|
||||
@ -91,28 +87,6 @@ class FormFieldSuggestion
|
||||
|
||||
}
|
||||
|
||||
public function getFilterFields(IcingaObject $object): array
|
||||
{
|
||||
$filterFields = [];
|
||||
$prefix = null;
|
||||
if ($object instanceof IcingaHost) {
|
||||
$prefix = 'host.vars.';
|
||||
} elseif ($object instanceof IcingaService) {
|
||||
$prefix = 'service.vars.';
|
||||
}
|
||||
|
||||
if ($prefix) {
|
||||
$loader = new IcingaObjectFieldLoader($object);
|
||||
$fields = $loader->getFields();
|
||||
|
||||
foreach ($fields as $varName => $field) {
|
||||
$filterFields[$prefix . $field->get('varname')] = $field->get('caption');
|
||||
}
|
||||
}
|
||||
|
||||
return $filterFields;
|
||||
}
|
||||
|
||||
protected static function extractMacroNamesFromString(?string $string): array
|
||||
{
|
||||
if ($string !== null && preg_match_all('/(\$[a-z0-9_]+\$)/i', $string, $matches, PREG_PATTERN_ORDER)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user