IcingaObjectFieldForm: move back getFilterFields()

This commit is contained in:
Thomas Gelf 2023-08-19 13:37:19 +02:00
parent d97bbc0526
commit 7aa7f51929
2 changed files with 26 additions and 27 deletions

View File

@ -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;
}
}

View File

@ -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)) {