You are here

function field_configuration_export_render in Configuration Management 7

Implements hook_configuration_export_render().

2 calls to field_configuration_export_render()
configuration_check_field in includes/configuration.field.inc
configuration_hash_field in includes/configuration.field.inc

File

includes/configuration.field.inc, line 89

Code

function field_configuration_export_render($module, $data, $export = NULL) {
  $translatables = $code = array();
  $code[] = '  $fields = array();';
  $code[] = '';
  foreach ($data as $identifier) {
    if ($field = configuration_field_load($identifier)) {
      if (!empty($field['field_instance']['widget']) && !isset($field['field_instance']['widget']['active'])) {

        // The first time this setting is exported, the active value is not exported.
        // Set it explicitly to avoid differences when reverting fields
        $field['field_instance']['widget']['active'] = module_exists($field['field_instance']['widget']['module']);
      }
      unset($field['field_config']['columns']);
      unset($field['field_config']['locked']);

      // Only remove the 'storage' declaration if the field is using the default
      // storage type.
      if ($field['field_config']['storage']['type'] == variable_get('field_storage_default', 'field_sql_storage')) {
        unset($field['field_config']['storage']);
      }

      // If we still have a storage declaration here it means that a non-default
      // storage type was altered into to the field definition. And noone would
      // never need to change the 'details' key, so don't render it.
      if (isset($field['field_config']['storage']['details'])) {
        unset($field['field_config']['storage']['details']);
      }
      _field_configuration_export_sort($field);
      $field_export = configuration_var_export($field, '  ');
      $field_identifier = configuration_var_export($identifier);
      $code[] = "  // Exported field: {$field_identifier}";
      $code[] = "  \$fields[{$field_identifier}] = {$field_export};";
      $code[] = "";

      // Add label and description to translatables array.
      if (!empty($field['field_instance']['label'])) {
        $translatables[] = $field['field_instance']['label'];
      }
      if (!empty($field['field_instance']['description'])) {
        $translatables[] = $field['field_instance']['description'];
      }
    }
  }
  if (!empty($translatables)) {
    $code[] = configuration_translatables_export($translatables, '  ');
  }
  $code[] = '  return $fields;';
  $code = implode("\n", $code);
  return array(
    'field_default_fields' => $code,
  );
}