From ae52bee8757463e7ec491ea6fd3498887aedf6ef Sun, 20 Nov 2011 16:59:46 +0100
From: Bram Goffings <bramgoffings@gmail.com>
Date: Sun, 20 Nov 2011 16:59:34 +0100
Subject: [PATCH] Argument handler 

diff --git a/core/includes/Drupal/Context/Handler/HandlerArg.php b/core/includes/Drupal/Context/Handler/HandlerArg.php
new file mode 100644
index 0000000..16dfd62
--- /dev/null
+++ b/core/includes/Drupal/Context/Handler/HandlerArg.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Drupal\Context\Handler;
+
+use \Drupal\Context\ContextInterface;
+
+/**
+ * Arg Context Handler implementation.
+ *
+ * When viewing a page at the path "admin/structure/types", for example,
+ * drupal_get_contex()->getValue('arg:0') returns "admin",
+ * drupal_get_contex()->getValue('arg:1') returns "structure", and
+ * drupal_get_contex()->getValue('arg:2') returns "types".
+ */
+class HandlerArg extends HandlerAbstract {
+
+  /**
+   * Implements HandlerInterface::getValue().
+   */
+  public function getValue(array $args = array(), ContextInterface $context = null) {
+
+    // Get current system path.
+    $path = $context->getValue('path:system');
+    // Fetch individual arguments
+    $arguments = explode('/', $path);
+
+    if (!isset($args[0])) {
+      return $arguments;
+    }
+
+    $index = $args[0];
+    if (isset($arguments[$index])) {
+      return $arguments[$index];
+    }
+  }
+}
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index fb8fe5f..831c545 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -2448,6 +2448,9 @@
     $context->setHandler('path:system', function() {
       return new \Drupal\Context\Handler\HandlerPathSystem();
     });
+    $context->setHandler('arg', function() {
+      return new \Drupal\Context\Handler\HandlerArg();
+    });
   }
 
   bootstrap_invoke_all('context_init', $context);
@@ -2778,55 +2781,6 @@
       'javascript' => ''
     )
   );
-}
-
-/**
- * Return a component of the current Drupal path.
- *
- * When viewing a page at the path "admin/structure/types", for example, arg(0)
- * returns "admin", arg(1) returns "structure", and arg(2) returns "types".
- *
- * Avoid use of this function where possible, as resulting code is hard to read.
- * In menu callback functions, attempt to use named arguments. See the explanation
- * in menu.inc for how to construct callbacks that take arguments. When attempting
- * to use this function to load an element from the current path, e.g. loading the
- * node on a node page, please use menu_get_object() instead.
- *
- * @param $index
- *   The index of the component, where each component is separated by a '/'
- *   (forward-slash), and where the first component has an index of 0 (zero).
- * @param $path
- *   A path to break into components. Defaults to the path of the current page.
- *
- * @return
- *   The component specified by $index, or NULL if the specified component was
- *   not found. If called without arguments, it returns an array containing all
- *   the components of the current path.
- */
-function arg($index = NULL, $path = NULL) {
-  // Even though $arguments doesn't need to be resettable for any functional
-  // reasons (the result of explode() does not depend on any run-time
-  // information), it should be resettable anyway in case a module needs to
-  // free up the memory used by it.
-  // Use the advanced drupal_static() pattern, since this is called very often.
-  static $drupal_static_fast;
-  if (!isset($drupal_static_fast)) {
-    $drupal_static_fast['arguments'] = &drupal_static(__FUNCTION__);
-  }
-  $arguments = &$drupal_static_fast['arguments'];
-
-  if (!isset($path)) {
-    $path = drupal_get_context()->getValue('path:system');
-  }
-  if (!isset($arguments[$path])) {
-    $arguments[$path] = explode('/', $path);
-  }
-  if (!isset($index)) {
-    return $arguments[$path];
-  }
-  if (isset($arguments[$path][$index])) {
-    return $arguments[$path][$index];
-  }
 }
 
 /**
diff --git a/core/includes/menu.inc b/core/includes/menu.inc
index 29a0a40..9a52b66 100644
--- a/core/includes/menu.inc
+++ b/core/includes/menu.inc
@@ -369,7 +369,7 @@
  * @param $map
  *   A path argument array, used to replace integer values in $data; an integer
  *   value N in $data will be replaced by value $map[N]. Typically, the $map
- *   array is generated from a call to the arg() function.
+ *   array is generated from a call to the context argument handler
  *
  * @return
  *   The unserialized $data array, with path arguments replaced.
@@ -424,6 +424,10 @@
  */
 function menu_get_item($path = NULL, $router_item = NULL) {
   $router_items = &drupal_static(__FUNCTION__);
+
+  // Get the current context.
+  $context = drupal_get_context();
+
   if (!isset($path)) {
     $path = drupal_get_context()->getValue('path:system');
   }
@@ -436,7 +440,19 @@
     if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
       menu_rebuild();
     }
-    $original_map = arg(NULL, $path);
+
+    if (isset($path)) {
+      $c2 = $context->addLayer();
+      $c2->setValue('path:system', $path);
+      $t2 = $c2->lock();
+
+      // Get arguments from mocked system path.
+      $original_map = $c2->getValue('arg');
+    }
+    else {
+      // Get arguments from current system path.
+      $original_map = $context->getValue('arg');
+    }
 
     // Since there is no limit to the length of $path, use a hash to keep it
     // short yet unique.
@@ -1688,7 +1704,7 @@
     return '';
   }
 
-  $arg = drupal_help_arg(arg(NULL));
+  $arg = drupal_help_arg(drupal_get_context()->getValue('arg'));
 
   foreach (module_implements('help') as $module) {
     $function = $module . '_help';
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 6e726af..5a45cb6 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2309,7 +2309,7 @@
   }
 
   // Populate the body classes.
-  if ($suggestions = theme_get_suggestions(arg(), 'page', '-')) {
+  if ($suggestions = theme_get_suggestions(drupal_get_context()->getValue('arg'), 'page', '-')) {
     foreach ($suggestions as $suggestion) {
       if ($suggestion != 'page-front') {
         // Add current suggestion to page classes to make it possible to theme
@@ -2357,7 +2357,7 @@
   $variables['head_title'] = implode(' | ', $head_title);
 
   // Populate the page template suggestions.
-  if ($suggestions = theme_get_suggestions(arg(), 'html')) {
+  if ($suggestions = theme_get_suggestions(drupal_get_context()->getValue('arg'), 'html')) {
     $variables['theme_hook_suggestions'] = $suggestions;
   }
 }
@@ -2369,8 +2369,8 @@
  * inside "modules/system/page.tpl.php". Look in there for the full list of
  * variables.
  *
- * Uses the arg() function to generate a series of page template suggestions
- * based on the current path.
+ * Uses the context argument handler to generate a series of page template
+ * suggestions based on the current path.
  *
  * Any changes to variables in this preprocessor should also be changed inside
  * template_preprocess_maintenance_page() to keep all of them consistent.
@@ -2416,7 +2416,7 @@
   }
 
   // Populate the page template suggestions.
-  if ($suggestions = theme_get_suggestions(arg(), 'page')) {
+  if ($suggestions = theme_get_suggestions(drupal_get_context()->getValue('arg'), 'page')) {
     $variables['theme_hook_suggestions'] = $suggestions;
   }
 }
@@ -2485,7 +2485,7 @@
  * base the additional suggestions on the path of the current page.
  *
  * @param $args
- *   An array of path arguments, such as from function arg().
+ *   An array of path arguments, such as from the context argument handler.
  * @param $base
  *   A string identifying the base 'thing' from which more specific suggestions
  *   are derived. For example, 'page' or 'html'.
diff --git a/core/modules/aggregator/aggregator.admin.inc b/core/modules/aggregator/aggregator.admin.inc
index c29e143..04f11f2 100644
--- a/core/modules/aggregator/aggregator.admin.inc
+++ b/core/modules/aggregator/aggregator.admin.inc
@@ -184,7 +184,7 @@
   if (isset($form_state['values']['fid'])) {
     if (isset($form_state['values']['title'])) {
       drupal_set_message(t('The feed %feed has been updated.', array('%feed' => $form_state['values']['title'])));
-      if (arg(0) == 'admin') {
+      if (drupal_get_context()->getValue('arg:0') == 'admin') {
         $form_state['redirect'] = 'admin/config/services/aggregator/';
         return;
       }
@@ -196,7 +196,7 @@
     else {
       watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $title));
       drupal_set_message(t('The feed %feed has been deleted.', array('%feed' => $title)));
-      if (arg(0) == 'admin') {
+      if (drupal_get_context()->getValue('arg:0') == 'admin') {
         $form_state['redirect'] = 'admin/config/services/aggregator/';
         return;
       }
@@ -622,7 +622,7 @@
   if (isset($form_state['values']['cid'])) {
     if (isset($form_state['values']['title'])) {
       drupal_set_message(t('The category %category has been updated.', array('%category' => $form_state['values']['title'])));
-      if (arg(0) == 'admin') {
+      if (drupal_get_context()->getValue('arg:0') == 'admin') {
         $form_state['redirect'] = 'admin/config/services/aggregator/';
         return;
       }
@@ -634,7 +634,7 @@
     else {
       watchdog('aggregator', 'Category %category deleted.', array('%category' => $title));
       drupal_set_message(t('The category %category has been deleted.', array('%category' => $title)));
-      if (arg(0) == 'admin') {
+      if (drupal_get_context()->getValue('arg:0') == 'admin') {
         $form_state['redirect'] = 'admin/config/services/aggregator/';
         return;
       }
diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc
index 8fd44c2..a2227ec 100644
--- a/core/modules/aggregator/aggregator.pages.inc
+++ b/core/modules/aggregator/aggregator.pages.inc
@@ -17,7 +17,7 @@
 
   $items = aggregator_load_feed_items('sum');
 
-  return _aggregator_page_list($items, arg(1));
+  return _aggregator_page_list($items, drupal_get_context()->getValue('arg:1'));
 }
 
 /**
@@ -38,7 +38,7 @@
   // database by aggregator_feed_load().
   $items = aggregator_load_feed_items('source', $feed);
 
-  return _aggregator_page_list($items, arg(3), $feed_source);
+  return _aggregator_page_list($items, drupal_get_context()->getValue('arg:3'), $feed_source);
 }
 
 /**
@@ -75,7 +75,7 @@
   // database by aggregator_category_load().
   $items = aggregator_load_feed_items('category', $category);
 
-  return _aggregator_page_list($items, arg(3));
+  return _aggregator_page_list($items, drupal_get_context()->getValue('arg:3'));
 }
 
 /**
@@ -402,9 +402,10 @@
  */
 function aggregator_page_rss() {
   $result = NULL;
-  // arg(2) is the passed cid, only select for that category.
-  if (arg(2)) {
-    $category = db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = :cid', array(':cid' => arg(2)))->fetchObject();
+  // drupal_get_context()->getValue('arg:2') is the passed cid, only select for
+  // that category.
+  if (drupal_get_context()->getValue('arg:2')) {
+    $category = db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = :cid', array(':cid' => drupal_get_context()->getValue('arg:2')))->fetchObject();
     $result = db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = :cid ORDER BY timestamp DESC, i.iid DESC', 0, variable_get('feed_default_items', 10), array(':cid' => $category->cid));
   }
   // Or, get the default aggregator items.
diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module
index 496a043..323da7c 100644
--- a/core/modules/dblog/dblog.module
+++ b/core/modules/dblog/dblog.module
@@ -87,7 +87,7 @@
  * Implements hook_init().
  */
 function dblog_init() {
-  if (arg(0) == 'admin' && arg(1) == 'reports') {
+  if (drupal_get_context()->getValue('arg:0') == 'admin' && drupal_get_context()->getValue('arg:1') == 'reports') {
     // Add the CSS for this module
     drupal_add_css(drupal_get_path('module', 'dblog') . '/dblog.css');
   }
diff --git a/core/modules/filter/filter.pages.inc b/core/modules/filter/filter.pages.inc
index dbbbe4c..9b4b2c4 100644
--- a/core/modules/filter/filter.pages.inc
+++ b/core/modules/filter/filter.pages.inc
@@ -10,7 +10,7 @@
  * Menu callback; show a page with long filter tips.
  */
 function filter_tips_long() {
-  $format_id = arg(2);
+  $format_id = drupal_get_context()->getValue('arg:2');
   if ($format_id) {
     $output = theme('filter_tips', array('tips' => _filter_tips($format_id, TRUE), 'long' => TRUE));
   }
diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module
index 65c5489..b9bebdb 100644
--- a/core/modules/forum/forum.module
+++ b/core/modules/forum/forum.module
@@ -606,7 +606,7 @@
       // If there is no default forum already selected, try to get the forum
       // ID from the URL (e.g., if we are on a page like node/add/forum/2, we
       // expect "2" to be the ID of the forum that was requested).
-      $requested_forum_id = arg(3);
+      $requested_forum_id = drupal_get_context()->getValue('arg:3');
       $form['taxonomy_forums'][$langcode]['#default_value'] = is_numeric($requested_forum_id) ? $requested_forum_id : '';
     }
   }
diff --git a/core/modules/help/help.api.php b/core/modules/help/help.api.php
index f7d9c08..389bc08 100644
--- a/core/modules/help/help.api.php
+++ b/core/modules/help/help.api.php
@@ -33,15 +33,10 @@
  *       The main module help text, displayed on the admin/help/modulename
  *       page and linked to from the admin/help page.
  * @param $arg
- *   An array that corresponds to the return value of the arg() function, for
- *   modules that want to provide help that is specific to certain values
- *   of wildcards in $path. For example, you could provide help for the path
- *   'user/1' by looking for the path 'user/%' and $arg[1] == '1'. This given
- *   array should always be used rather than directly invoking arg(), because
- *   your hook implementation may be called for other purposes besides building
- *   the current page's help. Note that depending on which module is invoking
- *   hook_help, $arg may contain only empty strings. Regardless, $arg[0] to
- *   $arg[11] will always be set.
+ *   An array that corresponds to the return value of the context argument
+ *   handler, for modules that want to provide help that is specific to certain
+ *   values of wildcards in $path. For example, you could provide help for the
+ *   path 'user/1' by looking for the path 'user/%' and $arg[1] == '1'.
  *
  * @return
  *   A localized string containing the help text.
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index c429fe5..77559dc 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -2394,8 +2394,9 @@
 
   $node = menu_get_object();
   $node_types = node_type_get_types();
-  if (arg(0) == 'node' && arg(1) == 'add' && arg(2)) {
-    $node_add_arg = strtr(arg(2), '-', '_');
+  $context = drupal_get_context();
+  if ($context->getValue('arg:0') == 'node' && $context->getValue('arg:1') == 'add' && $context->getValue('arg:2')) {
+    $node_add_arg = strtr($context->getValue('arg:2'), '-', '_');
   }
   foreach ($blocks as $key => $block) {
     if (!isset($block->theme) || !isset($block->status) || $block->theme != $theme_key || $block->status != 1) {
diff --git a/core/modules/openid/openid.pages.inc b/core/modules/openid/openid.pages.inc
index 6e3f096..119bdbf 100644
--- a/core/modules/openid/openid.pages.inc
+++ b/core/modules/openid/openid.pages.inc
@@ -86,7 +86,7 @@
 }
 
 function openid_user_add_submit($form, &$form_state) {
-  $return_to = url('user/' . arg(1) . '/openid', array('absolute' => TRUE));
+  $return_to = url('user/' . drupal_get_context()->getValue('arg:1') . '/openid', array('absolute' => TRUE));
   openid_begin($form_state['values']['openid_identifier'], $return_to);
 }
 
diff --git a/core/modules/openid/tests/openid_test.module b/core/modules/openid/tests/openid_test.module
index 629dcd3..355e6bb 100644
--- a/core/modules/openid/tests/openid_test.module
+++ b/core/modules/openid/tests/openid_test.module
@@ -94,16 +94,17 @@
     // Only respond to XRI requests for one specific XRI. The is used to verify
     // that the XRI has been properly encoded. The "+" sign in the _xrd_r query
     // parameter is decoded to a space by PHP.
-    if (arg(3) == 'xri') {
+    $context = drupal_get_context();
+    if ($context->getValue('arg:3') == 'xri') {
       if (variable_get('clean_url', 0)) {
-        if (arg(4) != '@example*résumé;%25' || $_GET['_xrd_r'] != 'application/xrds xml') {
+        if ($context->getValue('arg:4') != '@example*résumé;%25' || $_GET['_xrd_r'] != 'application/xrds xml') {
           drupal_not_found();
         }
       }
       else {
         // Drupal cannot properly emulate an XRI proxy resolver using unclean
         // URLs, so the arguments gets messed up.
-        if (arg(4) . '/' . arg(5) != '@example*résumé;%25?_xrd_r=application/xrds xml') {
+        if ($context->getValue('arg:4') . '/' . $context->getValue('arg:5') != '@example*résumé;%25?_xrd_r=application/xrds xml') {
           drupal_not_found();
         }
       }
@@ -137,7 +138,7 @@
             <URI>http://example.com/this-has-too-low-priority</URI>
           </Service>
           ';
-    if (arg(3) == 'server') {
+    if ($context->getValue('arg:3') == 'server') {
       print '
           <Service>
             <Type>http://specs.openid.net/auth/2.0/server</Type>
@@ -148,7 +149,7 @@
             <URI>' . url('openid-test/endpoint', array('absolute' => TRUE)) . '</URI>
           </Service>';
     }
-    elseif (arg(3) == 'delegate') {
+    elseif ($context->getValue('arg:3') == 'delegate') {
       print '
           <Service priority="0">
             <Type>http://specs.openid.net/auth/2.0/signon</Type>
diff --git a/core/modules/simpletest/tests/form_test.module b/core/modules/simpletest/tests/form_test.module
index 0393b18..4e89443 100644
--- a/core/modules/simpletest/tests/form_test.module
+++ b/core/modules/simpletest/tests/form_test.module
@@ -1524,7 +1524,7 @@
   // 'image_button', and a 'button' with #access=FALSE. This enables form.test
   // to test a variety of combinations.
   $i=0;
-  $args = array_slice(arg(), 2);
+  $args = array_slice(drupal_get_context()->getValue('arg'), 2);
   foreach ($args as $arg) {
     $name = 'button' . ++$i;
     // 's', 'b', or 'i' in the argument define the button type wanted.
diff --git a/core/modules/simpletest/tests/menu_test.module b/core/modules/simpletest/tests/menu_test.module
index c42aca6..406c0b3 100644
--- a/core/modules/simpletest/tests/menu_test.module
+++ b/core/modules/simpletest/tests/menu_test.module
@@ -259,7 +259,7 @@
   );
   $items['menu-title-test/case2'] = array(
    'title' => 'Example @sub1 - Case @op2',
-   // If '2' is not in quotes, the argument becomes arg(2).
+   // If '2' is not in quotes, the argument becomes 'arg:2'.
    'title arguments' => array('@sub1' => 'title', '@op2' => '2'),
    'access callback' => TRUE,
    'page callback' => 'menu_test_callback',
@@ -274,7 +274,7 @@
    // Title gets completely ignored. Good thing, too.
    'title' => 'Bike sheds full of blue smurfs',
    'title callback' => 'menu_test_title_callback',
-   // If '4' is not in quotes, the argument becomes arg(4).
+   // If '4' is not in quotes, the argument becomes 'arg:4'.
    'title arguments' => array('Example title', '4'),
    'access callback' => TRUE,
    'page callback' => 'menu_test_callback',
diff --git a/core/modules/simpletest/tests/theme_test.module b/core/modules/simpletest/tests/theme_test.module
index 597c090..960362b 100644
--- a/core/modules/simpletest/tests/theme_test.module
+++ b/core/modules/simpletest/tests/theme_test.module
@@ -46,7 +46,8 @@
  * Implements hook_init().
  */
 function theme_test_init() {
-  if (arg(0) == 'theme-test' && arg(1) == 'hook-init') {
+  $context = drupal_get_context();
+  if ($context->getValue('arg:0') == 'theme-test' && context->getValue('arg:1') == 'hook-init') {
     // First, force the theme registry to be rebuilt on this page request. This
     // allows us to test a full initialization of the theme system in the code
     // below.
@@ -63,7 +64,7 @@
  * Implements hook_exit().
  */
 function theme_test_exit() {
-  if (arg(0) == 'user') {
+  if ($context->getValue('arg:0') == 'user') {
     // Register a fake registry loading callback. If it gets called by
     // theme_get_registry(), the registry has not been initialized yet.
     _theme_registry_callback('_theme_test_load_registry', array());
diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module
index b14dc4e..59c5d54 100644
--- a/core/modules/statistics/statistics.module
+++ b/core/modules/statistics/statistics.module
@@ -59,10 +59,11 @@
 
   if (variable_get('statistics_count_content_views', 0)) {
     // We are counting content views.
-    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL) {
+    $context = drupal_get_context();
+    if ($context->getValue('arg:0') == 'node' && is_numeric($context->getValue('arg:1')) && $context->getValue('arg:2') == NULL) {
       // A node has been viewed, so update the node's counters.
       db_merge('node_counter')
-        ->key(array('nid' => arg(1)))
+        ->key(array('nid' => $context->getValue('arg:1')))
         ->fields(array(
           'daycount' => 1,
           'totalcount' => 1,
diff --git a/core/modules/statistics/statistics.pages.inc b/core/modules/statistics/statistics.pages.inc
index bb31f98..26e2288 100644
--- a/core/modules/statistics/statistics.pages.inc
+++ b/core/modules/statistics/statistics.pages.inc
@@ -6,7 +6,7 @@
  */
 
 function statistics_node_tracker() {
-  if ($node = node_load(arg(1))) {
+  if ($node = node_load(drupal_get_context()->getValue('arg:1'))) {
 
     $header = array(
         array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),
@@ -53,7 +53,7 @@
 }
 
 function statistics_user_tracker() {
-  if ($account = user_load(arg(1))) {
+  if ($account = user_load(drupal_get_context()->getValue('arg:1'))) {
 
     $header = array(
         array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
diff --git a/core/modules/trigger/trigger.module b/core/modules/trigger/trigger.module
index c0e516f..43f508d 100644
--- a/core/modules/trigger/trigger.module
+++ b/core/modules/trigger/trigger.module
@@ -453,8 +453,9 @@
     // If a single node is being viewed, return the node.
     case 'node':
       // If we are viewing an individual node, return the node.
-      if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL) {
-        return node_load(array('nid' => arg(1)));
+      $context = drupal_get_context();
+      if ($context->getValue('arg:1') == 'node' && is_numeric($context->getValue('arg:1')) && $context->getValue('arg:2') == NULL) {
+        return node_load(array('nid' => $context->getValue('arg:1')));
       }
       break;
   }
diff --git a/core/modules/update/update.module b/core/modules/update/update.module
index 43baebb..62073ea 100644
--- a/core/modules/update/update.module
+++ b/core/modules/update/update.module
@@ -106,7 +106,7 @@
  * Implements hook_init().
  */
 function update_init() {
-  if (arg(0) == 'admin' && user_access('administer site configuration')) {
+  if (drupal_get_context()->getValue('arg:0') == 'admin' && user_access('administer site configuration')) {
     switch (drupal_get_context()->getValue('path:system')) {
       // These pages don't need additional nagging.
       case 'admin/appearance/update':
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index af40a5f..0e2ff3b 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -1308,7 +1308,8 @@
   switch ($delta) {
     case 'login':
       // For usability's sake, avoid showing two login forms on one page.
-      if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
+      $context = drupal_get_context();
+      if (!$user->uid && !($context->getValue('arg:0') == 'user' && !is_numeric($context->getValue('arg:1')))) {
 
         $block['subject'] = t('User login');
         $block['content'] = drupal_get_form('user_login_block');
