- Patch #1346166 by Dave Reid: Improve performance of token_replace() if there are no tokens to replace.
parent
68fc0fad1a
commit
b55fc01277
|
@ -77,8 +77,13 @@
|
|||
* Text with tokens replaced.
|
||||
*/
|
||||
function token_replace($text, array $data = array(), array $options = array()) {
|
||||
$text_tokens = token_scan($text);
|
||||
if (empty($text_tokens)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
$replacements = array();
|
||||
foreach (token_scan($text) as $type => $tokens) {
|
||||
foreach ($text_tokens as $type => $tokens) {
|
||||
$replacements += token_generate($type, $tokens, $data, $options);
|
||||
if (!empty($options['clear'])) {
|
||||
$replacements += array_fill_keys($tokens, '');
|
||||
|
|
|
@ -1852,6 +1852,9 @@ class TokenReplaceTestCase extends DrupalWebTestCase {
|
|||
|
||||
$generated = token_generate('node', $raw_tokens, array('node' => $node), array('sanitize' => FALSE));
|
||||
$this->assertEqual($generated['[node:title]'], $node->title, t('Unsanitized token generated properly.'));
|
||||
|
||||
// Test token replacement when the string contains no tokens.
|
||||
$this->assertEqual(token_replace('No tokens here.'), 'No tokens here.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue