| Versionen | |
|---|---|
| drupal7 | _field_info_collate_types($reset = FALSE) |
Collate all information on field types, widget types and related structures.
$reset If TRUE, clear the cache. The information will be rebuilt from the database next time it is needed. Defaults to FALSE.
If $reset is TRUE, nothing. If $reset is FALSE, an array containing the following elements:
field types: array of hook_field_info() results, keyed by field_type.
widget types: array of hook_field_widget_info() results, keyed by widget_type.
formatter types: array of hook_field_formatter_info() results, keyed by formatter_type.
fieldable types: array of hook_fieldable_info() results, keyed by entity_type.
modules/
<?php
function _field_info_collate_types($reset = FALSE) {
static $info;
if ($reset) {
$info = NULL;
cache_clear_all('field_info_types', 'cache_field');
return;
}
if (!isset($info)) {
if ($cached = cache_get('field_info_types', 'cache_field')) {
$info = $cached->data;
}
else {
$info = array(
'field types' => array(),
'widget types' => array(),
'formatter types' => array(),
'fieldable types' => array(),
);
// Populate field types.
foreach (module_implements('field_info') as $module) {
$field_types = (array) module_invoke($module, 'field_info');
foreach ($field_types as $name => $field_info) {
$info['field types'][$name] = $field_info;
$info['field types'][$name]['module'] = $module;
}
}
// Populate widget types.
foreach (module_implements('field_widget_info') as $module) {
$widget_types = (array) module_invoke($module, 'field_widget_info');
foreach ($widget_types as $name => $widget_info) {
$info['widget types'][$name] = $widget_info;
$info['widget types'][$name]['module'] = $module;
}
}
// Populate formatters.
foreach (module_implements('field_formatter_info') as $module) {
$formatter_types = (array) module_invoke($module, 'field_formatter_info');
foreach ($formatter_types as $name => $formatter_info) {
$info['formatter types'][$name] = $formatter_info;
$info['formatter types'][$name]['module'] = $module;
}
}
// Populate information about 'fieldable' entities.
foreach (module_implements('fieldable_info') as $module) {
$fieldable_types = (array) module_invoke($module, 'fieldable_info');
foreach ($fieldable_types as $name => $fieldable_info) {
// Provide defaults.
$fieldable_info += array(
'revision key' => '',
'bundle key' => '',
'cacheable' => TRUE,
'bundles' => array(),
);
// If no bundle key provided, then we assume a single bundle, named
// after the type of the object. Make sure the bundle created
// has the human-readable name we need for bundle messages.
if (empty($fieldable_info['bundle key'])) {
$fieldable_info['bundles'] = array($name => $fieldable_info['name']);
}
$info['fieldable types'][$name] = $fieldable_info;
$info['fieldable types'][$name]['module'] = $module;
}
}
cache_set('field_info_types', $info, 'cache_field');
}
}
return $info;
}
?>
Kommentare
Kommentar hinzufügen