diff --git a/flag.api.php b/flag.api.php index 259e37a..3052c3f 100644 --- a/flag.api.php +++ b/flag.api.php @@ -70,6 +70,19 @@ function hook_flag_alter(&$flag) { } /** + * Allows other modules to modify the list of available flags + * prior to type/user filtering performed by flag_get_flags(). + * + * @param array $flags + * An array of available flag objects indexed by flag name. + * + * @see flag_get_flags() + */ +function hook_flag_get_flags($flags) { + +} + +/** * Alter a flag's default options. * * Modules that wish to extend flags and provide additional options must declare diff --git a/flag.module b/flag.module index 5c26b7a..ef64404 100644 --- a/flag.module +++ b/flag.module @@ -1826,7 +1826,16 @@ function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account = } // Make a variable copy to filter types and account. - $filtered_flags = $flags; + $filtered_flags = array(); + foreach ($flags as $name => $flag) { + $filtered_flags[$name] = clone $flag; + } + + // Let other modules modify our copy of the flags array prior to filtering. + foreach (module_implements('flag_get_flags') as $module) { + $function = $module . '_flag_get_flags'; + $function($filtered_flags); + } // Filter out flags based on type and subtype. if (isset($entity_type) || isset($content_subtype)) {