You are here

function content_associate_fields in Content Construction Kit (CCK) 6.3

Same name and namespace in other branches
  1. 6 content.module \content_associate_fields()
  2. 6.2 content.module \content_associate_fields()

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

Parameters

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

5 calls to content_associate_fields()
content_check_update in ./content.install
Helper function for module updates :
content_notify in ./content.module
Modules notify Content module when uninstalled, disabled, etc.
content_update_6000 in ./content.install
Add module name to fields table to make it easier to identify the fields to delete when a module is uninstalled.
optionwidgets_update_6000 in modules/optionwidgets/optionwidgets.install
Rename widgets from 'options_xxx' to 'optionwidgets_xxx' so hook_elements and hook_themes items are prefixed with module name as they should be.
text_update_6000 in modules/text/text.install
Rename widgets to match hook_elements values.

File

./content.module, line 608
Allows administrators to associate custom fields to content types.

Code

function content_associate_fields($module) {

  // When CCK modules are enabled before content module's update is run,
  // to add module and active columns, we can't do this.
  if (variable_get('content_schema_version', -1) < 6007) {
    return FALSE;
  }
  $module_fields = module_invoke($module, 'field_info');
  if ($module_fields) {
    foreach ($module_fields as $name => $field_info) {
      watchdog('content', 'Updating field type %type with module %module.', array(
        '%type' => $name,
        '%module' => $module,
      ));
      db_query("UPDATE {" . content_field_tablename() . "} SET module = '%s', active = %d WHERE type = '%s'", $module, 1, $name);
    }
  }
  $module_widgets = module_invoke($module, 'widget_info');
  if ($module_widgets) {
    foreach ($module_widgets as $name => $widget_info) {
      watchdog('content', 'Updating widget type %type with module %module.', array(
        '%type' => $name,
        '%module' => $module,
      ));
      db_query("UPDATE {" . content_instance_tablename() . "} SET widget_module = '%s', widget_active = %d WHERE widget_type = '%s'", $module, 1, $name);
    }
  }

  // This is called from updates and installs, so get the install-safe
  // version of a fields array.
  $fields_set = array();
  module_load_include('install', 'content');
  $types = content_types_install();
  foreach ($types as $type_name => $fields) {
    foreach ($fields as $field) {
      if ($field['module'] == $module && !in_array($field['field_name'], $fields_set)) {
        $columns = (array) module_invoke($field['module'], 'field_settings', 'database columns', $field);
        db_query("UPDATE {" . content_field_tablename() . "} SET db_columns = '%s' WHERE field_name = '%s'", serialize($columns), $field['field_name']);
        $fields_set[] = $field['field_name'];
      }
    }
  }
}