Skip to content

Commit

Permalink
PropertyModifier: Replace Null with String
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Dolinic authored and Thomas-Gelf committed Apr 20, 2022
1 parent 67eb4c1 commit 4692b28
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions library/Director/PropertyModifier/PropertyModifierReplaceNull.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Icinga\Module\Director\PropertyModifier;

use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Web\Form\QuickForm;

class PropertyModifierReplaceNull extends PropertyModifierHook
{

public function getName()
{
return 'Replace null value with String';
}

public static function addSettingsFormFields(QuickForm $form)
{
$form->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;
}
}
}
2 changes: 2 additions & 0 deletions register-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,6 +119,7 @@
PropertyModifierRejectOrSelect::class,
PropertyModifierRenameColumn::class,
PropertyModifierReplace::class,
PropertyModifierReplaceNull::class,
PropertyModifierSimpleGroupBy::class,
PropertyModifierSkipDuplicates::class,
PropertyModifierSplit::class,
Expand Down

0 comments on commit 4692b28

Please sign in to comment.