diff --git a/token.test b/token.test index e362af3..8bf7113 100644 --- a/token.test +++ b/token.test @@ -743,7 +743,7 @@ class TokenCurrentPageTestCase extends TokenTestHelper { function testCurrentPageTokens() { $tokens = array( - '[current-page:title]' => 'Welcome to Drupal', + '[current-page:title]' => t('Welcome to @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), '[current-page:url]' => url('node', array('absolute' => TRUE)), '[current-page:url:absolute]' => url('node', array('absolute' => TRUE)), '[current-page:url:relative]' => url('node', array('absolute' => FALSE)), @@ -752,6 +752,9 @@ class TokenCurrentPageTestCase extends TokenTestHelper { '[current-page:page-number]' => 1, '[current-page:arg:0]' => 'node', '[current-page:arg:1]' => NULL, + '[current-page:query:foo]' => NULL, + '[current-page:query:bar]' => NULL, + '[current-page:query:q]' => 'node', ); $this->assertPageTokens('', $tokens); @@ -767,8 +770,11 @@ class TokenCurrentPageTestCase extends TokenTestHelper { '[current-page:arg:0]' => 'node', '[current-page:arg:1]' => $node->nid, '[current-page:arg:2]' => NULL, + '[current-page:query:foo]' => 'bar', + '[current-page:query:bar]' => NULL, + '[current-page:query:q]' => 'node/1', ); - $this->assertPageTokens("node/{$node->nid}", $tokens); + $this->assertPageTokens("node/{$node->nid}", $tokens, array(), array('url_options' => array('query' => array('foo' => 'bar')))); } } diff --git a/token.tokens.inc b/token.tokens.inc index a5f352e..ed79f52 100644 --- a/token.tokens.inc +++ b/token.tokens.inc @@ -213,6 +213,11 @@ function token_token_info() { 'description' => t("The specific argument of the current page (e.g. 'arg:1' on the page 'node/1' returns '1')."), 'dynamic' => TRUE, ); + $info['tokens']['current-page']['query'] = array( + 'name' => t('Query string value'), + 'description' => t('The value of a specific query string field of the current page.'), + 'dynamic' => TRUE, + ); // URL tokens. $info['types']['url'] = array( @@ -550,7 +555,7 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar } } - // Argument tokens. + // [current-page:arg] dynamic tokens. if ($arg_tokens = token_find_with_prefix($tokens, 'arg')) { foreach ($arg_tokens as $name => $original) { if (is_numeric($name) && ($arg = arg($name)) && isset($arg)) { @@ -559,6 +564,15 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar } } + // [current-page:query] dynamic tokens. + if ($query_tokens = token_find_with_prefix($tokens, 'query')) { + foreach ($query_tokens as $name => $original) { + if (isset($_GET[$name])) { + $replacements[$original] = $sanitize ? check_plain($_GET[$name]) : $_GET[$name]; + } + } + } + // Chained token relationships. if ($url_tokens = token_find_with_prefix($tokens, 'url')) { $replacements += token_generate('url', $url_tokens, array('path' => $current_path), $options);