_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.

▾ 5 functions call _node_types_build()

node_type_get_base in modules/node/node.module
Returns the node type base of the passed node or node type string.
node_type_get_name in modules/node/node.module
Returns the node type name of the passed node or node type string.
node_type_get_names in modules/node/node.module
Returns a list of available node names.
node_type_get_type in modules/node/node.module
Returns the node type of the passed node or node type string.
node_type_get_types in modules/node/node.module
Returns a list of all the available node types.

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
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.