You are here

function flag_features_export in Flag 7.3

Same name and namespace in other branches
  1. 6.2 includes/flag.features.inc \flag_features_export()
  2. 7.2 includes/flag.features.inc \flag_features_export()

Implements hook_features_export().

File

includes/flag.features.inc, line 11
Features integration for Flag module.

Code

function flag_features_export($data, &$export, $module_name = '') {
  $pipe = array();

  // Add flag module as a dependency.
  $export['dependencies']['flag'] = 'flag';

  // Ensure the modules that provide the flag are included as dependencies.
  $modules = flag_features_providing_module();
  foreach ($data as $key => $flag) {
    $module = '';
    if ($flag = flag_load($flag, TRUE)) {

      // Try to get the module that provides the entity this flag is on.
      // First pass: check whether there's a module that implements
      // hook_flag_type_info() for this entity.
      if (array_key_exists($flag->entity_type, $modules)) {
        $module = $modules[$flag->entity_type];
      }
      else {

        // Second pass: check whether this entity is defined using Entity API
        // and therefore has an extra 'module' property in its information.
        if ($entity_info = entity_get_info($flag->entity_type)) {
          if (isset($entity_info['module'])) {
            $module = $entity_info['module'];
          }
        }
      }
      if (!empty($module)) {
        $export['dependencies'][$module] = $module;
      }
      $export['features']['flag'][$flag->name] = $flag->name;
    }
  }
  return $pipe;
}