diff --git a/tests/src/Kernel/FieldTest.php b/tests/src/Kernel/FieldTest.php index 8e96f31..69637fa 100644 --- a/tests/src/Kernel/FieldTest.php +++ b/tests/src/Kernel/FieldTest.php @@ -62,6 +62,7 @@ class FieldTest extends TokenKernelTestBase { 'language', 'datetime', 'datetime_range', + 'path', ]; /** @@ -472,8 +473,11 @@ class FieldTest extends TokenKernelTestBase { $this->assertEquals($token_info['description'], 'Text (plain) field.'); $this->assertEquals($token_info['module'], 'token'); - // Verify that node entity type doesn't have a uid token. - $this->assertNull($tokenService->getTokenInfo('node', 'uid')); + // Verify that node entity type has the uid token, a stored base field. + $this->assertNotNull($tokenService->getTokenInfo('node', 'uid')); + + // Verify that node entity type has the path token, a computed base field. + $this->assertNotNull($tokenService->getTokenInfo('node', 'path')); } /** diff --git a/token.tokens.inc b/token.tokens.inc index 7df34a4..e9e91f6 100644 --- a/token.tokens.inc +++ b/token.tokens.inc @@ -1552,20 +1552,20 @@ function _field_token_info_alter(&$info) { continue; } - $fields = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id); - foreach ($fields as $field_name => $field) { - /** @var \Drupal\field\FieldStorageConfigInterface $field */ + // Get base and storage field definitions for the entity type. + // Base field definitions include computed fields, while storage field + // definitions include + $fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type_id) + + \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id); - // Ensure the token implements FieldStorageConfigInterface or is defined - // in token module. - $provider = ''; - if (isset($info['types'][$token_type]['module'])) { - $provider = $info['types'][$token_type]['module']; - } - if (!($field instanceof FieldStorageConfigInterface) && $provider != 'token') { - continue; - } + // Bundles can define their own base field definitions so add those to the + // field list too. + // @see hook_entity_bundle_field_info_alter(). + foreach (\Drupal::service('entity_type.bundle.info')->getBundleInfo($entity_type_id) as $bundle_name => $bundle) { + $fields += \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle_name); + } + foreach ($fields as $field_name => $field) { // If a token already exists for this field, then don't add it. if (isset($info['tokens'][$token_type][$field_name])) { continue;