1 field.module field_associate_fields($module, &$fields = NULL)

Allows a module to update the database for fields and columns it controls.

@since 1.18.4 Second parameter $fields added for performance optimization.

Parameters

$module: The name of the module to update on.

$fields: An optional array of field definitions to operate on. If left empty, all fields will be loaded.

Related topics

File

core/modules/field/field.module, line 646
Attach custom data fields to Backdrop entities.

Code

function field_associate_fields($module, &$fields = NULL) {
  // Associate field types.
  $field_types = (array) module_invoke($module, 'field_info');
  $storage_types = (array) module_invoke($module, 'field_storage_info');

  // If this module does not provide any field types or storage types, then
  // nothing needs to be done.
  if (empty($field_types) && empty($storage_types)) {
    return;
  }

  // If no fields were provided, then load all of them.
  if (is_null($fields)) {
    $fields = field_read_fields();
  }

  foreach (array_keys($fields) as $field_name) {
    $old_field = $fields[$field_name];
    if (array_key_exists($fields[$field_name]['type'], $field_types)) {
      $fields[$field_name]['module'] = $module;
      $fields[$field_name]['active'] = 1;
    }
    if (array_key_exists($fields[$field_name]['storage']['type'], $storage_types)) {
      $fields[$field_name]['storage']['module'] = $module;
      $fields[$field_name]['storage']['active'] = 1;
    }
    if ($old_field !== $fields[$field_name]) {
      field_update_field($fields[$field_name]);
    }
  }
}