original_string: public static function validate($value, array $field)
      {
          if (!isset($field['type'])) {
              $field['type'] = 'text';
          }
          $type = $validate['type'] ?? $field['type'];
          $validate = (array)($field['validate'] ?? null);
          $required = $validate['required'] ?? false;
  
          // If value isn't required, we will stop validation if empty value is given.
          if ($required !== true && ($value === null || $value === '' || (($field['type'] === 'checkbox' || $field['type'] === 'switch') && $value == false))
          ) {
              return [];
          }
  
          // Get language class.
          $language = Grav::instance()['language'];
  
          $name = ucfirst($field['label'] ?? $field['name']);
          $message = (string) isset($field['validate']['message'])
              ? $language->translate($field['validate']['message'])
              : $language->translate('GRAV.FORM.INVALID_INPUT', null, true) . ' "' . $language->translate($name) . '"';
  
  
          // Validate type with fallback type text.
          $method = 'type' . str_replace('-', '_', $type);
  
          // If this is a YAML field validate/filter as such
          if (isset($field['yaml']) && $field['yaml'] === true) {
              $method = 'typeYaml';
          }
  
          $messages = [];
  
          $success = method_exists(__CLASS__, $method) ? self::$method($value, $validate, $field) : true;
          if (!$success) {
              $messages[$field['name']][] = $message;
          }
  
          // Check individual rules.
          foreach ($validate as $rule => $params) {
              $method = 'validate' . ucfirst(str_replace('-', '_', $rule));
  
              if (method_exists(__CLASS__, $method)) {
                  $success = self::$method($value, $params);
  
                  if (!$success) {
                      $messages[$field['name']][] = $message;
                  }
              }
          }
  
          return $messages;
      }
code: public static function validate($value, array $field)
      {
          if (!isset($field['type'])) {
              $field['type'] = 'text';
          }
          $type = $validate['type'] ?? $field['type'];
          $validate = (array)($field['validate'] ?? null);
          $required = $validate['required'] ?? false;
  
          // If value isn't required, we will stop validation if empty value is given.
          if ($required !== true && ($value === null || $value === '' || (($field['type'] === 'checkbox' || $field['type'] === 'switch') && $value == false))
          ) {
              return [];
          }
  
          // Get language class.
          $language = Grav::instance()['language'];
  
          $name = ucfirst($field['label'] ?? $field['name']);
          $message = (string) isset($field['validate']['message'])
              ? $language->translate($field['validate']['message'])
              : $language->translate('GRAV.FORM.INVALID_INPUT', null, true) . ' "' . $language->translate($name) . '"';
  
  
          // Validate type with fallback type text.
          $method = 'type' . str_replace('-', '_', $type);
  
          // If this is a YAML field validate/filter as such
          if (isset($field['yaml']) && $field['yaml'] === true) {
              $method = 'typeYaml';
          }
  
          $messages = [];
  
          $success = method_exists(__CLASS__, $method) ? self::$method($value, $validate, $field) : true;
          if (!$success) {
              $messages[$field['name']][] = $message;
          }
  
          // Check individual rules.
          foreach ($validate as $rule => $params) {
              $method = 'validate' . ucfirst(str_replace('-', '_', $rule));
  
              if (method_exists(__CLASS__, $method)) {
                  $success = self::$method($value, $params);
  
                  if (!$success) {
                      $messages[$field['name']][] = $message;
                  }
              }
          }
  
          return $messages;
      }
code_tokens: public static function validate ( $ value , array $ field ) { if ( ! isset ( $ field [ 'type' ] ) ) { $ field [ 'type' ] = 'text' ; } $ type = $ validate [ 'type' ] ?? $ field [ 'type' ] ; $ validate = ( array ) ( $ field [ 'validate' ] ?? null ) ; $ required = $ validate [ 'required' ] ?? false ; // If value isn't required, we will stop validation if empty value is given. if ( $ required !== true && ( $ value === null || $ value === '' || ( ( $ field [ 'type' ] === 'checkbox' || $ field [ 'type' ] === 'switch' ) && $ value == false ) ) ) { return [ ] ; } // Get language class. $ language = Grav :: instance ( ) [ 'language' ] ; $ name = ucfirst ( $ field [ 'label' ] ?? $ field [ 'name' ] ) ; $ message = ( string ) isset ( $ field [ 'validate' ] [ 'message' ] ) ? $ language -> translate ( $ field [ 'validate' ] [ 'message' ] ) : $ language -> translate ( 'GRAV.FORM.INVALID_INPUT' , null , true ) . ' "' . $ language -> translate ( $ name ) . '"' ; // Validate type with fallback type text. $ method = 'type' . str_replace ( '-' , '_' , $ type ) ; // If this is a YAML field validate/filter as such if ( isset ( $ field [ 'yaml' ] ) && $ field [ 'yaml' ] === true ) { $ method = 'typeYaml' ; } $ messages = [ ] ; $ success = method_exists ( __CLASS__ , $ method ) ? self :: $ method ( $ value , $ validate , $ field ) : true ; if ( ! $ success ) { $ messages [ $ field [ 'name' ] ] [ ] = $ message ; } // Check individual rules. foreach ( $ validate as $ rule => $ params ) { $ method = 'validate' . ucfirst ( str_replace ( '-' , '_' , $ rule ) ) ; if ( method_exists ( __CLASS__ , $ method ) ) { $ success = self :: $ method ( $ value , $ params ) ; if ( ! $ success ) { $ messages [ $ field [ 'name' ] ] [ ] = $ message ; } } } return $ messages ; }
docstring: Validate value against a blueprint field definition.
  
  @param mixed $value
  @param array $field
  @return array
docstring_tokens: Validate value against a blueprint field definition .