summaryrefslogtreecommitdiffstats
path: root/library/Director/PropertyModifier/PropertyModifierCombine.php
blob: 5be09ea3638699634886f900cec68587ce90aa37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

namespace Icinga\Module\Director\PropertyModifier;

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

class PropertyModifierCombine extends PropertyModifierHook
{
    public static function addSettingsFormFields(QuickForm $form)
    {
        $form->addElement('text', 'pattern', array(
            'label'       => $form->translate('Pattern'),
            'required'    => false,
            'description' => $form->translate(
                'This pattern will be evaluated, and variables like ${some_column}'
                . ' will be filled accordingly. A typical use-case is generating'
                . ' unique service identifiers via ${host}!${service} in case your'
                . ' data source doesn\'t allow you to ship such. The chosen "property"'
                . ' has no effect here and will be ignored.'
            )
        ));
    }

    public function getName()
    {
        return 'Combine multiple properties';
    }

    public function requiresRow()
    {
        return true;
    }

    public function transform($value)
    {
        return SyncUtils::fillVariables($this->getSetting('pattern'), $this->getRow());
    }
}