You are here

function flag_create_handler in Flag 7.3

Same name and namespace in other branches
  1. 5 flag.inc \flag_create_handler()
  2. 6.2 flag.inc \flag_create_handler()
  3. 6 flag.inc \flag_create_handler()
  4. 7.2 flag.inc \flag_create_handler()

Instantiates a new flag handler.

A flag handler is more commonly know as "a flag". A factory method usually populates this empty flag with settings loaded from the database.

Parameters

$entity_type: The entity type to create a flag handler for. This may be FALSE if the entity type property could not be found in the flag configuration data.

Return value

A flag handler object. This may be the special class flag_broken is there is a problem with the flag.

3 calls to flag_create_handler()
flag_flag::factory_by_array in includes/flag/flag_flag.inc
Create a complete flag (except an FID) from an array definition.
flag_flag::factory_by_entity_type in includes/flag/flag_flag.inc
Another factory method. Returns a new, "empty" flag; e.g., one suitable for the "Add new flag" page.
flag_flag::factory_by_row in includes/flag/flag_flag.inc
Creates a flag from a database row. Returns it.

File

./flag.module, line 579
The Flag module.

Code

function flag_create_handler($entity_type) {
  $definition = flag_fetch_definition($entity_type);
  if (isset($definition) && class_exists($definition['handler'])) {
    $handler = new $definition['handler']();
  }
  else {
    $handler = new flag_broken();
  }
  $handler->entity_type = $entity_type;
  $handler
    ->construct();
  return $handler;
}