Issue #1305378 by bforchhammer, penyaskito, k4v, Schnitzel, Gábor Hojtsy, Dave Reid: Added Tokens should use $options["langcode"] and not need a language object.
parent
7d7aa9797f
commit
44fc81a277
|
@ -53,7 +53,7 @@ define('MAIL_LINE_ENDINGS', isset($_SERVER['WINDIR']) || strpos($_SERVER['SERVER
|
|||
*
|
||||
* function example_mail($key, &$message, $params) {
|
||||
* $data['user'] = $params['account'];
|
||||
* $options['language'] = $message['language'];
|
||||
* $options['langcode'] = $message['language'];
|
||||
* user_mail_tokens($variables, $data, $options);
|
||||
* switch($key) {
|
||||
* case 'notice':
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
* @param $options
|
||||
* (optional) A keyed array of settings and flags to control the token
|
||||
* replacement process. Supported options are:
|
||||
* - language: A language object to be used when generating locale-sensitive
|
||||
* - langcode: A language code to be used when generating locale-sensitive
|
||||
* tokens.
|
||||
* - callback: A callback function that will be used to post-process the array
|
||||
* of token replacements after they are generated. For example, a module
|
||||
|
@ -154,7 +154,7 @@ function token_scan($text) {
|
|||
* @param $options
|
||||
* (optional) A keyed array of settings and flags to control the token
|
||||
* replacement process. Supported options are:
|
||||
* - language: A language object to be used when generating locale-sensitive
|
||||
* - langcode: A language code to be used when generating locale-sensitive
|
||||
* tokens.
|
||||
* - callback: A callback function that will be used to post-process the
|
||||
* array of token replacements after they are generated. Can be used when
|
||||
|
|
|
@ -104,9 +104,9 @@ function comment_token_info() {
|
|||
*/
|
||||
function comment_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$url_options = array('absolute' => TRUE);
|
||||
if (isset($options['language'])) {
|
||||
$url_options['language'] = $options['language'];
|
||||
$langcode = $options['language']->langcode;
|
||||
if (isset($options['langcode'])) {
|
||||
$url_options['language'] = language_load($options['langcode']);
|
||||
$langcode = $options['langcode'];
|
||||
}
|
||||
else {
|
||||
$langcode = NULL;
|
||||
|
|
|
@ -72,7 +72,7 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('comment' => $comment), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('comment' => $comment), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Sanitized comment token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
$tests['[comment:author:name]'] = $this->admin_user->name;
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('comment' => $comment), array('language' => $language_interface, 'sanitize' => FALSE));
|
||||
$output = token_replace($input, array('comment' => $comment), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, t('Unsanitized comment token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
$tests['[node:comment-count-new]'] = 2;
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('node' => $node), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('node' => $node), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Node comment token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('file' => $file), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('file' => $file), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Sanitized file token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
|
|||
$tests['[file:size]'] = format_size($file->filesize);
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('file' => $file), array('language' => $language_interface, 'sanitize' => FALSE));
|
||||
$output = token_replace($input, array('file' => $file), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, t('Unsanitized file token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ class NodeTokenReplaceTest extends NodeTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('node' => $node), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('node' => $node), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Sanitized node token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ class NodeTokenReplaceTest extends NodeTestBase {
|
|||
$tests['[node:author:name]'] = user_format_name($account);
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('node' => $node), array('language' => $language_interface, 'sanitize' => FALSE));
|
||||
$output = token_replace($input, array('node' => $node), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, t('Unsanitized node token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,12 +91,12 @@ function node_token_info() {
|
|||
*/
|
||||
function node_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$url_options = array('absolute' => TRUE);
|
||||
if (isset($options['language'])) {
|
||||
$url_options['language'] = $options['language'];
|
||||
$language_code = $options['language']->langcode;
|
||||
if (isset($options['langcode'])) {
|
||||
$url_options['language'] = language_load($options['langcode']);
|
||||
$langcode = $options['langcode'];
|
||||
}
|
||||
else {
|
||||
$language_code = NULL;
|
||||
$langcode = NULL;
|
||||
}
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
|
||||
|
@ -135,10 +135,10 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
|
|||
|
||||
case 'body':
|
||||
case 'summary':
|
||||
if ($items = field_get_items('node', $node, 'body', $language_code)) {
|
||||
if ($items = field_get_items('node', $node, 'body', $langcode)) {
|
||||
$column = ($name == 'body') ? 'value' : 'summary';
|
||||
$instance = field_info_instance('node', 'body', $node->type);
|
||||
$field_langcode = field_language('node', $node, 'body', $language_code);
|
||||
$field_langcode = field_language('node', $node, 'body', $langcode);
|
||||
$replacements[$original] = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], $column) : $items[0][$column];
|
||||
}
|
||||
break;
|
||||
|
@ -163,11 +163,11 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
|
|||
break;
|
||||
|
||||
case 'created':
|
||||
$replacements[$original] = format_date($node->created, 'medium', '', NULL, $language_code);
|
||||
$replacements[$original] = format_date($node->created, 'medium', '', NULL, $langcode);
|
||||
break;
|
||||
|
||||
case 'changed':
|
||||
$replacements[$original] = format_date($node->changed, 'medium', '', NULL, $language_code);
|
||||
$replacements[$original] = format_date($node->changed, 'medium', '', NULL, $langcode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class PollTokenReplaceTest extends PollTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('node' => $poll), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('node' => $poll), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Sanitized poll token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ class PollTokenReplaceTest extends PollTestBase {
|
|||
$tests['[node:poll-winner]'] = $poll->choice[1]['chtext'];
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('node' => $poll), array('language' => $language_interface, 'sanitize' => FALSE));
|
||||
$output = token_replace($input, array('node' => $poll), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, t('Unsanitized poll token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,12 +40,12 @@ function poll_token_info() {
|
|||
*/
|
||||
function poll_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
if (isset($options['language'])) {
|
||||
$url_options['language'] = $options['language'];
|
||||
$language_code = $options['language']->langcode;
|
||||
if (isset($options['langcode'])) {
|
||||
$url_options['language'] = language_load($options['langcode']);
|
||||
$langcode = $options['langcode'];
|
||||
}
|
||||
else {
|
||||
$language_code = NULL;
|
||||
$langcode = NULL;
|
||||
}
|
||||
|
||||
$replacements = array();
|
||||
|
@ -97,7 +97,7 @@ function poll_tokens($type, $tokens, array $data = array(), array $options = arr
|
|||
break;
|
||||
|
||||
case 'poll-duration':
|
||||
$replacements[$original] = format_interval($node->runtime, 1, $language_code);
|
||||
$replacements[$original] = format_interval($node->runtime, 1, $langcode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class StatisticsTokenReplaceTest extends StatisticsTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('node' => $node), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('node' => $node), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Statistics token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,13 +47,13 @@ class TokenReplaceTest extends WebTestBase {
|
|||
$target .= format_date(REQUEST_TIME, 'short', '', NULL, $language_interface->langcode);
|
||||
|
||||
// Test that the clear parameter cleans out non-existent tokens.
|
||||
$result = token_replace($source, array('node' => $node), array('language' => $language_interface, 'clear' => TRUE));
|
||||
$result = token_replace($source, array('node' => $node), array('langcode' => $language_interface->langcode, 'clear' => TRUE));
|
||||
$result = $this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens cleared out.');
|
||||
|
||||
// Test without using the clear parameter (non-existent token untouched).
|
||||
$target .= '[user:name]';
|
||||
$target .= '[bogus:token]';
|
||||
$result = token_replace($source, array('node' => $node), array('language' => $language_interface));
|
||||
$result = token_replace($source, array('node' => $node), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
|
||||
|
||||
// Check that the results of token_generate are sanitized properly. This does NOT
|
||||
|
@ -95,7 +95,7 @@ class TokenReplaceTest extends WebTestBase {
|
|||
foreach ($tests as $test) {
|
||||
$input = $test['prefix'] . '[site:name]' . $test['suffix'];
|
||||
$expected = $test['prefix'] . 'Drupal' . $test['suffix'];
|
||||
$output = token_replace($input, array(), array('language' => $language_interface));
|
||||
$output = token_replace($input, array(), array('langcode' => $language_interface->langcode));
|
||||
$this->assertTrue($output == $expected, t('Token recognized in string %string', array('%string' => $input)));
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ class TokenReplaceTest extends WebTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array(), array('language' => $language_interface));
|
||||
$output = token_replace($input, array(), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Sanitized system site information token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ class TokenReplaceTest extends WebTestBase {
|
|||
$tests['[site:slogan]'] = config('system.site')->get('slogan');
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array(), array('language' => $language_interface, 'sanitize' => FALSE));
|
||||
$output = token_replace($input, array(), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, t('Unsanitized system site information token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ class TokenReplaceTest extends WebTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('date' => $date), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('date' => $date), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Date token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3754,12 +3754,12 @@ function hook_url_outbound_alter(&$path, &$options, $original_path) {
|
|||
*/
|
||||
function hook_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$url_options = array('absolute' => TRUE);
|
||||
if (isset($options['language'])) {
|
||||
$url_options['language'] = $options['language'];
|
||||
$language_code = $options['language']->langcode;
|
||||
if (isset($options['langcode'])) {
|
||||
$url_options['language'] = language_load($options['langcode']);
|
||||
$langcode = $options['langcode'];
|
||||
}
|
||||
else {
|
||||
$language_code = NULL;
|
||||
$langcode = NULL;
|
||||
}
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
|
||||
|
@ -3790,7 +3790,7 @@ function hook_tokens($type, $tokens, array $data = array(), array $options = arr
|
|||
break;
|
||||
|
||||
case 'created':
|
||||
$replacements[$original] = format_date($node->created, 'medium', '', NULL, $language_code);
|
||||
$replacements[$original] = format_date($node->created, 'medium', '', NULL, $langcode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3827,12 +3827,12 @@ function hook_tokens($type, $tokens, array $data = array(), array $options = arr
|
|||
function hook_tokens_alter(array &$replacements, array $context) {
|
||||
$options = $context['options'];
|
||||
|
||||
if (isset($options['language'])) {
|
||||
$url_options['language'] = $options['language'];
|
||||
$language_code = $options['language']->langcode;
|
||||
if (isset($options['langcode'])) {
|
||||
$url_options['language'] = language_load($options['langcode']);
|
||||
$langcode = $options['langcode'];
|
||||
}
|
||||
else {
|
||||
$language_code = NULL;
|
||||
$langcode = NULL;
|
||||
}
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
|
||||
|
@ -3842,7 +3842,7 @@ function hook_tokens_alter(array &$replacements, array $context) {
|
|||
// Alter the [node:title] token, and replace it with the rendered content
|
||||
// of a field (field_title).
|
||||
if (isset($context['tokens']['title'])) {
|
||||
$title = field_view_field('node', $node, 'field_title', 'default', $language_code);
|
||||
$title = field_view_field('node', $node, 'field_title', 'default', $langcode);
|
||||
$replacements[$context['tokens']['title']] = drupal_render($title);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,12 +130,12 @@ function system_token_info() {
|
|||
*/
|
||||
function system_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$url_options = array('absolute' => TRUE);
|
||||
if (isset($options['language'])) {
|
||||
$url_options['language'] = $options['language'];
|
||||
$language_code = $options['language']->langcode;
|
||||
if (isset($options['langcode'])) {
|
||||
$url_options['language'] = language_load($options['langcode']);
|
||||
$langcode = $options['langcode'];
|
||||
}
|
||||
else {
|
||||
$language_code = NULL;
|
||||
$langcode = NULL;
|
||||
}
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
|
||||
|
@ -184,19 +184,19 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
|
|||
foreach ($tokens as $name => $original) {
|
||||
switch ($name) {
|
||||
case 'short':
|
||||
$replacements[$original] = format_date($date, 'short', '', NULL, $language_code);
|
||||
$replacements[$original] = format_date($date, 'short', '', NULL, $langcode);
|
||||
break;
|
||||
|
||||
case 'medium':
|
||||
$replacements[$original] = format_date($date, 'medium', '', NULL, $language_code);
|
||||
$replacements[$original] = format_date($date, 'medium', '', NULL, $langcode);
|
||||
break;
|
||||
|
||||
case 'long':
|
||||
$replacements[$original] = format_date($date, 'long', '', NULL, $language_code);
|
||||
$replacements[$original] = format_date($date, 'long', '', NULL, $langcode);
|
||||
break;
|
||||
|
||||
case 'since':
|
||||
$replacements[$original] = format_interval((REQUEST_TIME - $date), 2, $language_code);
|
||||
$replacements[$original] = format_interval((REQUEST_TIME - $date), 2, $langcode);
|
||||
break;
|
||||
|
||||
case 'raw':
|
||||
|
@ -207,7 +207,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
|
|||
|
||||
if ($created_tokens = token_find_with_prefix($tokens, 'custom')) {
|
||||
foreach ($created_tokens as $name => $original) {
|
||||
$replacements[$original] = format_date($date, 'custom', $name, NULL, $language_code);
|
||||
$replacements[$original] = format_date($date, 'custom', $name, NULL, $langcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
|
|||
|
||||
// These tokens are default variations on the chained tokens handled below.
|
||||
case 'timestamp':
|
||||
$replacements[$original] = format_date($file->timestamp, 'medium', '', NULL, $language_code);
|
||||
$replacements[$original] = format_date($file->timestamp, 'medium', '', NULL, $langcode);
|
||||
break;
|
||||
|
||||
case 'owner':
|
||||
|
|
|
@ -91,7 +91,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
$tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name);
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('term' => $term1), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('term' => $term1), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('term' => $term2), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('term' => $term2), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
$tests['[term:vocabulary:name]'] = $this->vocabulary->name;
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('term' => $term2), array('language' => $language_interface, 'sanitize' => FALSE));
|
||||
$output = token_replace($input, array('term' => $term2), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('vocabulary' => $this->vocabulary), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
$tests['[vocabulary:description]'] = $this->vocabulary->description;
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('vocabulary' => $this->vocabulary), array('language' => $language_interface, 'sanitize' => FALSE));
|
||||
$output = token_replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -274,31 +274,31 @@ class TranslationTest extends WebTestBase {
|
|||
/**
|
||||
* Installs the specified language, or enables it if it is already installed.
|
||||
*
|
||||
* @param $language_code
|
||||
* @param $langcode
|
||||
* The language code to check.
|
||||
*/
|
||||
function addLanguage($language_code) {
|
||||
function addLanguage($langcode) {
|
||||
// Check to make sure that language has not already been installed.
|
||||
$this->drupalGet('admin/config/regional/language');
|
||||
|
||||
if (strpos($this->drupalGetContent(), 'languages[' . $language_code . ']') === FALSE) {
|
||||
if (strpos($this->drupalGetContent(), 'languages[' . $langcode . ']') === FALSE) {
|
||||
// Doesn't have language installed so add it.
|
||||
$edit = array();
|
||||
$edit['predefined_langcode'] = $language_code;
|
||||
$edit['predefined_langcode'] = $langcode;
|
||||
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Make sure we are not using a stale list.
|
||||
drupal_static_reset('language_list');
|
||||
$languages = language_list();
|
||||
$this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
|
||||
$this->assertTrue(array_key_exists($langcode, $languages), t('Language was installed successfully.'));
|
||||
|
||||
if (array_key_exists($language_code, $languages)) {
|
||||
$this->assertRaw(t('The language %language has been created and can now be used.', array('%language' => $languages[$language_code]->name)), t('Language has been created.'));
|
||||
if (array_key_exists($langcode, $languages)) {
|
||||
$this->assertRaw(t('The language %language has been created and can now be used.', array('%language' => $languages[$langcode]->name)), t('Language has been created.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// It's installed. No need to do anything.
|
||||
$this->assertTrue(true, 'Language [' . $language_code . '] already installed.');
|
||||
$this->assertTrue(true, 'Language [' . $langcode . '] already installed.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class UserTokenReplaceTest extends WebTestBase {
|
|||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('user' => $account), array('language' => $language_interface));
|
||||
$output = token_replace($input, array('user' => $account), array('langcode' => $language_interface->langcode));
|
||||
$this->assertEqual($output, $expected, t('Sanitized user token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class UserTokenReplaceTest extends WebTestBase {
|
|||
$tests['[current-user:name]'] = user_format_name($global_account);
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = token_replace($input, array('user' => $account), array('language' => $language_interface, 'sanitize' => FALSE));
|
||||
$output = token_replace($input, array('user' => $account), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, t('Unsanitized user token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,9 @@ function user_token_info() {
|
|||
*/
|
||||
function user_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$url_options = array('absolute' => TRUE);
|
||||
if (isset($options['language'])) {
|
||||
$url_options['language'] = $options['language'];
|
||||
$langcode = $options['language']->langcode;
|
||||
if (isset($options['langcode'])) {
|
||||
$url_options['language'] = language_load($options['langcode']);
|
||||
$langcode = $options['langcode'];
|
||||
}
|
||||
else {
|
||||
$langcode = NULL;
|
||||
|
|
Loading…
Reference in New Issue