For the Year Only fields I get the following warnings:

$info['tokens']['node-field_my_node_field_type1_year']['value']
$info['tokens']['node-field_my_node_field_type2_year']['value']
$info['tokens']['node-field_my_node_field_type3_year']['value']
$info['tokens']['node-field_my_node_field_type4_year']['value']
$info['tokens']['paragraph-field_my_node_field_type1_year']['value']
$info['tokens']['paragraph-field_my_node_field_type2_year']['value']
$info['tokens']['paragraph-field_my_node_field_type3_year']['value']
$info['tokens']['paragraph-field_my_node_field_type4_year']['value']
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Thomas Factory created an issue. See original summary.

steveoriol’s picture

You can add (patch) in "yearonly.module" with the next code, but it's not dynamic :-(

/**
 * Implements hook_token_info_alter().
 */

function yearonly_token_info_alter(&$info) {
  $info['tokens']['node-field_my_node_field_type1_year']['value'] = array (
    'name' => t('yearonly: type1'),
    'description' => t('Yearonly for the type1'),
  );
  $info['tokens']['node-field_my_node_field_type2_year']['value'] = array (
    'name' => t('yearonly: type2'),
    'description' => t('Yearonly for the type2'),
  );
[...]
}
waverate’s picture

It looks like the Heading Field module figured out how to do this dynamically within the module.

See how they did it in patch #10 at #2934662: TOKENS OR TOKEN TYPES MISSING NAME PROPERTY after update.

waverate’s picture

Status: Active » Needs review
FileSize
936 bytes

Shamelessly taken from Heading Field module at #3.

Patch attached.

GaëlG’s picture

Status: Needs review » Reviewed & tested by the community

It may be shameless, but it works! :)

jungle’s picture

Assigned: Unassigned » jungle
Status: Reviewed & tested by the community » Needs work

The root cause is that the filed type definition is incomplete

jungle’s picture

Run `drush updb` to get it updated

jungle’s picture

Assigned: jungle » Unassigned
Status: Needs work » Needs review
aperedos’s picture

The patch https://www.drupal.org/files/issues/2019-08-01/token_missing-2951179-7.p... doesn´t work for 1.3.0, the warning still apearing on the status report page after apply the patch and run updb.

Thanks,

ronaldmulero’s picture

Thanks waverate. #4 works.

Drupal 8.8.5
yearonly 8.x-1.3

robcarr’s picture

Status: Needs review » Reviewed & tested by the community

Patch #4 works on Drupal 8.9

superlolo95’s picture

#4 works for nodes but not for paragraphs.

skumararatne’s picture

I used patch #4 but slightly modified it to work with my custom content entities that were throwing the missing name property warning. This should work with paragraph entities as well though i haven't tested that.

/**
 * Implements hook_token_info_alter().
 *
 * This adds the missing token info for automatically detected tokens.
 */

function yearonly_token_info_alter(&$info) {
  $entities = \Drupal::service('entity_field.manager')->getFieldMap();
  foreach ($entities as $entity_key => $entity) {
    foreach ($entity as $field_key => $field) {
      if ($field['type'] !== 'yearonly' ) {
        continue;
      }

      $token_key = sprintf($entity_key . '-%s', $field_key);
      $info['tokens'][$token_key]['value'] = [
        'name' => t('Year Only'),
        'description' => t('Year only value.'),
      ];
    }
  }
}
PCate’s picture

#4 patch did not apply for me with latest 8.x release, but #7 did and fixed the issue once I ran updb.

noah’s picture

It looks like the patch excludes every entity type except nodes—is that necessary for this solution? I've seen this warning for fields in taxonomy terms and paragraphs, would a more generic solution like that proposed by @skumararatne work, or are there potential unintended consequences?

ronaldmulero’s picture

#7 fixes $info['tokens']['term-field_year']['value'] warning that #4 did not.
Thanks jungle!

Drupal 8.9.13
yearonly 9.0.0

AlvaroDeMendoza’s picture

FileSize
982 bytes

Updated patch with code from #13

Drupal 9.3.9
yearonly 9.0.0

superlolo95’s picture

+1 for #17

adrianodias’s picture

+1 for #17

Drupal 9.4.1
yearonly 9.0.0

joseph-dickson’s picture

Version: 8.x-1.3 » 9.0.0

+1 for #17
Drupal 9.4.2
yearonly 9.0.0

I've applied #17 using the 'cweagans/composer-patches' composer.json patching method.

gist available at https://gist.github.com/josephdickson/5178979b3b67c3cc14c84f3ff33746de

joseph-dickson’s picture

Version: 9.0.0 » 8.x-1.3
joaomfantunes’s picture

+1 for #17

justcaldwell’s picture

Version: 8.x-1.3 » 9.0.x-dev

New co-maintainer here 👋. Moving to the 9.x branch, as all new development/fixes will occur there. Thanks!

jungle’s picture

Status: Reviewed & tested by the community » Needs review

#11 RTBC'ed #4 but I don't think #4 should be RTBC'ed. And #17 does resolve the issue, but I do not think it's the right way.

#14: #4 patch did not apply for me with latest 8.x release, but #7 did and fixed the issue once I ran updb.

#16: #7 fixes $info['tokens']['term-field_year']['value'] warning that #4 did not.

I still think #7 is the right fix with the confirmation from #14 and #16, thanks!

jungle’s picture

Implement foo_token_info_alter() to alter the tokens provided by module foo itself, which is weird and does not make sense at all.

jungle’s picture

Title: Tokens or token types missing name property » Incomplete filed type definition caused tokens or token types missing name property
justcaldwell’s picture

Assigned: Unassigned » justcaldwell

Hi @jungle. Yeah, I was just looking at this, and I tend to agree that your solution (#7) is likely the way to go. I'm going to do a bit more testing. Thanks for the additional feedback!

  • justcaldwell committed f372fbe on 9.0.x
    Issue #2951779 by jungle, waverate, AlvaroDeMendoza, ronaldmulero,...
justcaldwell’s picture

Title: Incomplete filed type definition caused tokens or token types missing name property » Incomplete field type definition caused tokens or token types missing name property
Assigned: justcaldwell » Unassigned
Status: Needs review » Fixed

I committed #7 to the 9.x-dev branch because:

  1. The field definition updated is needed regardless of the token warnings.
  2. #4 works for nodes only.
  3. #17 doesn't work for taxonomy terms.
  4. In my testing, #7 resolves the token warning for all entity types.

Please test with the dev branch if you are able. Be sure to run updates (drush updb)! 😀

justcaldwell’s picture

justcaldwell’s picture

Updating credit. Thanks to everyone for pushing this forward.

jungle’s picture

Thanks @justcaldwell for reviewing and committing!

justcaldwell’s picture

Included in 9.1.0 release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.