Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By benjifisher on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.3.x
Introduced in version:
9.3.0-alpha1
Issue links:
Description:
Summary
The node revision routes, like /node/123/revisions/456/view
, the code \Drupal::routeMatch()->getParameter('node')
and \Drupal::routeMatch()->getParameter('node_revision')
now return a Node object. Before Drupal 9.3.0, this code returned an integer when used on the following routes:
- entity.node.revision:
/node/{node}/revisions/{node_revision}/view
- node.revision_revert_confirm:
/node/{node}/revisions/{node_revision}/revert
- node.revision_revert_translation_confirm:
/node/{node}/revisions/{node_revision}/revert/{langcode}
- node.revision_delete_confirm:
/node/{node}/revisions/{node_revision}/delete
Now, that code always returns a Node object.
Before
Use
$nid = \Drupal::routeMatch()->getParameter('node');
$node = \Drupal\node\Entity\Node::load($nid);
$vid = \Drupal::routeMatch()->getParameter('node_revision');
$node_revision = node_revision_load($vid);
to get the (integer) node ID $nid
and the Node object $node
Or to get the (integer) revision ID $vid
and the Node revision object $node_revision
After
Use
$node = \Drupal::routeMatch()->getParameter('node');
$nid = $node->id();
$node_revision = \Drupal::routeMatch()->getParameter('node_revision');
$vid = $node_revision->getRevisionId();
To get just the node ID or revision ID, use
$nid = \Drupal::routeMatch()->getRawParameter('node');
$vid = \Drupal::routeMatch()->getRawParameter('node_revision');
Impacts:
Module developers
Themers