From 4692b28dbd720912fb8684a0641355564c439b78 Mon Sep 17 00:00:00 2001 From: Patrick Dolinic Date: Wed, 20 Apr 2022 13:19:30 +0200 Subject: [PATCH] PropertyModifier: Replace Null with String --- .../PropertyModifierReplaceNull.php | 33 +++++++++++++++++++ register-hooks.php | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 library/Director/PropertyModifier/PropertyModifierReplaceNull.php diff --git a/library/Director/PropertyModifier/PropertyModifierReplaceNull.php b/library/Director/PropertyModifier/PropertyModifierReplaceNull.php new file mode 100644 index 000000000..f59f5b834 --- /dev/null +++ b/library/Director/PropertyModifier/PropertyModifierReplaceNull.php @@ -0,0 +1,33 @@ +addElement('text', 'string', array( + 'label' => 'Replacement String', + 'description' => $form->translate('Your replacement string'), + 'required' => true, + )); + } + + public function transform($value) + { + if ($value === null) { + return $this->getSetting('string'); + } else { + return $value; + } + } +} diff --git a/register-hooks.php b/register-hooks.php index a37aa706e..d628e4e34 100644 --- a/register-hooks.php +++ b/register-hooks.php @@ -45,6 +45,7 @@ use Icinga\Module\Director\PropertyModifier\PropertyModifierRejectOrSelect; use Icinga\Module\Director\PropertyModifier\PropertyModifierRenameColumn; use Icinga\Module\Director\PropertyModifier\PropertyModifierReplace; +use Icinga\Module\Director\PropertyModifier\PropertyModifierReplaceNull; use Icinga\Module\Director\PropertyModifier\PropertyModifierSimpleGroupBy; use Icinga\Module\Director\PropertyModifier\PropertyModifierSkipDuplicates; use Icinga\Module\Director\PropertyModifier\PropertyModifierSplit; @@ -118,6 +119,7 @@ PropertyModifierRejectOrSelect::class, PropertyModifierRenameColumn::class, PropertyModifierReplace::class, + PropertyModifierReplaceNull::class, PropertyModifierSimpleGroupBy::class, PropertyModifierSkipDuplicates::class, PropertyModifierSplit::class,