_node_types_build
- Versions
- 5 – 7
_node_types_build()
Builds and returns the list of available node types.
The list of types is built by querying hook_node_info() in all modules, and by comparing this information with the node types in the {node_type} table.
Code
modules/node/node.module, line 662
<?php
function _node_types_build() {
$_node_types = &drupal_static(__FUNCTION__);
if (is_object($_node_types)) {
return $_node_types;
}
$_node_types = (object)array('types' => array(), 'names' => array());
$info_array = module_invoke_all('node_info');
foreach ($info_array as $type => $info) {
$info['type'] = $type;
$_node_types->types[$type] = node_type_set_defaults($info);
$_node_types->names[$type] = $info['name'];
}
$type_result = db_select('node_type', 'nt')
->addTag('translatable')
->addTag('node_type_access')
->fields('nt')
->orderBy('nt.type', 'ASC')
->execute();
foreach ($type_result as $type_object) {
// Check for node types from disabled modules and mark their types for removal.
// Types defined by the node module in the database (rather than by a separate
// module using hook_node_info) have a base value of 'node_content'. The isset()
// check prevents errors on old (pre-Drupal 7) databases.
if (isset($type_object->base) && $type_object->base != 'node_content' && empty($info_array[$type_object->type])) {
$type_object->disabled = TRUE;
}
if (!isset($_node_types->types[$type_object->type]) || $type_object->modified) {
$_node_types->types[$type_object->type] = $type_object;
$_node_types->names[$type_object->type] = $type_object->name;
if ($type_object->type != $type_object->orig_type) {
unset($_node_types->types[$type_object->orig_type]);
unset($_node_types->names[$type_object->orig_type]);
}
}
}
asort($_node_types->names);
return $_node_types;
}
?>Login or register to post comments 