1 node.module | _node_types_build() |
Builds and returns the list of available node types.
This function reads from disk individual config files that define the available content types in the system. Modules may bundle a content type with their module by including a "node.type.[type_name].json" config file in their module's config directory. Each file should contain:
- name: (required) The human-readable name of the node type.
- base: (required) The base string used to construct callbacks corresponding to this node type (for example, if base is defined as example_foo, then example_foo_insert will be called when inserting a node of that type). This string is usually the name of the module, but not always.
- description: (required) A brief description of the node type.
- help: (optional) Help information shown to the user when creating a node of this type.
- has_title: (optional) A Boolean indicating whether or not this node type has a title field.
- title_label: (optional) The label for the title field of this content type.
- locked: (optional) A Boolean indicating whether the administrator can change the machine name of this type. FALSE = changeable (not locked), TRUE = unchangeable (locked).
Return value
An object with two properties::
- names: Associative array of the names of node types, keyed by the type.
- types: Associative array of node type objects, keyed by the type.
These arrays will also include obsolete types: types that were previously defined by modules that have been disabled, likely by a module that was provided a node type and then was disabled. These are indicated in the type object by $type->disabled being set to TRUE.
File
- core/
modules/ node/ node.module, line 698 - The core module that allows content to be submitted to the site.
Code
function _node_types_build() {
$cid = 'node_types:' . $GLOBALS['language']->langcode;
$_node_types = &backdrop_static(__FUNCTION__);
if (isset($_node_types)) {
return $_node_types;
}
if ($cache = cache()->get($cid)) {
$_node_types = $cache->data;
return $_node_types;
}
$_node_types = (object) array('types' => array(), 'names' => array());
module_load_include('inc', 'node', 'node.types');
$config_names = config_get_names_with_prefix('node.type.');
foreach ($config_names as $config_name) {
$node_type_data = config($config_name)->get();
// Check if the node type is disabled or the module is enabled.
$module = $node_type_data['module'];
$module_disabled = TRUE;
if ($module === 'node' || module_exists($module)) {
$module_disabled = FALSE;
}
// If the module is enabled, $disabled is forced to TRUE.
$node_type_data['disabled'] = !empty($node_type_data['disabled']) || $module_disabled;
$type = str_replace('node.type.', '', $config_name);
$_node_types->types[$type] = node_type_set_defaults($node_type_data);
$_node_types->names[$type] = $node_type_data['name'];
}
// Allow modules to load their defaults into the node type info.
foreach (module_implements('node_type_load') as $module) {
$function = $module . '_node_type_load';
$function($_node_types->types);
}
cache()->set($cid, $_node_types);
return $_node_types;
}