/** * Set default. * * The default value here should be one of the existing list of options. * * @param array $value default value. * @return OKT_FormElement fluent interface */ function setDefault($value) { if (!array_key_exists($value, $this->options)) { throw new InvalidArgumentException("default {$value} is not in options"); } return parent::setDefault($value); }
/** * Set default. * * The default value here is an array of values that should be checked by * default. On input, these default values are checked to see they are * already options. * * @param array $value default value. * @return OKT_FormElement fluent interface */ function setDefault($value) { if (!is_array($value)) { throw new InvalidArgumentException('default required as array'); } $intersect = array_intersect(array_keys($this->getOptions()), $value); if (count($intersect) !== count($value)) { throw new InvalidArgumentException('default values not in options'); } return parent::setDefault(array_values($intersect)); }