diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 94d0e57..7941fa1 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -1025,6 +1025,9 @@ function menu_get_object($type = 'node', $position = 1, $path = NULL) { if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type . '_load') { return $router_item['map'][$position]; } + // For new routing items the above code will not trigger + $request = Drupal::service('request'); + return $request->attributes->get($type); } /** diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 7712bf1..7b624ed 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -276,7 +276,7 @@ public function getIterator() { public function access($operation = 'view', AccountInterface $account = NULL) { return \Drupal::entityManager() ->getAccessController($this->entityType) - ->access($this, $operation, Language::LANGCODE_DEFAULT, $account); + ->access($this, $operation, $this->language()->id, $account); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 3d0c5c6..0e722e9 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -424,7 +424,7 @@ public function isEmpty() { public function access($operation = 'view', AccountInterface $account = NULL) { return \Drupal::entityManager() ->getAccessController($this->entityType) - ->access($this, $operation, $this->activeLangcode, $account); + ->access($this, $operation, $this->language()->id, $account); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index 8d7a472..a91a4df 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -56,7 +56,7 @@ function testCommentInterface() { $this->assertTrue($this->commentExists($comment), 'Comment found.'); // Check comment display. - $this->drupalGet('node/' . $this->node->nid . '/' . $comment->id()); + $this->drupalGet('node/' . $this->node->nid); $this->assertText($subject_text, 'Individual comment subject found.'); $this->assertText($comment_text, 'Individual comment body found.'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php index 7910196..4e951d2 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php @@ -68,7 +68,7 @@ function testThreadedCommentView() { $this->assertTrue($this->commentExists($comment), 'Comment found.'); // Check comment display. - $this->drupalGet('node/' . $this->node->nid . '/' . $comment->id()); + $this->drupalGet('node/' . $this->node->nid); $this->assertText($comment_subject, 'Individual comment subject found.'); $this->assertText($comment_text, 'Individual comment body found.'); diff --git a/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php b/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php index 5e1dbf1..092ca21 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php +++ b/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php @@ -71,6 +71,14 @@ public function build(array $attributes) { break; } } + // @todo Temporary added code to support the new routing system, this + // should be consolidated with the above. + elseif (isset($attributes['node'])) { + $node = $attributes['node']; + if (_forum_node_check_node_type($node)) { + $breadcrumb = $this->forumPostBreadcrumb($node); + } + } if (!empty($breadcrumb)) { return $breadcrumb; diff --git a/core/modules/node/lib/Drupal/node/Controller/NodeViewController.php b/core/modules/node/lib/Drupal/node/Controller/NodeViewController.php new file mode 100644 index 0000000..0142e2c --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Controller/NodeViewController.php @@ -0,0 +1,57 @@ +label()); + $uri = $node->uri(); + // Set the node path as the canonical URL to prevent duplicate content. + drupal_add_html_head_link(array( + 'rel' => 'canonical', + 'href' => url($uri['path'], $uri['options']) + ), TRUE); + // Set the non-aliased path as a default shortlink. + drupal_add_html_head_link(array( + 'rel' => 'shortlink', + 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE))) + ), TRUE); + + return node_show($node); + } + +} diff --git a/core/modules/node/node.module b/core/modules/node/node.module index b9c5bd3..94f519f 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -686,14 +686,14 @@ function node_show(EntityInterface $node, $message = FALSE) { /** * Checks whether the current page is the full page view of the passed-in node. * - * @param \Drupal\Core\Entity\EntityInterface $node + * @param \Drupal\node\NodeInterface $node * A node entity. * * @return * The ID of the node if this is a full page view, otherwise FALSE. */ -function node_is_page(EntityInterface $node) { - $page_node = menu_get_object(); +function node_is_page(NodeInterface $node) { + $page_node = \Drupal::service('request')->attributes->get('node'); return (!empty($page_node) ? $page_node->id() == $node->id() : FALSE); } @@ -1321,16 +1321,10 @@ function node_menu() { 'file' => 'node.pages.inc', ); $items['node/%node'] = array( - 'title callback' => 'node_page_title', - 'title arguments' => array(1), - // The page callback also invokes drupal_set_title() in case - // the menu router's title is overridden by a menu link. - 'page callback' => 'node_page_view', - 'page arguments' => array(1), - 'access callback' => 'node_access', - 'access arguments' => array('view', 1), + 'route_name' => 'node_view', ); $items['node/%node/view'] = array( + 'route_name' => 'node_view_default_task', 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, ); @@ -1404,21 +1398,6 @@ function node_menu_local_tasks(&$data, $router_item, $root_path) { } /** - * Title callback: Displays the node's title. - * - * @param \Drupal\Core\Entity\EntityInterface $node - * The node entity. - * - * @return - * An unsanitized string that is the title of the node. - * - * @see node_menu() - */ -function node_page_title(EntityInterface $node) { - return $node->label(); -} - -/** * Finds the last time a node was changed. * * @param $nid @@ -1804,37 +1783,6 @@ function node_view_multiple($nodes, $view_mode = 'teaser', $langcode = NULL) { } /** - * Page callback: Displays a single node. - * - * @param \Drupal\Core\Entity\EntityInterface $node - * The node entity. - * - * @return - * A page array suitable for use by drupal_render(). - * - * @see node_menu() - */ -function node_page_view(EntityInterface $node) { - // If there is a menu link to this node, the link becomes the last part - // of the active trail, and the link name becomes the page title. - // Thus, we must explicitly set the page title to be the node title. - drupal_set_title($node->label()); - - foreach ($node->uriRelationships() as $rel) { - $uri = $node->uri($rel); - // Set the node path as the canonical URL to prevent duplicate content. - drupal_add_html_head_link(array('rel' => $rel, 'href' => url($uri['path'], $uri['options'])), TRUE); - - if ($rel == 'canonical') { - // Set the non-aliased canonical path as a default shortlink. - drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE); - } - } - - return node_show($node); -} - -/** * Implements hook_update_index(). */ function node_update_index() { diff --git a/core/modules/node/node.routing.yml b/core/modules/node/node.routing.yml index 9204a2b..9fb284d 100644 --- a/core/modules/node/node.routing.yml +++ b/core/modules/node/node.routing.yml @@ -47,3 +47,19 @@ node_type_delete_confirm: _entity_form: 'node_type.delete' requirements: _entity_access: 'node_type.delete' + +node_view: + pattern: '/node/{node}' + defaults: + _content: '\Drupal\node\Controller\NodeViewController::render' + requirements: + _entity_access: 'node.view' + node: \d+ + +node_view_default_task: + pattern: '/node/{node}/view' + defaults: + _content: '\Drupal\node\Controller\NodeViewController::render' + requirements: + _entity_access: 'node.view' + node: \d+