You are here

function field_instance_features_export in Features 7.2

Implements hook_features_export().

File

includes/features.field.inc, line 119
Features integration on behalf of 'field' module.

Code

function field_instance_features_export($data, &$export, $module_name = '') {
  $pipe = array(
    'field_base' => array(),
  );
  $map = features_get_default_map('field_instance');

  // The field_default_field_instances() hook integration is provided by the
  // features module so we need to add it as a dependency.
  $export['dependencies']['features'] = 'features';
  foreach ($data as $identifier) {
    if ($instance = features_field_instance_load($identifier)) {

      // If this field is already provided by another module, remove the field
      // and add the other module as a dependency.
      if (isset($map[$identifier]) && $map[$identifier] != $module_name) {
        if (isset($export['features']['field_instance'][$identifier])) {
          unset($export['features']['field_instance'][$identifier]);
        }
        $module = $map[$identifier];
        $export['dependencies'][$module] = $module;
      }
      else {
        $export['features']['field_instance'][$identifier] = $identifier;
        $export['dependencies'][$instance['widget']['module']] = $instance['widget']['module'];
        foreach ($instance['display'] as $key => $display) {
          if (isset($display['module'])) {
            $export['dependencies'][$display['module']] = $display['module'];

            // @TODO: handle the pipe to image styles
          }
        }
        $pipe['field_base'][] = $instance['field_name'];
      }
    }
  }
  return $pipe;
}