function flag_get_flags in Flag 6.2
Same name and namespace in other branches
- 5 flag.module \flag_get_flags()
- 6 flag.module \flag_get_flags()
- 7.3 flag.module \flag_get_flags()
- 7.2 flag.module \flag_get_flags()
List all flags available.
If node type or account are entered, a list of all possible flags will be returned.
Parameters
$content_type: Optional. The type of content 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.
$reset: Optional. Reset the internal query cache.
Return value
$flags An array of the structure [fid] = flag_object.
29 calls to flag_get_flags()
- FlagTestCase::testFlagAdmin in tests/
flag.test - Create a flag through the UI and ensure that it is saved properly.
- 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_page in includes/
flag.admin.inc - Flag administration page. Display a list of existing flags.
File
- ./
flag.module, line 1307 - The Flag module.
Code
function flag_get_flags($content_type = NULL, $content_subtype = NULL, $account = NULL, $reset = FALSE) {
static $flags;
// Retrieve a list of all flags, regardless of the parameters.
if (!isset($flags) || $reset) {
$flags = array();
// Database flags.
$result = db_query("SELECT f.*, fn.type FROM {flags} f LEFT JOIN {flag_types} fn ON fn.fid = f.fid");
while ($row = db_fetch_object($result)) {
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');
// Allow modules implementing hook_flag_alter(&$flag) to modify each flag.
foreach ($flags as $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($content_type) || isset($content_subtype)) {
foreach ($filtered_flags as $name => $flag) {
if (!_flag_content_enabled($flag, $content_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;
}