node_get_types

Definition

node_get_types($op = 'types', $node = NULL, $reset = FALSE)
modules/node/node.module, line 412

Description

Builds a list of available node types, and returns all of part of this list in the specified format.

Parameters

$op The format in which to return the list. When this is set to 'type', 'module', or 'name', only the specified node type is returned. When set to 'types' or 'names', all node types are returned.

$node A node object, array, or string that indicates the node type to return. Leave at default value (NULL) to return a list of all node types.

$reset Whether or not to reset this function's internal cache (defaults to FALSE).

Return value

Either an array of all available node types, or a single node type, in a variable format. Returns FALSE if the node type is not found.

Code

<?php
function node_get_types($op = 'types', $node = NULL, $reset = FALSE) {
  static $_node_types, $_node_names;

  if ($reset || !isset($_node_types)) {
    list($_node_types, $_node_names) = _node_types_build();
  }

  if ($node) {
    if (is_array($node)) {
      $type = $node['type'];
    }
    elseif (is_object($node)) {
      $type = $node->type;
    }
    elseif (is_string($node)) {
      $type = $node;
    }
    if (!isset($_node_types[$type])) {
      return FALSE;
    }
  }
  switch ($op) {
    case 'types':
      return $_node_types;
    case 'type':
      return isset($_node_types[$type]) ? $_node_types[$type] : FALSE;
    case 'module':
      return isset($_node_types[$type]->module) ? $_node_types[$type]->module : FALSE;
    case 'names':
      return $_node_names;
    case 'name':
      return isset($_node_names[$type]) ? $_node_names[$type] : FALSE;
  }
}
?>
 
 

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.