protected function validateRequired(&$value, array $field, Validation $validation) {
        $required = val('required', $field, false);
        $type = $field['type'];

        if ($value === '' || $value === null) {
            if (!$required) {
                $value = null;
                return true;
            }

            switch ($type) {
                case 'boolean':
                    $value = false;
                    return true;
                case 'string':
                    if (val('minLength', $field, 1) == 0) {
                        $value = '';
                        return true;
                    }
            }
            $validation->addError('missing_field', $field);
            return false;
        }
        return null;
    }
protected function validateRequired(&$value, array $field, Validation $validation) {
        $required = val('required', $field, false);
        $type = $field['type'];

        if ($value === '' || $value === null) {
            if (!$required) {
                $value = null;
                return true;
            }

            switch ($type) {
                case 'boolean':
                    $value = false;
                    return true;
                case 'string':
                    if (val('minLength', $field, 1) == 0) {
                        $value = '';
                        return true;
                    }
            }
            $validation->addError('missing_field', $field);
            return false;
        }
        return null;
    }
protected function validateRequired ( & $ value , array $ field , Validation $ validation ) { $ required = val ( 'required' , $ field , false ) ; $ type = $ field [ 'type' ] ; if ( $ value === '' || $ value === null ) { if ( ! $ required ) { $ value = null ; return true ; } switch ( $ type ) { case 'boolean' : $ value = false ; return true ; case 'string' : if ( val ( 'minLength' , $ field , 1 ) == 0 ) { $ value = '' ; return true ; } } $ validation -> addError ( 'missing_field' , $ field ) ; return false ; } return null ; }
Validate a required field.

@param mixed &$value The field value.
@param array $field The field definition.
@param Validation $validation A {@link Validation} object to collect errors.
@return bool|null Returns one of the following:
- null: The field is not required.
- true: The field is required and {@link $value} is not empty.
- false: The field is required and {@link $value} is empty.
Validate a required field .