You are here

function field_configuration_export in Configuration Management 7

Implements hook_configuration_export().

File

includes/configuration.field.inc, line 38

Code

function field_configuration_export($data, &$export, $module_name = '') {
  $pipe = array();
  $map = configuration_get_default_map('field');

  // The field_default_fields() hook integration is provided by the
  // configuration module so we need to add it as a dependency.
  $export['dependencies']['configuration'] = 'configuration';
  foreach ($data as $identifier) {
    $new_dependencies = array();
    if ($field = configuration_field_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['configuration']['field'][$identifier])) {
          unset($export['configuration']['field'][$identifier]);
        }
        $module = $map[$identifier];
        $export['dependencies'][$module] = $module;
      }

      // If the field has not yet been exported, add it
      $export['configuration']['field'][$identifier] = $identifier;
      $new_dependencies[$field['field_config']['module']] = $field['field_config']['module'];
      $new_dependencies[$field['field_config']['storage']['module']] = $field['field_config']['storage']['module'];
      $new_dependencies[$field['field_instance']['widget']['module']] = $field['field_instance']['widget']['module'];
      foreach ($field['field_instance']['display'] as $key => $display) {
        if (isset($display['module'])) {
          $new_dependencies[$display['module']] = $display['module'];

          // @TODO: handle the pipe to image styles
        }
      }

      // Merge new dependencies with global.
      $export['dependencies'] = array_merge($export['dependencies'], $new_dependencies);

      // If taxonomy field, add in the vocabulary
      if ($field['field_config']['type'] == 'taxonomy_term_reference' && !empty($field['field_config']['settings']['allowed_values'])) {
        foreach ($field['field_config']['settings']['allowed_values'] as $allowed_values) {
          if (!empty($allowed_values['vocabulary'])) {
            $export['configuration_dependency']['configuration']['taxonomy'][$allowed_values['vocabulary']] = $identifier;
            $export['configuration_dependency']['modules']['taxonomy'][$allowed_values['vocabulary']] = serialize($new_dependencies);
            $pipe['taxonomy'][] = $allowed_values['vocabulary'];
          }
        }
      }
    }
  }
  return $pipe;
}