You are here

function _content_type_info in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 5 content.module \_content_type_info()
  2. 6.3 content.module \_content_type_info()
  3. 6 content.module \_content_type_info()

Collate all information on content types, fields, and related structures.

Parameters

$reset: If TRUE, clear the cache and fetch the information from the database again.

8 calls to _content_type_info()
content_clear_type_cache in ./content.module
Clear the cache of content_types; called in several places when content information is changed.
content_copy_fields in modules/content_copy/content_copy.module
Get all the *active* fields for a content type.
content_copy_import_form_submit in modules/content_copy/content_copy.module
Submit handler for import form. For each submitted field: 1) add new field to the database 2) execute the imported field macro to update the settings to the imported values
content_copy_types in modules/content_copy/content_copy.module
Get all content types.
content_fields in ./content.module
Return a list of all fields.

... See full list

File

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

Code

function _content_type_info($reset = FALSE) {
  global $language;
  static $info;
  if ($reset || !isset($info)) {

    // Make sure this function doesn't run until the tables have been created,
    // For instance: when first enabled and called from content_menu(),
    // or when uninstalled and some subsequent field module uninstall
    // attempts to refresh the data.
    // Don't try this before content module's update is run
    // to add module and active columns to the table.
    if (variable_get('content_schema_version', -1) < 6007) {
      return array();
    }
    if (!$reset && ($cached = cache_get('content_type_info:' . $language->language, content_cache_tablename()))) {
      $info = $cached->data;
    }
    else {
      $info = array(
        'field types' => array(),
        'widget types' => array(),
        'fields' => array(),
        'content types' => array(),
      );

      // Populate field types.
      foreach (module_list() as $module) {
        $module_field_types = module_invoke($module, 'field_info');
        if ($module_field_types) {
          foreach ($module_field_types as $name => $field_info) {

            // Truncate names to match the value that is stored in the database.
            $db_name = substr($name, 0, 32);
            $info['field types'][$db_name] = $field_info;
            $info['field types'][$db_name]['module'] = $module;
            $info['field types'][$db_name]['formatters'] = array();
          }
        }
      }

      // Populate widget types and formatters for known field types.
      foreach (module_list() as $module) {
        if ($module_widgets = module_invoke($module, 'widget_info')) {
          foreach ($module_widgets as $name => $widget_info) {

            // Truncate names to match the value that is stored in the database.
            $db_name = substr($name, 0, 32);
            $info['widget types'][$db_name] = $widget_info;
            $info['widget types'][$db_name]['module'] = $module;

            // Replace field types with db_compatible version of known field types.
            $info['widget types'][$db_name]['field types'] = array();
            foreach ($widget_info['field types'] as $field_type) {
              $field_type_db_name = substr($field_type, 0, 32);
              if (isset($info['field types'][$field_type_db_name])) {
                $info['widget types'][$db_name]['field types'][] = $field_type_db_name;
              }
            }
          }
        }
        if ($module_formatters = module_invoke($module, 'field_formatter_info')) {
          foreach ($module_formatters as $name => $formatter_info) {
            foreach ($formatter_info['field types'] as $field_type) {

              // Truncate names to match the value that is stored in the database.
              $db_name = substr($field_type, 0, 32);
              if (isset($info['field types'][$db_name])) {
                $info['field types'][$db_name]['formatters'][$name] = $formatter_info;
                $info['field types'][$db_name]['formatters'][$name]['module'] = $module;
              }
            }
          }
        }
      }

      // Populate actual field instances.
      module_load_include('inc', 'content', 'includes/content.crud');
      foreach (node_get_types('types', NULL, TRUE) as $type_name => $data) {
        $type = (array) $data;
        $type['url_str'] = str_replace('_', '-', $type['type']);
        $type['fields'] = array();
        $type['tables'] = array();
        if ($fields = content_field_instance_read(array(
          'type_name' => $type_name,
        ))) {
          foreach ($fields as $field) {
            $db_info = content_database_info($field);
            $type['tables'][$db_info['table']] = $db_info['table'];

            // Allow external modules to translate field strings.
            $field_strings = array(
              'widget_label' => $field['widget']['label'],
              'widget_description' => $field['widget']['description'],
            );
            drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']);
            $field['widget']['label'] = $field_strings['widget_label'];
            $field['widget']['description'] = $field_strings['widget_description'];
            $type['fields'][$field['field_name']] = $field;

            // This means that content_fields($field_name) (no type name)
            // returns the last instance loaded.
            $info['fields'][$field['field_name']] = $field;
          }

          // Make sure the per-type table is added, even if no field is actually
          // stored in it.
          $table = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
          $type['tables'][$table] = $table;
        }

        // Gather information about non-CCK 'fields'.
        $extra = module_invoke_all('content_extra_fields', $type_name);
        drupal_alter('content_extra_fields', $extra, $type_name);

        // Add saved weights.
        foreach (variable_get('content_extra_weights_' . $type_name, array()) as $key => $value) {

          // Some stored entries might not exist anymore, for instance if uploads
          // have been disabled, or vocabularies removed...
          if (isset($extra[$key])) {
            $extra[$key]['weight'] = $value;
          }
        }
        $type['extra'] = $extra;
        $info['content types'][$type_name] = $type;
      }
      cache_set('content_type_info:' . $language->language, $info, content_cache_tablename());
    }
  }
  return $info;
}