By effulgentsia on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
In Drupal 7, if you wanted to access the current Drupal path, you could do so by either calling current_path() or accessing $_GET['q']. In Drupal 8, the Drupal path is no longer stored in $_GET['q'], so modules and themes must be changed to call current_path() instead.
Drupal 7:
function contact_mail($key, &$message, $params) {
...
$variables = array(
...
'!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)),
...
}
Drupal 8:
function contact_mail($key, &$message, $params) {
...
$variables = array(
...
'!form-url' => url(current_path(), array('absolute' => TRUE, 'language' => $language)),
...
}
In Drupal 7, some modules would occasionally set $_GET['q']. For example:
function comment_permalink($cid) {
...
$_GET['q'] = 'node/' . $node->nid;
...
}
In Drupal 8, this is not allowed (or rather, doing so, does not affect the current Drupal path). Instead, a subrequest can be invoked as documented in the Symfony request handling change record.
Impacts:
Module developers
Themers
Comments
USE \Drupal::url('<current>')
Druapl - 8.0.0-beta15
Look like current_path() function no longer exists. Alternatively we can use
Grt!! Thanks
Grt!! Thanks
Looks like this has changed
Looks like this has changed again from the Drupal 8 beta. This currently works in 8.1.3:
$current_path = \Drupal::service('path.current')->getPath()