summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/Web/Form/Element/StateOverrides.php
blob: c2216c0de6386453463177c7afe402fa62377756 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

namespace Icinga\Module\Businessprocess\Web\Form\Element;

class StateOverrides extends FormElement
{
    public $helper = 'formStateOverrides';

    /** @var array The overridable states */
    protected $states;

    /**
     * Set the overridable states
     *
     * @param array $states
     *
     * @return $this
     */
    public function setStates(array $states)
    {
        $this->states = $states;

        return $this;
    }

    /**
     * Get the overridable states
     *
     * @return array
     */
    public function getStates()
    {
        return $this->states;
    }

    public function init()
    {
        $this->setIsArray(true);
    }

    public function setValue($value)
    {
        $cleanedValue = [];

        if (! empty($value)) {
            foreach ($value as $from => $to) {
                if ((int) $from !== (int) $to) {
                    $cleanedValue[$from] = $to;
                }
            }
        }

        return parent::setValue($cleanedValue);
    }
}