function flag_export_flags in Flag 6.2
Same name and namespace in other branches
- 7.3 includes/flag.export.inc \flag_export_flags()
- 7.2 includes/flag.export.inc \flag_export_flags()
Export a flag to code.
Parameters
$flags: An array of flag objects, or flag name.
$module: Optional. The name of the module that will be created if exporting to use in hook_flag_default_flags().
2 calls to flag_export_flags()
- flag_export_form in includes/
flag.export.inc - Export a flag and display it in a form.
- flag_features_export_render in includes/
flag.features.inc - Implements hook_features_export_render().
File
- includes/
flag.export.inc, line 17 - Import/Export functionality provided by Flag module.
Code
function flag_export_flags($flags = array(), $module = '', $indent = '') {
module_load_include('inc', 'features', 'features.export');
// For features_var_export() (optional).
$output = $indent . '$flags = array();' . "\n";
foreach ($flags as $item) {
if (is_object($item)) {
$flag = $item;
}
else {
// We got just the flag name, for example from the features
// implementation.
if (!($flag = flag_load($item, TRUE))) {
continue;
}
}
if (!$flag
->is_compatible()) {
drupal_set_message(t('Could not export flag %flag-name: Your flag was created by a different version of the Flag module than is now being used.', array(
'%flag-name' => $flag->name,
)), 'error');
continue;
}
$flag->api_version = FLAG_API_VERSION;
$new_flag = (array) $flag;
if (!empty($module)) {
// Even though Flag adds the module name itself later, we add the module
// name here for reference by other modules (such as Features).
$new_flag['module'] = $module;
// Lock the flag name, as is normally desired by modules using
// hook_flag_default_flags(), and needed by Features.
$new_flag['locked'] = array(
'name',
);
}
// Allow other modules to change the exported flag.
drupal_alter('flag_export', $new_flag);
// Remove the flag ID.
unset($new_flag['fid']);
// The name is emitted as the key for the array.
unset($new_flag['name']);
$output .= $indent . '// Exported flag: "' . check_plain($flag
->get_title()) . '"' . ".\n";
$output .= $indent . '$flags[\'' . $flag->name . '\'] = ' . (function_exists('features_var_export') ? features_var_export($new_flag, $indent) : var_export($new_flag, TRUE)) . ";\n";
}
$output .= $indent . 'return $flags;' . "\n";
return $output;
}