Habari\FormValidators::validate_username PHP Метод

validate_username() публичный статический Метод

A validation function that returns an error if the the passed username is unavailable
public static validate_username ( $value, FormControl $control, FormContainer $form, string $allowed_name = null, string $warning = null ) : array
$control FormControl The control that defines the value
$form FormContainer The container that holds the control
$allowed_name string An optional name which overrides the check and is always allowed
$warning string An optional error message
Результат array An empty array if the value exists, or an array with strings describing the errors
    public static function validate_username($value, $control, $form, $allowed_name = null, $warning = null)
    {
        if (isset($allowed_name) && $value == $allowed_name) {
            return array();
        }
        if (User::get_by_name($value)) {
            $warning = empty($warning) ? _t('That username supplied for %s is already in use.', array($control->get_label())) : $warning;
            return array($warning);
        }
        return array();
    }