function flag_flag::validate_name in Flag 6.2
Same name and namespace in other branches
- 5 flag.inc \flag_flag::validate_name()
- 6 flag.inc \flag_flag::validate_name()
- 7.3 includes/flag/flag_flag.inc \flag_flag::validate_name()
- 7.2 flag.inc \flag_flag::validate_name()
Validates that the current flag's name is valid.
Return value
A list of errors encountered while validating this flag's name.
1 call to flag_flag::validate_name()
- flag_flag::validate in ./
flag.inc - Validates this flag's options.
File
- ./
flag.inc, line 302 - Implements various flags. Uses object oriented style inspired by that of Views 2.
Class
- flag_flag
- This abstract class represents a flag, or, in Views 2 terminology, "a handler".
Code
function validate_name() {
$errors = array();
// Ensure a safe machine name.
if (!preg_match('/^[a-z_][a-z0-9_]*$/', $this->name)) {
$errors['name'][] = array(
'error' => 'flag_name_characters',
'message' => t('The flag name may only contain lowercase letters, underscores, and numbers.'),
);
}
// Ensure the machine name is unique.
$flag = flag_get_flag($this->name);
if (!empty($flag) && (!isset($this->fid) || $flag->fid != $this->fid)) {
$errors['name'][] = array(
'error' => 'flag_name_unique',
'message' => t('Flag names must be unique. This flag name is already in use.'),
);
}
return $errors;
}