function _content_type_info in Content Construction Kit (CCK) 5
Same name and namespace in other branches
- 6.3 content.module \_content_type_info()
- 6 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 ./
content_copy.module - Get all the fields for a content type.
- content_copy_import_form_submit in ./
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 ./
content_copy.module - Get all content types.
- content_fields in ./
content.module - Return a list of all fields.
File
- ./
content.module, line 755 - Allows administrators to associate custom fields to content types.
Code
function _content_type_info($reset = FALSE) {
static $info;
if ($reset || !isset($info)) {
if ($cached = cache_get('content_type_info', 'cache_content')) {
$info = unserialize($cached->data);
}
else {
$info = array(
'field types' => array(),
'widget types' => array(),
'fields' => array(),
'content types' => array(),
);
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();
}
}
$module_widgets = module_invoke($module, 'widget_info');
if ($module_widgets) {
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;
foreach ($widget_info['field types'] as $delta => $type) {
$info['widget types'][$db_name][$delta] = substr($type, 0, 32);
}
}
}
}
foreach (module_list() as $module) {
$module_formatters = module_invoke($module, 'field_formatter_info');
if ($module_formatters) {
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);
$info['field types'][$db_name]['formatters'][$name] = $formatter_info;
$info['field types'][$db_name]['formatters'][$name]['module'] = $module;
}
}
}
}
$field_result = db_query('SELECT * FROM {node_field}');
while ($field = db_fetch_array($field_result)) {
$global_settings = $field['global_settings'] ? unserialize($field['global_settings']) : array();
unset($field['global_settings']);
// Preventative error handling for PHP5 if field nodule hasn't created an arrray.
if (is_array($global_settings)) {
$field = array_merge($field, $global_settings);
}
$instance_info = db_fetch_array(db_query("SELECT type_name, label FROM {node_field_instance} WHERE field_name = '%s'", $field['field_name']));
$field['widget']['label'] = $instance_info['label'];
$field['type_name'] = $instance_info['type_name'];
$info['fields'][$field['field_name']] = $field;
}
$type_result = db_query('SELECT * FROM {node_type} ORDER BY type ASC');
while ($type = db_fetch_array($type_result)) {
$type['url_str'] = str_replace('_', '-', $type['type']);
$type['fields'] = array();
$field_result = db_query("SELECT * FROM {node_field_instance} nfi WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type['type']);
while ($field = db_fetch_array($field_result)) {
// Overwrite global field information with specific information
$field = array_merge($info['fields'][$field['field_name']], $field);
$widget_settings = $field['widget_settings'] ? unserialize($field['widget_settings']) : array();
unset($field['widget_settings']);
$field['widget'] = $widget_settings;
$field['widget']['type'] = $field['widget_type'];
unset($field['widget_type']);
$field['widget']['weight'] = $field['weight'];
unset($field['weight']);
$field['widget']['label'] = $field['label'];
unset($field['label']);
$field['widget']['description'] = $field['description'];
unset($field['description']);
$field['type_name'] = $type['type'];
$field['display_settings'] = $field['display_settings'] ? unserialize($field['display_settings']) : array();
$type['fields'][$field['field_name']] = $field;
}
$info['content types'][$type['type']] = $type;
}
cache_set('content_type_info', 'cache_content', serialize($info));
}
}
return $info;
}