diff --git a/token.module b/token.module index 7bba8a7..d154ad6 100644 --- a/token.module +++ b/token.module @@ -377,7 +377,7 @@ function token_clear_cache() { * @see token_entity_info_alter() * @see http://drupal.org/node/737726 */ -function token_get_entity_mapping($value_type = 'token', $value = NULL) { +function token_get_entity_mapping($value_type = 'token', $value = NULL, $fallback = FALSE) { $mapping = &drupal_static(__FUNCTION__, array()); if (empty($mapping)) { @@ -390,10 +390,11 @@ function token_get_entity_mapping($value_type = 'token', $value = NULL) { return $mapping; } elseif ($value_type == 'token') { - return array_search($value, $mapping); + $return = array_search($value, $mapping); + return $return !== FALSE ? $return : ($fallback ? $value : FALSE); } elseif ($value_type == 'entity') { - return isset($mapping[$value]) ? $mapping[$value] : FALSE; + return isset($mapping[$value]) ? $mapping[$value] : ($fallback ? $value : FALSE); } } diff --git a/token.test b/token.test index b7e9582..59fa645 100644 --- a/token.test +++ b/token.test @@ -676,10 +676,12 @@ class TokenEntityTestCase extends TokenTestHelper { $this->assertIdentical(token_get_entity_mapping('token', 'term'), 'taxonomy_term'); $this->assertIdentical(token_get_entity_mapping('token', 'vocabulary'), 'taxonomy_vocabulary'); $this->assertIdentical(token_get_entity_mapping('token', 'invalid'), FALSE); + $this->assertIdentical(token_get_entity_mapping('token', 'invalid', TRUE), 'invalid'); $this->assertIdentical(token_get_entity_mapping('entity', 'node'), 'node'); $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_term'), 'term'); $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_vocabulary'), 'vocabulary'); $this->assertIdentical(token_get_entity_mapping('entity', 'invalid'), FALSE); + $this->assertIdentical(token_get_entity_mapping('entity', 'invalid', TRUE), 'invalid'); // Test that when we send the mis-matched entity type into token_replace() // that we still get the tokens replaced.