Issue #2587337 by sdstyles: hook_node_links_alter() names its parameters differently from its implementations

8.1.x
Nathaniel Catchpole 2016-02-03 17:42:10 +09:00
parent 33ba34e3ea
commit 055590603e
3 changed files with 15 additions and 15 deletions

View File

@ -88,7 +88,7 @@ function book_entity_type_build(array &$entity_types) {
/** /**
* Implements hook_node_links_alter(). * Implements hook_node_links_alter().
*/ */
function book_node_links_alter(array &$node_links, NodeInterface $node, array &$context) { function book_node_links_alter(array &$links, NodeInterface $node, array &$context) {
if ($context['view_mode'] != 'rss') { if ($context['view_mode'] != 'rss') {
$account = \Drupal::currentUser(); $account = \Drupal::currentUser();
@ -97,14 +97,14 @@ function book_node_links_alter(array &$node_links, NodeInterface $node, array &$
$child_type = \Drupal::config('book.settings')->get('child_type'); $child_type = \Drupal::config('book.settings')->get('child_type');
$access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node'); $access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node');
if (($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines')) && $access_control_handler->createAccess($child_type) && $node->isPublished() && $node->book['depth'] < BookManager::BOOK_MAX_DEPTH) { if (($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines')) && $access_control_handler->createAccess($child_type) && $node->isPublished() && $node->book['depth'] < BookManager::BOOK_MAX_DEPTH) {
$links['book_add_child'] = array( $book_links['book_add_child'] = array(
'title' => t('Add child page'), 'title' => t('Add child page'),
'url' => Url::fromRoute('node.add', ['node_type' => $child_type], ['query' => ['parent' => $node->id()]]), 'url' => Url::fromRoute('node.add', ['node_type' => $child_type], ['query' => ['parent' => $node->id()]]),
); );
} }
if ($account->hasPermission('access printer-friendly version')) { if ($account->hasPermission('access printer-friendly version')) {
$links['book_printer'] = array( $book_links['book_printer'] = array(
'title' => t('Printer-friendly version'), 'title' => t('Printer-friendly version'),
'url' => Url::fromRoute('book.export', [ 'url' => Url::fromRoute('book.export', [
'type' => 'html', 'type' => 'html',
@ -116,10 +116,10 @@ function book_node_links_alter(array &$node_links, NodeInterface $node, array &$
} }
} }
if (!empty($links)) { if (!empty($book_links)) {
$node_links['book'] = array( $links['book'] = array(
'#theme' => 'links__node__book', '#theme' => 'links__node__book',
'#links' => $links, '#links' => $book_links,
'#attributes' => array('class' => array('links', 'inline')), '#attributes' => array('class' => array('links', 'inline')),
); );
} }

View File

@ -194,15 +194,15 @@ function comment_field_config_delete(FieldConfigInterface $field) {
/** /**
* Implements hook_node_links_alter(). * Implements hook_node_links_alter().
*/ */
function comment_node_links_alter(array &$node_links, NodeInterface $node, array &$context) { function comment_node_links_alter(array &$links, NodeInterface $node, array &$context) {
// Comment links are only added to node entity type for backwards // Comment links are only added to node entity type for backwards
// compatibility. Should you require comment links for other entity types you // compatibility. Should you require comment links for other entity types you
// can do so by implementing a new field formatter. // can do so by implementing a new field formatter.
// @todo Make this configurable from the formatter. See // @todo Make this configurable from the formatter. See
// https://www.drupal.org/node/1901110. // https://www.drupal.org/node/1901110.
$links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context); $comment_links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context);
$node_links += $links; $links += $comment_links;
} }
/** /**

View File

@ -48,20 +48,20 @@ function statistics_node_view(array &$build, EntityInterface $node, EntityViewDi
/** /**
* Implements hook_node_links_alter(). * Implements hook_node_links_alter().
*/ */
function statistics_node_links_alter(array &$node_links, NodeInterface $entity, array &$context) { function statistics_node_links_alter(array &$links, NodeInterface $entity, array &$context) {
if ($context['view_mode'] != 'rss') { if ($context['view_mode'] != 'rss') {
$node_links['#cache']['contexts'][] = 'user.permissions'; $links['#cache']['contexts'][] = 'user.permissions';
if (\Drupal::currentUser()->hasPermission('view post access counter')) { if (\Drupal::currentUser()->hasPermission('view post access counter')) {
$statistics = statistics_get($entity->id()); $statistics = statistics_get($entity->id());
if ($statistics) { if ($statistics) {
$links['statistics_counter']['title'] = \Drupal::translation()->formatPlural($statistics['totalcount'], '1 view', '@count views'); $statistics_links['statistics_counter']['title'] = \Drupal::translation()->formatPlural($statistics['totalcount'], '1 view', '@count views');
$node_links['statistics'] = array( $links['statistics'] = array(
'#theme' => 'links__node__statistics', '#theme' => 'links__node__statistics',
'#links' => $links, '#links' => $statistics_links,
'#attributes' => array('class' => array('links', 'inline')), '#attributes' => array('class' => array('links', 'inline')),
); );
} }
$node_links['#cache']['max-age'] = \Drupal::config('statistics.settings')->get('display_max_age'); $links['#cache']['max-age'] = \Drupal::config('statistics.settings')->get('display_max_age');
} }
} }
} }