Example #1
0
 /**
  * Validates the specified value.
  *
  * This function uses the validator defined using the {@link VALIDATOR} special attribute to
  * validate its value.
  *
  * @param $value
  * @param \ICanBoogie\Errors $errors
  *
  * @return boolean `true` if  the validation succeed, `false` otherwise.
  */
 public function validate($value, \ICanBoogie\Errors $errors)
 {
     $validator = $this[self::VALIDATOR];
     $options = $this[self::VALIDATOR_OPTIONS];
     if ($validator) {
         if ($validator instanceof \Closure) {
             return $validator($errors, $this, $value);
         }
         list($callback, $params) = $validator + [1 => []];
         return call_user_func($callback, $errors, $this, $value, $params);
     }
     #
     # default validator
     #
     if (!$options) {
         return true;
     }
     switch ($this->type) {
         case self::TYPE_CHECKBOX_GROUP:
             if (isset($options['max-checked'])) {
                 $limit = $options['max-checked'];
                 if (count($value) > $limit) {
                     $errors[$this->name] = $this->t('Le nombre de choix possible pour le champ %name est limité à :limit', ['name' => Form::select_element_label($this), 'limit' => $limit]);
                     return false;
                 }
             }
             break;
     }
     return true;
 }