Commit cd8986c2 authored by alexpott's avatar alexpott

Issue #2278567 by kgoel, azinck, dawehner | Crell: Standardize node route names by relationship.

parent 2d03e83a
......@@ -103,9 +103,9 @@ public function label();
* example:
* @code
* links = {
* "canonical" = "node.view",
* "edit-form" = "node.page_edit",
* "version-history" = "node.revision_overview"
* "canonical" = "entity.node.canonical",
* "edit-form" = "entity.node.edit_form",
* "version-history" = "entity.node.version_history"
* }
* @endcode
* or specified in a callback function set like:
......
......@@ -59,7 +59,7 @@ public function executeSubmitHandlers(&$form, FormStateInterface &$form_state);
* @endcode
* And here is an example of how to redirect to 'node/123?foo=bar#baz':
* @code
* $form_state->setRedirect('node.view',
* $form_state->setRedirect('entity.node.canonical',
* array('node' => 123),
* array(
* 'query' => array(
......
......@@ -29,7 +29,7 @@ function theme_book_admin_table($variables) {
$access = \Drupal::currentUser()->hasPermission('administer nodes');
foreach (Element::children($form) as $key) {
$nid = $form[$key]['nid']['#value'];
$href = \Drupal::url('node.view', array('node' => $nid));
$href = \Drupal::url('entity.node.canonical', array('node' => $nid));
// Add special classes to be used with tabledrag.js.
$form[$key]['pid']['#attributes']['class'] = array('book-pid');
......@@ -50,13 +50,13 @@ function theme_book_admin_table($variables) {
if ($access) {
$links['edit'] = array(
'title' => t('Edit'),
'route_name' => 'node.page_edit',
'route_name' => 'entity.node.edit_form',
'route_parameters' => array('node' => $nid),
'query' => $destination,
);
$links['delete'] = array(
'title' => t('Delete'),
'route_name' => 'node.delete_confirm',
'route_name' => 'entity.node.delete_form',
'route_parameters' => array('node' => $nid),
'query' => $destination,
);
......
......@@ -10,6 +10,6 @@ book.settings:
book.outline:
route_name: book.outline
base_route: node.view
base_route: entity.node.canonical
title: Outline
weight: 2
......@@ -406,7 +406,7 @@ function template_preprocess_book_navigation(&$variables) {
// Provide extra variables for themers. Not needed by default.
$variables['book_id'] = $book_link['bid'];
$variables['book_title'] = String::checkPlain($book_link['link_title']);
$variables['book_url'] = \Drupal::url('node.view', array('node' => $book_link['bid']));
$variables['book_url'] = \Drupal::url('entity.node.canonical', array('node' => $book_link['bid']));
$variables['current_depth'] = $book_link['depth'];
$variables['tree'] = '';
......@@ -419,7 +419,7 @@ function template_preprocess_book_navigation(&$variables) {
$build = array();
if ($prev = $book_outline->prevLink($book_link)) {
$prev_href = \Drupal::url('node.view', array('node' => $prev['nid']));
$prev_href = \Drupal::url('entity.node.canonical', array('node' => $prev['nid']));
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'prev',
'href' => $prev_href,
......@@ -431,7 +431,7 @@ function template_preprocess_book_navigation(&$variables) {
/** @var \Drupal\book\BookManagerInterface $book_manager */
$book_manager = \Drupal::service('book.manager');
if ($book_link['pid'] && $parent = $book_manager->loadBookLink($book_link['pid'])) {
$parent_href = \Drupal::url('node.view', array('node' => $book_link['pid']));
$parent_href = \Drupal::url('entity.node.canonical', array('node' => $book_link['pid']));
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'up',
'href' => $parent_href,
......@@ -441,7 +441,7 @@ function template_preprocess_book_navigation(&$variables) {
}
if ($next = $book_outline->nextLink($book_link)) {
$next_href = \Drupal::url('node.view', array('node' => $next['nid']));
$next_href = \Drupal::url('entity.node.canonical', array('node' => $next['nid']));
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'next',
'href' => $next_href,
......
......@@ -87,7 +87,7 @@ public function build(RouteMatchInterface $route_match) {
while (!empty($book['p' . ($depth + 1)])) {
if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) {
if ($parent_book->access('view', $this->account)) {
$links[] = $this->l($parent_book->label(), 'node.view', array('node' => $parent_book->id()));
$links[] = $this->l($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id()));
}
}
$depth++;
......
......@@ -103,7 +103,7 @@ protected function actions(array $form, FormStateInterface $form_state) {
*/
public function submit(array $form, FormStateInterface $form_state) {
$form_state->setRedirect(
'node.view',
'entity.node.canonical',
array('node' => $this->entity->id())
);
$book_link = $form_state->getValue('book');
......
......@@ -53,7 +53,7 @@ public function getBookAdminRoutes() {
*/
public function testBookNodeLocalTasks($route) {
$this->assertLocalTasks($route, array(
0 => array('book.outline', 'node.view', 'node.page_edit', 'node.delete_confirm', 'node.revision_overview',),
0 => array('book.outline', 'entity.node.canonical', 'entity.node.edit_form', 'entity.node.delete_form', 'entity.node.version_history',),
));
}
......@@ -62,7 +62,7 @@ public function testBookNodeLocalTasks($route) {
*/
public function getBookNodeRoutes() {
return array(
array('node.view'),
array('entity.node.canonical'),
array('book.outline'),
);
}
......
......@@ -27,7 +27,7 @@ public function setUp() {
$entity_type->expects($this->any())
->method('getLinkTemplate')
->will($this->returnValueMap(array(
array('canonical', 'node.view'),
array('canonical', 'entity.node.canonical'),
array('drupal:content-translation-overview', 'content_translation.translation_overview_node'),
)));
$content_translation_manager = $this->getMock('Drupal\content_translation\ContentTranslationManagerInterface');
......@@ -53,19 +53,19 @@ public function testBlockAdminDisplay($route, $expected) {
*/
public function providerTestBlockAdminDisplay() {
return array(
array('node.view', array(array(
array('entity.node.canonical', array(array(
'content_translation.local_tasks:content_translation.translation_overview_node',
'node.view',
'node.page_edit',
'node.delete_confirm',
'node.revision_overview',
'entity.node.canonical',
'entity.node.edit_form',
'entity.node.delete_form',
'entity.node.version_history',
))),
array('content_translation.translation_overview_node', array(array(
'content_translation.local_tasks:content_translation.translation_overview_node',
'node.view',
'node.page_edit',
'node.delete_confirm',
'node.revision_overview',
'entity.node.canonical',
'entity.node.edit_form',
'entity.node.delete_form',
'entity.node.version_history',
))),
);
}
......
......@@ -74,9 +74,9 @@ function testDifferentPermissions() {
$response = $this->renderContextualLinks($ids, 'node');
$this->assertResponse(200);
$json = Json::decode($response);
$this->assertIdentical($json[$ids[0]], '<ul class="contextual-links"><li class="nodepage-edit"><a href="' . base_path() . 'node/1/edit">Edit</a></li></ul>');
$this->assertIdentical($json[$ids[0]], '<ul class="contextual-links"><li class="entitynodeedit-form"><a href="' . base_path() . 'node/1/edit">Edit</a></li></ul>');
$this->assertIdentical($json[$ids[1]], '');
$this->assertIdentical($json[$ids[2]], '<ul class="contextual-links"><li class="nodepage-edit"><a href="' . base_path() . 'node/3/edit">Edit</a></li></ul>');
$this->assertIdentical($json[$ids[2]], '<ul class="contextual-links"><li class="entitynodeedit-form"><a href="' . base_path() . 'node/3/edit">Edit</a></li></ul>');
$this->assertIdentical($json[$ids[3]], '');
// Authenticated user: can access contextual links, cannot edit articles.
......
......@@ -18,7 +18,7 @@ class ForumNodeBreadcrumbBuilder extends ForumBreadcrumbBuilderBase {
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
return $route_match->getRouteName() == 'node.view'
return $route_match->getRouteName() == 'entity.node.canonical'
&& $route_match->getParameter('node')
&& $this->forumManager->checkNodeType($route_match->getParameter('node'));
}
......
......@@ -84,20 +84,20 @@ public function providerTestApplies() {
),
array(
FALSE,
'NOT.node.view',
'NOT.entity.node.canonical',
),
array(
FALSE,
'node.view',
'entity.node.canonical',
),
array(
FALSE,
'node.view',
'entity.node.canonical',
array(array('node', NULL)),
),
array(
TRUE,
'node.view',
'entity.node.canonical',
array(array('node', $mock_node)),
),
);
......
......@@ -48,8 +48,8 @@ public function getRouteParameters();
*
* @param array $route_parameters
* The route parameters, usually derived from the path entered by the
* administrator. For example, for a link to a node with route 'node.view'
* the route needs the node ID as a parameter:
* administrator. For example, for a link to a node with route
* 'entity.node.canonical' the route needs the node ID as a parameter:
* @code
* array('node' => 2)
* @endcode
......
......@@ -209,7 +209,7 @@ function menu_ui_node_save(EntityInterface $node) {
$entity = entity_create('menu_link_content', array(
'title' => trim($definition['title']),
'description' => trim($definition['description']),
'route_name' => 'node.view',
'route_name' => 'entity.node.canonical',
'route_parameters' => array('node' => $node->id()),
'menu_name' => $definition['menu_name'],
'parent' => $definition['parent'],
......@@ -233,7 +233,7 @@ function menu_ui_node_predelete(EntityInterface $node) {
// Delete all MenuLinkContent links that point to this node.
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$result = $menu_link_manager->loadLinksByRoute('node.view', array('node' => $node->id()));
$result = $menu_link_manager->loadLinksByRoute('entity.node.canonical', array('node' => $node->id()));
if (!empty($result)) {
foreach ($result as $id => $instance) {
......@@ -259,7 +259,7 @@ function menu_ui_node_prepare_form(NodeInterface $node, $operation, FormStateInt
$type_menus = $node_type_config->get('available_menus');
if (in_array($menu_name, $type_menus)) {
$query = \Drupal::entityQuery('menu_link_content')
->condition('route_name', 'node.view')
->condition('route_name', 'entity.node.canonical')
->condition('route_parameters', serialize(array('node' => $node->id())))
->condition('menu_name', $menu_name)
->sort('id', 'ASC')
......@@ -271,7 +271,7 @@ function menu_ui_node_prepare_form(NodeInterface $node, $operation, FormStateInt
// Check all allowed menus if a link does not exist in the default menu.
if (!$id && !empty($type_menus)) {
$query = \Drupal::entityQuery('menu_link_content')
->condition('route_name', 'node.view')
->condition('route_name', 'entity.node.canonical')
->condition('route_parameters', serialize(array('node' => $node->id())))
->condition('menu_name', array_values($type_menus), 'IN')
->sort('id', 'ASC')
......
......@@ -126,7 +126,7 @@ function testMenuNodeFormWidget() {
// Add a menu link to the Administration menu.
$item = entity_create('menu_link_content', array(
'route_name' => 'node.view',
'route_name' => 'entity.node.canonical',
'route_parameters' => array('node' => $node->id()),
'title' => $this->randomMachineName(16),
'menu_name' => 'admin',
......@@ -150,7 +150,7 @@ function testMenuNodeFormWidget() {
$child_node = $this->drupalCreateNode(array('type' => 'article'));
// Assign a menu link to the second node, being a child of the first one.
$child_item = entity_create('menu_link_content', array(
'route_name' => 'node.view',
'route_name' => 'entity.node.canonical',
'route_parameters' => array('node' => $child_node->id()),
'title' => $this->randomMachineName(16),
'parent' => $item->getPluginId(),
......
......@@ -318,7 +318,7 @@ function doMenuTests() {
$this->assertMenuLink($item6->getPluginId(), array(
'children' => array(),
'parents' => array($item6->getPluginId(), $item4->getPluginId()),
'route_name' => 'node.view',
'route_name' => 'entity.node.canonical',
'route_parameters' => array('node' => $node5->id()),
'url' => '',
// See above.
......
node.page_edit:
route_name: node.page_edit
entity.node.edit_form:
route_name: entity.node.edit_form
group: node
title: Edit
node.delete_confirm:
route_name: node.delete_confirm
entity.node.delete_form:
route_name: entity.node.delete_form
group: node
title: Delete
weight: 10
node.view:
route_name: node.view
base_route: node.view
entity.node.canonical:
route_name: entity.node.canonical
base_route: entity.node.canonical
title: 'View'
node.page_edit:
route_name: node.page_edit
base_route: node.view
entity.node.edit_form:
route_name: entity.node.edit_form
base_route: entity.node.canonical
title: Edit
node.delete_confirm:
route_name: node.delete_confirm
base_route: node.view
entity.node.delete_form:
route_name: entity.node.delete_form
base_route: entity.node.canonical
title: Delete
weight: 10
node.revision_overview:
route_name: node.revision_overview
base_route: node.view
entity.node.version_history:
route_name: entity.node.version_history
base_route: entity.node.canonical
title: 'Revisions'
weight: 20
node.type_edit:
entity.node_type.edit_form:
title: 'Edit'
route_name: node.type_edit
base_route: node.type_edit
route_name: entity.node_type.edit_form
base_route: entity.node_type.edit_form
node.overview_types:
title: List
route_name: node.overview_types
......
......@@ -138,10 +138,10 @@ function node_help($route_name, RouteMatchInterface $route_match) {
return '<p>' . t('Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. <em>Teaser</em> is a short format that is typically used in lists of multiple content items. <em>Full content</em> is typically used when the content is displayed on its own page.') . '</p>' .
'<p>' . 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' => $type->label())) . '</p>';
case 'node.revision_overview':
case 'entity.node.version_history':
return '<p>' . t('Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.') . '</p>';
case 'node.page_edit':
case 'entity.node.edit_form':
$node = $route_match->getParameter('node');
$type = $node->getType();
return (!empty($type->help) ? Xss::filterAdmin($type->help) : '');
......@@ -545,7 +545,7 @@ function node_revision_delete($revision_id) {
*/
function node_is_page(NodeInterface $node) {
$route_match = \Drupal::routeMatch();
if ($route_match->getRouteName() == 'node.view') {
if ($route_match->getRouteName() == 'entity.node.canonical') {
$page_node = $route_match->getParameter('node');
}
return (!empty($page_node) ? $page_node->id() == $node->id() : FALSE);
......
......@@ -6,7 +6,7 @@ node.multiple_delete_confirm:
requirements:
_permission: 'administer nodes'
node.page_edit:
entity.node.edit_form:
path: '/node/{node}/edit'
defaults:
_entity_form: 'node.edit'
......@@ -37,7 +37,7 @@ node.add:
options:
_node_operation_route: TRUE
node.view:
entity.node.canonical:
path: '/node/{node}'
defaults:
_content: '\Drupal\node\Controller\NodeViewController::view'
......@@ -45,7 +45,7 @@ node.view:
requirements:
_entity_access: 'node.view'
node.delete_confirm:
entity.node.delete_form:
path: '/node/{node}/delete'
defaults:
_entity_form: 'node.delete'
......@@ -55,7 +55,7 @@ node.delete_confirm:
options:
_node_operation_route: TRUE
node.revision_overview:
entity.node.version_history:
path: '/node/{node}/revisions'
defaults:
_title: 'Revisions'
......@@ -110,14 +110,14 @@ node.type_add:
requirements:
_permission: 'administer content types'
node.type_edit:
entity.node_type.edit_form:
path: '/admin/structure/types/manage/{node_type}'
defaults:
_entity_form: 'node_type.edit'
requirements:
_permission: 'administer content types'
node.type_delete_confirm:
entity.node_type.delete_form:
path: '/admin/structure/types/manage/{node_type}/delete'
defaults:
_entity_form: 'node_type.delete'
......
......@@ -173,7 +173,7 @@ public function revisionOverview(NodeInterface $node) {
'#theme' => 'username',
'#account' => $revision_author,
);
$row[] = array('data' => $this->t('!date by !username', array('!date' => $this->l($this->dateFormatter->format($revision->revision_timestamp->value, 'short'), 'node.view', array('node' => $node->id())), '!username' => drupal_render($username)))
$row[] = array('data' => $this->t('!date by !username', array('!date' => $this->l($this->dateFormatter->format($revision->revision_timestamp->value, 'short'), 'entity.node.canonical', array('node' => $node->id())), '!username' => drupal_render($username)))
. (($revision->revision_log->value != '') ? '<p class="revision-log">' . Xss::filter($revision->revision_log->value) . '</p>' : ''),
'class' => array('revision-current'));
$row[] = array('data' => String::placeholder($this->t('current revision')), 'class' => array('revision-current'));
......
......@@ -51,11 +51,11 @@
* bundle_entity_type = "node_type",
* permission_granularity = "bundle",
* links = {
* "canonical" = "node.view",
* "delete-form" = "node.delete_confirm",
* "edit-form" = "node.page_edit",
* "version-history" = "node.revision_overview",
* "admin-form" = "node.type_edit"
* "canonical" = "entity.node.canonical",
* "delete-form" = "entity.node.delete_form",
* "edit-form" = "entity.node.edit_form",
* "version-history" = "entity.node.version_history",
* "admin-form" = "entity.node_type.edit_form"
* }
* )
*/
......
......@@ -35,9 +35,8 @@
* "label" = "name"
* },
* links = {
* "add-form" = "node.add",
* "edit-form" = "node.type_edit",
* "delete-form" = "node.type_delete_confirm"
* "edit-form" = "entity.node_type.edit_form",
* "delete-form" = "entity.node_type.delete_form"
* }
* )
*/
......
......@@ -94,7 +94,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('node.revision_overview', array('node' => $this->revision->id()));
return new Url('entity.node.version_history', array('node' => $this->revision->id()));
}
/**
......@@ -124,12 +124,12 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$node_type = $this->nodeTypeStorage->load($this->revision->bundle())->label();
drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($this->revision->getRevisionCreationTime()), '@type' => $node_type, '%title' => $this->revision->label())));
$form_state->setRedirect(
'node.view',
'entity.node.canonical',
array('node' => $this->revision->id())
);
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {node_field_revision} WHERE nid = :nid', array(':nid' => $this->revision->id()))->fetchField() > 1) {
$form_state->setRedirect(
'node.revision_overview',
'entity.node.version_history',
array('node' => $this->revision->id())
);
}
......
......@@ -70,7 +70,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('node.revision_overview', array('node' => $this->revision->id()));
return new Url('entity.node.version_history', array('node' => $this->revision->id()));
}
/**
......@@ -116,7 +116,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->logger('content')->notice('@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()));
drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => format_date($original_revision_timestamp))));
$form_state->setRedirect(
'node.revision_overview',
'entity.node.version_history',
array('node' => $this->revision->id())
);
}
......
......@@ -450,7 +450,7 @@ public function save(array $form, FormStateInterface $form_state) {
$form_state['nid'] = $node->id();
if ($node->access('view')) {
$form_state->setRedirect(
'node.view',
'entity.node.canonical',
array('node' => $node->id())
);
}
......
......@@ -319,7 +319,7 @@
* entity interface you have defined as its parameter, and returns routing
* information for the entity page; see node_uri() for an example. You will
* also need to add a corresponding route to your module's routing.yml file;
* see the node.view route in node.routing.yml for an example, and see
* see the entity.node.canonical route in node.routing.yml for an example, and see
* @ref sec_routes below for some notes.
* - Define routing and links for the various URLs associated with the entity.
* These go into the 'links' annotation, with the link type as the key, and
......
......@@ -411,9 +411,10 @@ function hook_page_build(&$page) {
* patten is the route name followed by a dot and a unique suffix. For
* example, an additional logout link might have a machine name of
* user.logout.navigation, and default links provided to edit the article and
* page content types could use machine names node.type_edit.article and
* node.type_edit.page. Since the machine name may be arbitrary, you should
* never write code that assumes it is identical to the route name.
* page content types could use machine names
* entity.node_type.edit_form.article and entity.node_type.edit_form.page.
* Since the machine name may be arbitrary, you should never write code that
* assumes it is identical to the route name.
*
* The value corresponding to each machine name key is an associative array
* that may contain the following key-value pairs:
......
......@@ -51,7 +51,7 @@ protected function setUp() {
$this->installSchema('node', array('node_access'));
$this->installConfig(array('node', 'language'));
// The node.view route must exist when nodes are rendered.
// The entity.node.canonical route must exist when nodes are rendered.
$this->container->get('router.builder')->rebuild();
$this->langcodes = array(\Drupal::languageManager()->getDefaultLanguage()->id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment