icingaweb2-module-businessp.../library/Businessprocess/Web/Form/Element/StateOverrides.php
Johannes Meyer 49ebbc4cdb Apply state overrides on demand instead of directly
Internally non-process children are only instantiated once.
This means when applying state overrides directly they're
used everywhere and do not differ between the containing
process. State overrides are now applied explicitly and
on demand, decoupling them from children.
2020-07-01 08:54:34 +02:00

55 lines
1,021 B
PHP

<?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);
}
}