diff --git a/core/includes/common.inc b/core/includes/common.inc
index 2048ab4..b57f459 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -10,6 +10,7 @@
 use Drupal\Component\Utility\Xss;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Language\Language;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\Yaml\Parser;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpFoundation\Request;
@@ -286,6 +287,23 @@ function drupal_get_profile() {
   return $profile;
 }
 
+/**
+ * Provides a helper for deriving the current route name from a request.
+ *
+ * @param \Symfony\Component\HttpFoundation\Request $request
+ *   (optional) The request to check. If not provided, will use the current
+ *   request.
+ *
+ * @return string|null
+ *   Either the machine name for the route used for this request, or NULL if
+ *   none is found.
+ */
+function drupal_get_route_name(Request $request = NULL) {
+  if (!$request) {
+    $request = \Drupal::request();
+  }
+  return $request->attributes->get(RouteObjectInterface::ROUTE_NAME);
+}
 
 /**
  * Sets the breadcrumb trail for the current page.
diff --git a/core/includes/menu.inc b/core/includes/menu.inc
index c8fddcd..058c386 100644
--- a/core/includes/menu.inc
+++ b/core/includes/menu.inc
@@ -1299,7 +1299,7 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail =
   // Load the router item corresponding to the current page.
   $request = \Drupal::request();
   $system_path = NULL;
-  if ($route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME)) {
+  if ($route_name = drupal_get_route_name($request)) {
     // @todo https://drupal.org/node/2068471 is adding support so we can tell
     // if this is called on a 404/403 page.
     $system_path = $request->attributes->get('_system_path');
@@ -1974,7 +1974,7 @@ function menu_local_tasks($level = 0) {
     $data['tabs'] = array();
     $data['actions'] = array();
 
-    $route_name = \Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
+    $route_name = drupal_get_route_name();
     if (!empty($route_name)) {
       $manager = \Drupal::service('plugin.manager.menu.local_task');
       $local_tasks = $manager->getTasksBuild($route_name);
@@ -2325,7 +2325,7 @@ function menu_secondary_local_tasks() {
  */
 function menu_get_local_actions() {
   $links = menu_local_tasks();
-  $route_name = Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
+  $route_name = drupal_get_route_name();
   $manager = \Drupal::service('plugin.manager.menu.local_action');
   $links['actions'] += $manager->getActionsForRoute($route_name);
   return $links['actions'];
