diff --git a/modules/node/node.install b/modules/node/node.install index e50571ab284..4cf1d04b033 100644 --- a/modules/node/node.install +++ b/modules/node/node.install @@ -521,7 +521,7 @@ function node_update_7004() { // Map old preview setting to new values order. $original_preview ? $original_preview = 2 : $original_preview = 1; - drupal_static_reset('_node_types_build'); + node_type_cache_reset(); // Apply original settings to all types. foreach (_update_7000_node_get_types() as $type => $type_object) { @@ -552,7 +552,7 @@ function node_update_7006(&$sandbox) { $sandbox['#finished'] = 0; // Get node type info for every invocation. - drupal_static_reset('_node_types_build'); + node_type_cache_reset(); if (!isset($sandbox['total'])) { // Initial invocation. diff --git a/modules/node/node.module b/modules/node/node.module index ae193a68d4d..831dc734e0a 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -533,7 +533,7 @@ function node_type_save($info) { } // Clear the node type cache. - drupal_static_reset('_node_types_build'); + node_type_cache_reset(); return $status; } @@ -624,7 +624,7 @@ function node_type_delete($type) { module_invoke_all('node_type_delete', $info); // Clear the node type cache. - drupal_static_reset('_node_types_build'); + node_type_cache_reset(); } /** @@ -669,14 +669,20 @@ function node_type_update_nodes($old_type, $type) { * type object by $type->disabled being set to TRUE. */ function _node_types_build($rebuild = FALSE) { + $cid = 'node_types:' . $GLOBALS['language']->language; + if (!$rebuild) { $_node_types = &drupal_static(__FUNCTION__); - if (is_object($_node_types)) { + 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()); + $_node_types = (object) array('types' => array(), 'names' => array()); foreach (module_implements('node_info') as $module) { $info_array = module_invoke($module, 'node_info'); @@ -732,9 +738,19 @@ function _node_types_build($rebuild = FALSE) { asort($_node_types->names); + cache_set($cid, $_node_types); + return $_node_types; } +/** + * Clears the node type cache. + */ +function node_type_cache_reset() { + cache_clear_all('node_types:', 'cache', TRUE); + drupal_static_reset('_node_types_build'); +} + /** * Set the default values for a node type. * @@ -746,33 +762,26 @@ function _node_types_build($rebuild = FALSE) { * An object or array containing values to override the defaults. * * @return - * A node type object. + * A node type object. */ function node_type_set_defaults($info = array()) { - $type = &drupal_static(__FUNCTION__); - - if (!isset($type)) { - $type = new stdClass(); - $type->type = ''; - $type->name = ''; - $type->base = ''; - $type->description = ''; - $type->help = ''; - $type->custom = 0; - $type->modified = 0; - $type->locked = 1; - $type->disabled = 0; - $type->is_new = 1; - - $type->has_title = 1; - $type->title_label = 'Title'; - } - - $new_type = clone $type; $info = (array) $info; - foreach ($info as $key => $data) { - $new_type->$key = $data; - } + $new_type = $info + array( + 'type' => '', + 'name' => '', + 'base' => '', + 'description' => '', + 'help' => '', + 'custom' => 0, + 'modified' => 0, + 'locked' => 1, + 'disabled' => 0, + 'is_new' => 1, + 'has_title' => 1, + 'title_label' => 'Title', + ); + $new_type = (object) $new_type; + // If the type has no title, set an empty label. if (!$new_type->has_title) { $new_type->title_label = ''; @@ -1935,7 +1944,7 @@ function node_menu() { // @todo Remove this loop when we have a 'description callback' property. // Reset internal static cache of _node_types_build(), forces to rebuild the // node type information. - drupal_static_reset('_node_types_build'); + node_type_cache_reset(); foreach (node_type_get_types() as $type) { $type_url_str = str_replace('_', '-', $type->type); $items['node/add/' . $type_url_str] = array(