summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorziomizar2016-07-30 15:40:28 +0200
committerSascha Grossenbacher2016-07-30 15:40:35 +0200
commit0bf90c6343766d4a44a83fb93423acc02fd85d86 (patch)
tree177926864ceb81b0c88b4ec3ece1865626b3e6c2
parent1fc9c5a80835d339362b9fa866f5595c12eafa23 (diff)
Issue #2769577 by ziomizar, Gravypower: Fixed Field xxx is unknown exception.
-rw-r--r--tests/src/Kernel/FieldTest.php16
-rw-r--r--token.tokens.inc4
2 files changed, 19 insertions, 1 deletions
diff --git a/tests/src/Kernel/FieldTest.php b/tests/src/Kernel/FieldTest.php
index 732657c..1eb88db 100644
--- a/tests/src/Kernel/FieldTest.php
+++ b/tests/src/Kernel/FieldTest.php
@@ -206,6 +206,22 @@ class FieldTest extends KernelTestBase {
$this->assertEqual($typeInfo['name'], 'List of test_list values');
$this->assertEqual($typeInfo['type'], 'list<node-test_list>');
+ // Create a node type that does not have test_field field.
+ $node_type = NodeType::create([
+ 'type' => 'page',
+ ]);
+ $node_type->save();
+
+ $node_without_test_field = Node::create([
+ 'title' => 'Node without test_field',
+ 'type' => 'page',
+ ]);
+ $node_without_test_field->save();
+
+ // Ensure that trying to generate tokens for a non-existing field does not
+ // throw an exception.
+ $this->assertNoTokens('node', ['node' => $node_without_test_field], ['test_field']);
+
// Create a node without a value in the text field and test its token.
$entity = Node::create([
'title' => 'Test node title',
diff --git a/token.tokens.inc b/token.tokens.inc
index 5b39039..be11518 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -1357,7 +1357,9 @@ function field_tokens($type, $tokens, array $data = array(), array $options = ar
}
$token_name = $field_name;
}
- if (_token_module($data['token_type'], $token_name) != 'token') {
+ // Ensure the entity has the requested field and that the token for it is
+ // defined by token.module.
+ if (!$entity->hasField($field_name) || _token_module($data['token_type'], $token_name) != 'token') {
continue;
}