Habari\FormValidators::validate_groupname PHP Method

validate_groupname() public static method

A validation function that returns an error if the the passed group name is unavailable
public static validate_groupname ( $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
return array An empty array if the value exists, or an array with strings describing the errors
    public static function validate_groupname($value, $control, $form, $allowed_name = null, $warning = null)
    {
        if (isset($allowed_name) && $value == $allowed_name) {
            return array();
        }
        if (UserGroup::exists($value)) {
            $warning = empty($warning) ? _t('The group %s already exists.', array($value)) : $warning;
            return array($warning);
        }
        return array();
    }