You are here

function flag_flag::validate_name in Flag 7.3

Same name and namespace in other branches
  1. 5 flag.inc \flag_flag::validate_name()
  2. 6.2 flag.inc \flag_flag::validate_name()
  3. 6 flag.inc \flag_flag::validate_name()
  4. 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 includes/flag/flag_flag.inc
Validates this flag's options.

File

includes/flag/flag_flag.inc, line 283
Contains the flag_flag class. Flag type classes use an 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;
}