Nette\Forms\Controls\MultiChoiceControl::setValue PHP Method

setValue() public method

Sets selected items (by keys).
public setValue ( $values ) : self
return self
    public function setValue($values)
    {
        if (is_scalar($values) || $values === NULL) {
            $values = (array) $values;
        } elseif (!is_array($values)) {
            throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
        }
        $flip = [];
        foreach ($values as $value) {
            if (!is_scalar($value) && !method_exists($value, '__toString')) {
                throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
            }
            $flip[(string) $value] = TRUE;
        }
        $values = array_keys($flip);
        if ($this->checkAllowedValues && ($diff = array_diff($values, array_keys($this->items)))) {
            $set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
                return var_export($s, TRUE);
            }, array_keys($this->items))), 70, '...');
            $vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
            throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed set [{$set}] in field '{$this->name}'.");
        }
        $this->value = $values;
        return $this;
    }