function _content_type_info in Content Construction Kit (CCK) 6
Same name and namespace in other branches
- 5 content.module \_content_type_info()
- 6.3 content.module \_content_type_info()
- 6.2 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.
9 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 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.
File
- ./
content.module, line 1221 - Allows administrators to associate custom fields to content types.
Code
function _content_type_info($reset = FALSE) {
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().
if (!db_table_exists(content_field_tablename()) || !db_table_exists(content_instance_tablename())) {
return array();
}
if ($cached = cache_get('content_type_info', 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() as $type_name => $data) {
$type = (array) $data;
$type['url_str'] = str_replace('_', '-', $type['type']);
$type['fields'] = array();
$type['tables'] = array();
$fields = content_field_instance_read(array(
'type_name' => $type_name,
));
foreach ($fields as $field) {
$type['fields'][$field['field_name']] = $field;
$db_info = content_database_info($field);
$type['tables'][$db_info['table']] = $db_info['table'];
$info['fields'][$field['field_name']] = $field;
}
// 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', $info, content_cache_tablename());
}
}
return $info;
}