diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 30b1e6b..9a5fba6 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -180,7 +180,7 @@ function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) { $links[$type] = array( '#theme' => 'menu_local_action', '#link' => array( - 'title' => t('Add new @node_type', array('@node_type' => node_type_get_name($type))), + 'title' => t('Add new @node_type', array('@node_type' => node_type_get_label($type))), 'href' => 'node/add/' . $type . '/' . $forum_term->tid, ), ); diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index c5763e8..408b650 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -87,8 +87,8 @@ class NodeFormController extends EntityFormController { // because hook_form() needs to be able to receive $form_state by reference. // @todo hook_form() implementations are unable to add #validate or #submit // handlers to the form buttons below. Remove hook_form() entirely. - $function = node_type_get_base($node) . '_form'; - if (function_exists($function) && ($extra = $function($node, $form_state))) { + $function = node_hook($node, 'form'); + if ($function && ($extra = $function($node, $form_state))) { $form = array_merge_recursive($form, $extra); } // If the node type has a title, and the node type form defined no special diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index ee47546..b023c56 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -167,8 +167,9 @@ class NodeStorageController extends DatabaseStorageController { // Call object type specific callbacks on each typed array of nodes. foreach ($typed_nodes as $node_type => $nodes_of_type) { - if (node_hook($node_type, 'load')) { - $function = node_type_get_base($node_type) . '_load'; + // Retrieve the node type 'base' hook implementation based on a Node in + // the type-specific stack. + if ($function = node_hook(current($nodes_of_type), 'load')) { $function($nodes_of_type); } } diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index 0bf8a91..e92cd85 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -492,7 +492,7 @@ function node_admin_nodes() { '#suffix' => ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))), ), ), - 'type' => check_plain(node_type_get_name($node)), + 'type' => check_plain(node_get_type_label($node)), 'author' => theme('username', array('account' => $node)), 'status' => $node->status ? t('published') : t('not published'), 'changed' => format_date($node->changed, 'short'), diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 349aab5..17d9ab2 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -130,7 +130,7 @@ function node_help($path, $arg) { case 'admin/structure/types/manage/%/display': return '

' . t('Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. Teaser is a short format that is typically used in lists of multiple content items. Full content is typically used when the content is displayed on its own page.') . '

' . - '

' . t('Here, you can define which fields are shown and hidden when %type content is displayed in each view mode, and define how the fields are displayed in each view mode.', array('%type' => node_type_get_name($arg[4]))) . '

'; + '

' . t('Here, you can define which fields are shown and hidden when %type content is displayed in each view mode, and define how the fields are displayed in each view mode.', array('%type' => node_type_get_label($arg[4]))) . '

'; case 'node/%/revisions': return '

' . t('Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.') . '

'; @@ -401,16 +401,17 @@ function node_mark($nid, $timestamp) { } /** - * Extracts the type name. + * Returns the node type label for the passed Node. * - * @param Drupal\node\Node|string $node - * Either a string or object, containing the node type information. + * @param Drupal\node\Node $node + * A Node entity. * - * @return - * Node type of the passed-in data. + * @return string|false + * The node type label or FALSE if the node type is not found. */ -function _node_extract_type($node) { - return is_object($node) ? $node->type : $node; +function node_get_type_label(Node $node) { + $types = _node_types_build()->names; + return isset($types[$node->type]) ? $types[$node->type] : FALSE; } /** @@ -435,18 +436,17 @@ function node_type_get_types() { * execute node-type-specific hooks. For types defined in the user interface * and managed by node.module, the base is 'node_content'. * - * @param Drupal\node\Node|string $node - * A node entity or string that indicates the node type to return. + * @param Drupal\node\Node $node + * A Node entity. * * @return * The node type base or FALSE if the node type is not found. * * @see node_invoke() */ -function node_type_get_base($node) { - $type = _node_extract_type($node); +function node_type_get_base(Node $node) { $types = _node_types_build()->types; - return isset($types[$type]) && isset($types[$type]->base) ? $types[$type]->base : FALSE; + return isset($types[$node->type]->base) ? $types[$node->type]->base : FALSE; } /** @@ -456,25 +456,24 @@ function node_type_get_base($node) { * See _node_types_build() for details. * * @return - * An array of node type names, keyed by the type. + * An array of node type labels, keyed by the node type name. */ function node_type_get_names() { return _node_types_build()->names; } /** - * Returns the node type name of the passed node or node type string. + * Returns the node type label for the passed node type name. * - * @param Drupal\node\Node|string $node - * A node entity or string that indicates the node type to return. + * @param string $name + * The machine name of a node type. * - * @return - * The node type name or FALSE if the node type is not found. + * @return string|false + * The node type label or FALSE if the node type is not found. */ -function node_type_get_name($node) { - $type = _node_extract_type($node); +function node_type_get_label($name) { $types = _node_types_build()->names; - return isset($types[$type]) ? $types[$type] : FALSE; + return isset($types[$name]) ? $types[$name] : FALSE; } /** @@ -946,15 +945,15 @@ function node_rdf_mapping() { /** * Determines whether a node hook exists. * - * @param Drupal\node\Node|string $node - * A node entity or a string containing the node type. + * @param Drupal\node\Node $node + * A Node entity. * @param $hook * A string containing the name of the hook. * * @return * TRUE if the $hook exists in the node type of $node. */ -function node_hook($node, $hook) { +function node_hook(Node $node, $hook) { $base = node_type_get_base($node); return module_hook($base, $hook); } @@ -962,8 +961,8 @@ function node_hook($node, $hook) { /** * Invokes a node hook. * - * @param Drupal\node\Node|string $node - * A node entity or a string containing the node type. + * @param Drupal\node\Node $node + * A Node entity. * @param $hook * A string containing the name of the hook. * @param $a2, $a3, $a4 @@ -972,11 +971,9 @@ function node_hook($node, $hook) { * @return * The returned value of the invoked hook. */ -function node_invoke($node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { - if (node_hook($node, $hook)) { - $base = node_type_get_base($node); - $function = $base . '_' . $hook; - return ($function($node, $a2, $a3, $a4)); +function node_invoke(Node $node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { + if ($function = node_hook($node, $hook)) { + return $function($node, $a2, $a3, $a4); } } @@ -1575,7 +1572,7 @@ function node_search_execute($keys = NULL, $conditions = NULL) { $uri = $node->uri(); $results[] = array( 'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))), - 'type' => check_plain(node_type_get_name($node)), + 'type' => check_plain(node_get_type_label($node)), 'title' => $node->label($item->langcode), 'user' => theme('username', array('account' => $node)), 'date' => $node->get('changed', $item->langcode), @@ -3679,7 +3676,7 @@ function node_action_info() { */ function node_publish_action(Node $node, $context = array()) { $node->status = NODE_PUBLISHED; - watchdog('action', 'Set @type %title to published.', array('@type' => node_type_get_name($node), '%title' => $node->label())); + watchdog('action', 'Set @type %title to published.', array('@type' => node_get_type_label($node), '%title' => $node->label())); } /** @@ -3695,7 +3692,7 @@ function node_publish_action(Node $node, $context = array()) { */ function node_unpublish_action(Node $node, $context = array()) { $node->status = NODE_NOT_PUBLISHED; - watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->label())); + watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_type_label($node), '%title' => $node->label())); } /** @@ -3711,7 +3708,7 @@ function node_unpublish_action(Node $node, $context = array()) { */ function node_make_sticky_action(Node $node, $context = array()) { $node->sticky = NODE_STICKY; - watchdog('action', 'Set @type %title to sticky.', array('@type' => node_type_get_name($node), '%title' => $node->label())); + watchdog('action', 'Set @type %title to sticky.', array('@type' => node_get_type_label($node), '%title' => $node->label())); } /** @@ -3727,7 +3724,7 @@ function node_make_sticky_action(Node $node, $context = array()) { */ function node_make_unsticky_action(Node $node, $context = array()) { $node->sticky = NODE_NOT_STICKY; - watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_type_get_name($node), '%title' => $node->label())); + watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_get_type_label($node), '%title' => $node->label())); } /** @@ -3743,7 +3740,7 @@ function node_make_unsticky_action(Node $node, $context = array()) { */ function node_promote_action(Node $node, $context = array()) { $node->promote = NODE_PROMOTED; - watchdog('action', 'Promoted @type %title to front page.', array('@type' => node_type_get_name($node), '%title' => $node->label())); + watchdog('action', 'Promoted @type %title to front page.', array('@type' => node_get_type_label($node), '%title' => $node->label())); } /** @@ -3759,7 +3756,7 @@ function node_promote_action(Node $node, $context = array()) { */ function node_unpromote_action(Node $node, $context = array()) { $node->promote = NODE_NOT_PROMOTED; - watchdog('action', 'Removed @type %title from front page.', array('@type' => node_type_get_name($node), '%title' => $node->label())); + watchdog('action', 'Removed @type %title from front page.', array('@type' => node_get_type_label($node), '%title' => $node->label())); } /** @@ -3772,7 +3769,7 @@ function node_unpromote_action(Node $node, $context = array()) { */ function node_save_action(Node $node) { $node->save(); - watchdog('action', 'Saved @type %title', array('@type' => node_type_get_name($node), '%title' => $node->label())); + watchdog('action', 'Saved @type %title', array('@type' => node_get_type_label($node), '%title' => $node->label())); } /** @@ -3793,7 +3790,7 @@ function node_save_action(Node $node) { function node_assign_owner_action(Node $node, $context) { $node->uid = $context['owner_uid']; $owner_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchField(); - watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_type_get_name($node), '%title' => $node->label(), '%name' => $owner_name)); + watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_get_type_label($node), '%title' => $node->label(), '%name' => $owner_name)); } /** @@ -3909,7 +3906,7 @@ function node_unpublish_by_keyword_action(Node $node, $context) { $elements = node_view(clone $node); if (strpos(drupal_render($elements), $keyword) !== FALSE || strpos($node->label(), $keyword) !== FALSE) { $node->status = NODE_NOT_PUBLISHED; - watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->label())); + watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_type_label($node), '%title' => $node->label())); break; } } diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index b2e1e4b..4cff983 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -16,9 +16,8 @@ use Drupal\node\Node; * * @see node_menu() */ -function node_page_edit($node) { - $type_name = node_type_get_name($node); - drupal_set_title(t('Edit @type @title', array('@type' => $type_name, '@title' => $node->label())), PASS_THROUGH); +function node_page_edit(Node $node) { + drupal_set_title(t('Edit @type @title', array('@type' => node_get_type_label($node), '@title' => $node->label())), PASS_THROUGH); return entity_get_form($node); } @@ -210,7 +209,7 @@ function node_delete_confirm_submit($form, &$form_state) { $node = node_load($form_state['values']['nid']); node_delete($form_state['values']['nid']); watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->label())); - drupal_set_message(t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->label()))); + drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_type_label($node), '%title' => $node->label()))); } $form_state['redirect'] = ''; @@ -301,7 +300,7 @@ function node_revision_revert_confirm_submit($form, &$form_state) { $node_revision->save(); watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->label(), '%revision' => $node_revision->vid)); - drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_type_get_name($node_revision), '%title' => $node_revision->label(), '%revision-date' => format_date($original_revision_timestamp)))); + drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_get_type_label($node_revision), '%title' => $node_revision->label(), '%revision-date' => format_date($original_revision_timestamp)))); $form_state['redirect'] = 'node/' . $node_revision->nid . '/revisions'; } @@ -326,7 +325,7 @@ function node_revision_delete_confirm_submit($form, &$form_state) { node_revision_delete($node_revision->vid); watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->label(), '%revision' => $node_revision->vid)); - drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_type_get_name($node_revision), '%title' => $node_revision->label()))); + drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_get_type_label($node_revision), '%title' => $node_revision->label()))); $form_state['redirect'] = 'node/' . $node_revision->nid; if (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node_revision->nid))->fetchField() > 1) { $form_state['redirect'] .= '/revisions'; diff --git a/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc index 1b37fc8..96247aa 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -125,7 +125,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr break; case 'type-name': - $type_name = node_type_get_name($node); + $type_name = node_get_type_label($node); $replacements[$original] = $sanitize ? check_plain($type_name) : $type_name; break; diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index 4c24475..32fb82f 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -239,7 +239,7 @@ function hook_search_execute($keys = NULL, $conditions = NULL) { $uri = $node->uri(); $results[] = array( 'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))), - 'type' => check_plain(node_type_get_name($node)), + 'type' => check_plain(node_get_type_label($node)), 'title' => $node->label($item->langcode), 'user' => theme('username', array('account' => $node)), 'date' => $node->get('changed', $item->langcode), diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 13dd567..c467aa6 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -2004,7 +2004,7 @@ function hook_mail($key, &$message, $params) { $variables += array( '%uid' => $node->uid, '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)), - '%node_type' => node_type_get_name($node), + '%node_type' => node_get_type_label($node), '%title' => $node->title, '%teaser' => $node->teaser, '%body' => $node->body, diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc index f012264..853f50d 100644 --- a/core/modules/tracker/tracker.pages.inc +++ b/core/modules/tracker/tracker.pages.inc @@ -70,7 +70,7 @@ function tracker_page($account = NULL, $set_title = FALSE) { } $row = array( - 'type' => check_plain(node_type_get_name($node->type)), + 'type' => check_plain(node_get_type_label($node)), // Do not use $node->label(), because $node comes from the database. 'title' => array('data' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed)))), 'author' => array('data' => theme('username', array('account' => $node))),