diff --git a/tests/src/Kernel/FieldTest.php b/tests/src/Kernel/FieldTest.php index 99af343..caba840 100644 --- a/tests/src/Kernel/FieldTest.php +++ b/tests/src/Kernel/FieldTest.php @@ -209,12 +209,11 @@ class FieldTest extends KernelTestBase { */ public function testBaseFieldToken() { // Create a new contact_message entity and verify that tokens are generated - // for its base fields. A contact_message is used, as that entity type does - // not provide any token by default. + // for its base fields. The contact_message entity type is used because it + // provides no tokens by default. $contact_form = ContactForm::create([ - 'id' => 'form_id', - ] - ); + 'id' => 'form_id', + ]); $contact_form->save(); $entity = Message::create([ diff --git a/token.tokens.inc b/token.tokens.inc index 09060f8..bd0cfd0 100644 --- a/token.tokens.inc +++ b/token.tokens.inc @@ -70,10 +70,11 @@ function token_token_info_alter(&$info) { $token_type = $entity_info->get('token_type'); if (!isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) { - // Define entity type that doesn't exist yet. + $entity_type_label = Unicode::strtolower($entity_info->getPluralLabel()); + // Define tokens for entity type's without their own integration. $info['types'][$entity_info->id()] = [ 'name' => $entity_info->getLabel(), - 'description' => t('Tokens related to %entity entity.', ['%entity' => $entity_info->getLabel()]), + 'description' => t('Tokens related to @entity_type.', ['@entity_type' => $entity_type_label]), 'needs-data' => $entity_info->id(), 'module' => 'token', ]; @@ -1178,15 +1179,12 @@ function field_token_info_alter(&$info) { // Ensure the token implements FieldStorageConfigInterface or is defined // in token module. - if (!($field instanceof FieldStorageConfigInterface)) { - if (isset($info['types'][$token_type]['module'])) { - if ($info['types'][$token_type]['module'] !== 'token') { - continue; - } - } - else { - continue; - } + $provider = ''; + if (isset($info['types'][$token_type]['module'])) { + $provider = $info['types'][$token_type]['module']; + } + if (!($field instanceof FieldStorageConfigInterface) && $provider != 'token') { + continue; } // If a token already exists for this field, then don't add it. @@ -1226,7 +1224,9 @@ function field_token_info_alter(&$info) { * * Therefore it looks up in all bundles to find the most used instance. * - * Based on field_views_field_label(). + * Based on views_entity_field_label(). + * + * @todo Resync this method with views_entity_field_label(). */ function _token_field_label($entity_type, $field_name) { $labels = [];