diff -u b/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php
--- b/core/modules/node/lib/Drupal/node/NodeFormController.php
+++ b/core/modules/node/lib/Drupal/node/NodeFormController.php
@@ -376,14 +376,14 @@
$node->save();
$node_link = l(t('view'), 'node/' . $node->nid);
$watchdog_args = array('@type' => $node->type, '%title' => $node->label());
- $t_args = array('@type' => node_type_get_label($node->type), '%title' => $node->label());
+ $t_args = array('@type' => node_type_get_name($node), '%title' => $node->label());
if ($insert) {
watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
$node->save();
$node_link = l(t('view'), 'node/' . $node->nid);
$watchdog_args = array('@type' => $node->type, '%title' => $node->label());
- $t_args = array('@type' => node_type_get_name($node), '%title' => $node->label());
+ $t_args = array('@type' => node_get_type_label($node), '%title' => $node->label());
if ($insert) {
watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
diff -u b/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php
--- b/core/modules/node/lib/Drupal/node/NodeStorageController.php
+++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php
@@ -167,9 +167,8 @@
// Call object type specific callbacks on each typed array of nodes.
foreach ($typed_nodes as $node_type => $nodes_of_type) {
- // Retrieve the node type 'base' hook implementation based on a Node in
- // the type-specific stack.
- if ($function = node_hook($node_type, 'load')) {
+ if (node_hook($node_type, 'load')) {
+ $function = node_type_get_base($node_type) . '_load';
$function($nodes_of_type);
}
}
@@ -177,8 +176,9 @@
// 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($node_type, 'load')) {
$function($nodes_of_type);
}
}
diff -u b/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc
--- b/core/modules/node/node.admin.inc
+++ b/core/modules/node/node.admin.inc
@@ -492,7 +492,7 @@
'#suffix' => ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))),
),
),
- 'type' => check_plain(node_type_get_label($node->type)),
+ '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 -u b/core/modules/node/node.module b/core/modules/node/node.module
--- b/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -466,0 +467,14 @@
+ * Returns the node type label for the passed node.
+ *
+ * @param Drupal\node\Node $node
+ * A node entity to return the node type's label for.
+ *
+ * @return string|false
+ * The node type label or FALSE if the node type is not found.
+ */
+function node_get_type_label(Node $node) {
+ $types = _node_types_build()->names;
+ return isset($types[$node->type]) ? $types[$node->type] : FALSE;
+}
+
+/**
@@ -933,48 +947,48 @@
/**
* Determines whether a node hook exists.
*
- * @param string $type
- * A string containing the node type.
+ * @param Drupal\node\Node|string $node
+ * A node entity or a string containing the node type.
* @param $hook
* A string containing the name of the hook.
*
- * @return string|false
- * A string containing the function name or FALSE if it isn't found.
+ * @return
+ * TRUE if the $hook exists in the node type of $node.
*/
-function node_hook($type, $hook) {
- $base = node_type_get_base($type);
- return module_hook($base, $hook) ? $base . '_' . $hook : FALSE;
+function node_hook($node, $hook) {
+ $base = node_type_get_base($node);
+ return module_hook($base, $hook);
}
/**
* Invokes a node hook.
*
- * @param Drupal\node\Node $node
- * A Node entity.
+ * @param Drupal\node\Node|string $node
+ * A node entity or a string containing the node type.
* @param $hook
* A string containing the name of the hook.
* @param $a2, $a3, $a4
/**
* Determines whether a node hook exists.
*
- * @param Drupal\node\Node|string $node
- * A node entity or a string containing the node type.
+ * @param string $type
+ * A string containing the node type.
* @param $hook
* A string containing the name of the hook.
*
- * @return
- * TRUE if the $hook exists in the node type of $node.
+ * @return string|false
+ * A string containing the function name or FALSE if it isn't found.
*/
-function node_hook($node, $hook) {
- $base = node_type_get_base($node);
- return module_hook($base, $hook);
+function node_hook($type, $hook) {
+ $base = node_type_get_base($type);
+ return module_hook($base, $hook) ? $base . '_' . $hook : FALSE;
}
/**
* 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
@@ -1584,7 +1598,7 @@
$uri = $node->uri();
$results[] = array(
'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))),
- 'type' => check_plain(node_type_get_label($node->type)),
+ '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),
@@ -3691,7 +3705,7 @@
*/
function node_publish_action(Node $node, $context = array()) {
$node->status = NODE_PUBLISHED;
- watchdog('action', 'Set @type %title to published.', array('@type' => node_type_get_label($node->type), '%title' => $node->label()));
+ watchdog('action', 'Set @type %title to published.', array('@type' => node_get_type_label($node), '%title' => $node->label()));
}
/**
@@ -3707,7 +3721,7 @@
*/
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_label($node->type), '%title' => $node->label()));
+ watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_type_label($node), '%title' => $node->label()));
}
/**
@@ -3723,7 +3737,7 @@
*/
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_label($node->type), '%title' => $node->label()));
+ watchdog('action', 'Set @type %title to sticky.', array('@type' => node_get_type_label($node), '%title' => $node->label()));
}
/**
@@ -3739,7 +3753,7 @@
*/
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_label($node->type), '%title' => $node->label()));
+ watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_get_type_label($node), '%title' => $node->label()));
}
/**
@@ -3755,7 +3769,7 @@
*/
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_label($node->type), '%title' => $node->label()));
+ watchdog('action', 'Promoted @type %title to front page.', array('@type' => node_get_type_label($node), '%title' => $node->label()));
}
/**
@@ -3771,7 +3785,7 @@
*/
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_label($node->type), '%title' => $node->label()));
+ watchdog('action', 'Removed @type %title from front page.', array('@type' => node_get_type_label($node), '%title' => $node->label()));
}
/**
@@ -3784,7 +3798,7 @@
*/
function node_save_action(Node $node) {
$node->save();
- watchdog('action', 'Saved @type %title', array('@type' => node_type_get_label($node->type), '%title' => $node->label()));
+ watchdog('action', 'Saved @type %title', array('@type' => node_get_type_label($node), '%title' => $node->label()));
}
/**
@@ -3805,7 +3819,7 @@
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_label($node->type), '%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));
}
/**
@@ -3921,7 +3935,7 @@
$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_label($node->type), '%title' => $node->label()));
+ watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_type_label($node), '%title' => $node->label()));
break;
}
}
diff -u b/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc
--- b/core/modules/node/node.pages.inc
+++ b/core/modules/node/node.pages.inc
@@ -17,7 +17,7 @@
* @see node_menu()
*/
function node_page_edit($node) {
- drupal_set_title(t('Edit @type @title', array('@type' => node_type_get_label($node->type), '@title' => $node->label())), PASS_THROUGH);
+ drupal_set_title(t('Edit @type @title', array('@type' => node_get_type_label($node), '@title' => $node->label())), PASS_THROUGH);
return entity_get_form($node);
}
@@ -209,7 +209,7 @@
$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_label($node->type), '%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'] = '';
@@ -302,7 +302,7 @@
$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_label($node_revision->type), '%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';
}
@@ -327,7 +327,7 @@
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_label($node_revision->type), '%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 -u b/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc
--- b/core/modules/node/node.tokens.inc
+++ b/core/modules/node/node.tokens.inc
@@ -125,7 +125,7 @@
break;
case 'type-name':
- $type_name = node_type_get_label($node->type);
+ $type_name = node_get_type_label($node);
$replacements[$original] = $sanitize ? check_plain($type_name) : $type_name;
break;
diff -u b/core/modules/search/search.api.php b/core/modules/search/search.api.php
--- b/core/modules/search/search.api.php
+++ b/core/modules/search/search.api.php
@@ -239,7 +239,7 @@
$uri = $node->uri();
$results[] = array(
'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))),
- 'type' => check_plain(node_type_get_label($node->type)),
+ '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 -u b/core/modules/system/system.api.php b/core/modules/system/system.api.php
--- b/core/modules/system/system.api.php
+++ b/core/modules/system/system.api.php
@@ -2003,7 +2003,7 @@
$variables += array(
'%uid' => $node->uid,
'%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
- '%node_type' => node_type_get_label($node->type),
+ '%node_type' => node_get_type_label($node),
'%title' => $node->title,
'%teaser' => $node->teaser,
'%body' => $node->body,
diff -u b/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc
--- b/core/modules/tracker/tracker.pages.inc
+++ b/core/modules/tracker/tracker.pages.inc
@@ -70,7 +70,7 @@
}
$row = array(
- 'type' => check_plain(node_type_get_label($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))),