You are here

function flag_actions_get_actions in Flag 5

Same name and namespace in other branches
  1. 6.2 flag_actions.module \flag_actions_get_actions()
  2. 6 flag_actions.module \flag_actions_get_actions()
  3. 7.3 flag_actions.module \flag_actions_get_actions()
  4. 7.2 flag_actions.module \flag_actions_get_actions()
3 calls to flag_actions_get_actions()
flag_actions_do in ./flag_actions.module
Perform flag actions.
flag_actions_get_action in ./flag_actions.module
flag_actions_page in ./flag_actions.module
Menu callback for admin/build/flags/actions.

File

./flag_actions.module, line 63
Actions support for the Flag module.

Code

function flag_actions_get_actions($flag_name = NULL, $reset = FALSE) {
  static $flag_actions;

  // Get a list of all possible actions defined by modules.
  $actions = module_invoke_all('action_info');

  // Retrieve the list of user-defined flag actions.
  if (!isset($flag_actions) || $reset) {
    $flag_actions = array();
    $result = db_query("SELECT a.*, f.name as flag FROM {flag_actions} a INNER JOIN {flags} f ON a.fid = f.fid");
    while ($action = db_fetch_object($result)) {
      if (!isset($actions[$action->callback])) {
        $actions[$action->callback] = array(
          'description' => t('Missing action "@action-callback". Module providing it was either uninstalled or disabled.', array(
            '@action-callback' => $action->callback,
          )),
          'configurable' => FALSE,
          'type' => 'node',
          'missing' => TRUE,
        );
      }
      $action->parameters = unserialize($action->parameters);
      $action->description = $actions[$action->callback]['description'];
      $action->configurable = $actions[$action->callback]['configurable'];
      $action->behavior = isset($actions[$action->callback]['behavior']) ? $actions[$action->callback]['behavior'] : array();
      $action->type = $actions[$action->callback]['type'];
      $action->missing = !empty($actions[$action->callback]['missing']);
      $flag_actions[$action->aid] = $action;
    }
  }

  // Filter actions to a specified flag.
  if (isset($flag_name)) {
    $specific_flag_actions = array();
    foreach ($flag_actions as $aid => $action) {
      if ($action->flag == $flag_name) {
        $specific_flag_actions[$aid] = $action;
      }
    }
    return $specific_flag_actions;
  }
  return $flag_actions;
}