You are here

function flag_get_flags in Flag 7.3

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

List all flags available.

If all the parameters are omitted, a list of all flags will be returned.

Parameters

$entity_type: (optional) The type of entity for which to load the flags. Usually 'node'.

$content_subtype: (optional) The node type for which to load the flags.

$account: (optional) The user accont to filter available flags. If not set, all flags for will this node will be returned.

Return value

An array of flag objects, keyed by the flag names.

36 calls to flag_get_flags()
flag_actions_add_form in ./flag_actions.module
Modified version of the Add action form that redirects back to the flag list.
flag_action_form in includes/flag.actions.inc
Generic form for configuring Flag actions.
flag_action_info_alter in includes/flag.actions.inc
Implements hook_action_info_alter().
flag_admin_menu_map in ./flag.module
Implements hook_admin_menu_map().
flag_admin_page in includes/flag.admin.inc
Flag administration page. Display a list of existing flags.

... See full list

7 string references to 'flag_get_flags'
FlagAdminTestCase::testFlagAdmin in tests/flag.test
Create a flag through the UI and ensure that it is saved properly.
FlagLinkTypeConfirmTestCase::setUp in tests/flag.test
Implements setUp().
FlagTestCaseBase::createFlag in tests/flag.test
Helper to create a flag from an array of data and clear caches etc.
flag_bookmark_enable in flag_bookmark/flag_bookmark.install
Implements hook_enable().
flag_flag::revert in includes/flag/flag_flag.inc
Reverts an overriding flag to its default state.

... See full list

File

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

Code

function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account = NULL) {
  $flags =& drupal_static(__FUNCTION__);

  // Retrieve a list of all flags, regardless of the parameters.
  if (!isset($flags)) {
    $flags = array();

    // Database flags.
    $query = db_select('flag', 'f');
    $query
      ->leftJoin('flag_types', 'fn', 'fn.fid = f.fid');
    $result = $query
      ->fields('f', array(
      'fid',
      'entity_type',
      'name',
      'title',
      'global',
      'options',
    ))
      ->fields('fn', array(
      'type',
    ))
      ->execute();
    foreach ($result as $row) {
      if (!isset($flags[$row->name])) {
        $flags[$row->name] = flag_flag::factory_by_row($row);
      }
      else {
        $flags[$row->name]->types[] = $row->type;
      }
    }

    // Add code-based flags provided by modules.
    $default_flags = flag_get_default_flags();
    foreach ($default_flags as $name => $default_flag) {

      // Insert new enabled flags into the database to give them an FID.
      if ($default_flag->status && !isset($flags[$name])) {
        $default_flag
          ->save();
        $flags[$name] = $default_flag;
      }
      if (isset($flags[$name])) {

        // Ensure overridden flags are associated with their parent module.
        $flags[$name]->module = $default_flag->module;

        // Update the flag with any properties that are "locked" by the code
        // version.
        if (isset($default_flag->locked)) {
          $flags[$name]->locked = $default_flag->locked;
          foreach ($default_flag->locked as $property) {
            $flags[$name]->{$property} = $default_flag->{$property};
          }
        }
      }
    }

    // Sort the list of flags by weight.
    uasort($flags, '_flag_compare_weight');
    foreach ($flags as $flag) {

      // Allow modules implementing hook_flag_alter(&$flag) to modify each flag.
      drupal_alter('flag', $flag);
    }
  }

  // Make a variable copy to filter types and account.
  $filtered_flags = $flags;

  // Filter out flags based on type and subtype.
  if (isset($entity_type) || isset($content_subtype)) {
    foreach ($filtered_flags as $name => $flag) {
      if (!$flag
        ->access_entity_enabled($entity_type, $content_subtype)) {
        unset($filtered_flags[$name]);
      }
    }
  }

  // Filter out flags based on account permissions.
  if (isset($account) && $account->uid != 1) {
    foreach ($filtered_flags as $name => $flag) {

      // We test against the 'flag' action, which is the minimum permission to
      // use a flag.
      if (!$flag
        ->user_access('flag', $account)) {
        unset($filtered_flags[$name]);
      }
    }
  }
  return $filtered_flags;
}