2015-07-23 08:29:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\PropertyModifier;
|
|
|
|
|
|
2016-02-17 05:11:05 -05:00
|
|
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
2016-02-18 17:21:28 -05:00
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
2015-07-23 08:29:15 -04:00
|
|
|
|
2016-02-18 17:21:28 -05:00
|
|
|
class PropertyModifierReplace extends PropertyModifierHook
|
2015-07-23 08:29:15 -04:00
|
|
|
{
|
2015-07-23 08:42:53 -04:00
|
|
|
public static function addSettingsFormFields(QuickForm $form)
|
|
|
|
|
{
|
|
|
|
|
$form->addElement('text', 'string', array(
|
2016-03-05 18:37:03 -05:00
|
|
|
'label' => 'Search string',
|
|
|
|
|
'description' => $form->translate('The string you want to search for'),
|
|
|
|
|
'required' => true,
|
2015-07-23 08:42:53 -04:00
|
|
|
));
|
2016-02-18 17:21:28 -05:00
|
|
|
|
2015-07-23 08:42:53 -04:00
|
|
|
$form->addElement('text', 'replacement', array(
|
2016-03-05 18:37:03 -05:00
|
|
|
'label' => 'Replacement',
|
|
|
|
|
'description' => $form->translate('Your replacement string'),
|
2015-07-23 08:42:53 -04:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 08:29:15 -04:00
|
|
|
public function transform($value)
|
|
|
|
|
{
|
2021-08-12 05:45:40 -04:00
|
|
|
if ($value === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-24 10:40:08 -04:00
|
|
|
return str_replace(
|
|
|
|
|
$this->getSetting('string'),
|
|
|
|
|
$this->getSetting('replacement'),
|
|
|
|
|
$value
|
|
|
|
|
);
|
2015-07-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
}
|