_errorMessages; // @codingStandardsIgnoreEnd } /** * @codingStandardsIgnoreStart */ protected function _filterValue(&$value, &$key) { // @codingStandardsIgnoreEnd if (is_array($value)) { $value = array_filter($value, 'strlen'); } elseif (is_string($value) && !strlen($value)) { $value = null; } parent::_filterValue($value, $key); } public function isValid($value, $context = null) { if ($value === null) { $value = []; } $value = array_filter($value, 'strlen'); $this->setValue($value); if ($this->isRequired() && empty($value)) { // TODO: translate $this->addError('You are required to choose at least one element'); return false; } if ($this->hasErrors()) { return false; } return parent::isValid($value, $context); } }