Hello,

I found this while using another module that requires Entity Reference Quantity, but after testing I can confirm this error is occurring on this module.

When you create an entity reference field with quantity, the token :quantity for the field doesn't have a name, and the following warning message is displayed on Status Report page:

TOKENS OR TOKEN TYPES MISSING NAME PROPERTY

As you can see on attached screenshots, the referencing field does have tokens associated to it, but Quantity is missing name. This is happening for fields on content types and taxonomy terms - I didn't test it for other entity types.

I'm not sure if this token must be assigned on field creation or if some sort of hook_token_info_alter could solve that.

Regards,

Mauricio M. Silveira

Comments

maursilveira created an issue. See original summary.

waverate’s picture

Status: Active » Needs review
StatusFileSize
new1.02 KB

Patch attached.

szecsodimlaszlo’s picture

I have the same problem as the OP.
And there is a related – now Closed (duplicate) – issue @Basic cart:
#2908116 - Token status report warning after Drupal core upgrade

#2 patch seems NOT solve the problem.

After patching I have got these two error messages:

  1. Tokens or token types missing name property: $info['tokens']['node-basic_cart_content']['quantity']
  2. The following token types are not defined but have tokens: $info['types']['basic_cart_order']
waverate’s picture

@szecsodimlaszlo. This issue and patch is for the Entity Reference Quantity module. Is this the module you are having problems with or is it the Basic Cart module?

szecsodimlaszlo’s picture

@waverate, Basic Cart depends on Entity Reference Quantity. I am not 100% sure which one causes the errors. I haven't used either of them before.

Although, the first line of @maursilveira's second image shows me that he/she had the same error adding an Entity reference w/quantity by Basic Cart:

Tokens or token types missing name property: $info['tokens']['node-basic_cart_content']['quantity']

I got the same error that is why I guess it is caused by Entity Reference Quantity. I may be wrong.

(...)

Now, for testing purposes, I added a test field of Entity reference w/quantity field type to my Basic page content type. I got this error message on Status Report:

Tokens or token types missing name property:

  • $info['tokens']['node-field_test']['quantity']
  • $info['tokens']['node-basic_cart_content']['quantity']

Drupal version: 8.7.2
Entity Reference Quantity: 8.x-1.x-dev with the patch #2

--

Examining again, the second error message I wrote above is probably not related to Entity Reference Quantity.

waverate’s picture

Okay. I didn't realize the Basic Cart module required Entity Reference Quantity.

The patch at #2 is automatically creating the tokens for any entity_type=node and field_type=entity_reference_quantity. In essence that is saying, if you have any Content Type and added an Entity Reference Quantity field to it; this patch should take care of creating the missing tokens ['quantity'] regardless of what you named the field.

1. Can you check the Status Report before and after the patch at #2? Let me know the error messages in each case.

2. I expect we should be able to fix the missing quantity tokens in this issue.

3. Once we complete item 2, we may need to fix $info['types']['basic_cart_order'] in #2908116: Token status report warning after Drupal core upgrade.

szecsodimlaszlo’s picture

@waverate, I went back to a backup, reinstalled Basic Cart with its dependencies (Easy Install, Entity Reference Quantity, Telephone). It doesn't matter whether I use the above patch or not, I got the same error message on the Status Report:

Tokens or token types missing name property: $info['tokens']['node-basic_cart_content']['quantity']

The patched entity_reference_quantity.module:

<?php

/**
 * @file
 * Contains entity_reference_quantity.module..
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function entity_reference_quantity_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the entity_reference_quantity module.
    case 'help.page.entity_reference_quantity':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Entity reference field with quantity') . '</p>';
      return $output;

    default:
  }
}

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

function entity_reference_quantity_token_info_alter(&$info) {
  $entities = \Drupal::service('entity_field.manager')->getFieldMap();
  foreach ($entities as $entity_key => $entity) {
    if ($entity_key !== 'node') {
      continue;
    }

    foreach ($entity as $field_key => $field) {
      if ($field['type'] !== 'entity_reference_quantity' ) {
        continue;
      }

      $token_key = sprintf('node-%s', $field_key);
      $info['tokens'][$token_key]['quantity'] = [
        'name' => t('Quantity Value'),
        'description' => t('The quantity value.'),
      ];
    }
  }
}
waverate’s picture

Status: Needs review » Needs work
szecsodimlaszlo’s picture

StatusFileSize
new28.05 KB

@waverate, it seems to me that [node:basic_cart_content] is an array or what. It may help.
tokens

waverate’s picture

I would have expected this to work:

/**
 * Implements hook_token_info_alter().
 */

function entity_reference_quantity_token_info_alter(&$info) {
  $info['tokens']['node-basic_cart_content']['quantity'] = [
    'name' => t('Basic Cart: Quantity Value'),
    'description' => t('The Basic Cart quantity value.'),
  ];
}
szecsodimlaszlo’s picture

@waverate, the code #10 is not working.

I checked your patch before. It does what we both expected. When I printed out the $info, I got this:

drupal_set_message($token_key . ': ' . $info['tokens'][$token_key]['quantity']['name']);

node-basic_cart_content: Quantity Value

waverate’s picture

Well, that’s what patch at #2 is supposed to do. #stumped.

szecsodimlaszlo’s picture

@waverate, I went back to a backup and reinstalled Basic Cart with its dependencies again. Without selecting any of the content types for which I can have the "Add to cart" option of Basic Cart, I checked the field types in the foreach ($entity as $field_key => $field) loop in your patch. I realized that there is no entity_reference_quantity field type in this case while there is the error message on Status Report.

My conclusion is that this issue cannot be solved in the entity_reference_quantity_token_info_alter hook. The error must be generated earlier on the chain.

What do you think?

waverate’s picture

To help troubleshoot this, you may want to use the Entity Reference Quantity module on its own instead of with Basic Cart. The missing tokens message occurs after the module is enabled and an Entity Reference Quantity field is added to a Content Type.

chucksimply’s picture

I've also installed the latest patch. Using Entity Reference Quantity on it's own (without basic cart).

And I'm still getting the same warning on the status report page...

Tokens or token types missing name property
$info['tokens']['node-field_species_count']['quantity']

Any updates on this patch?

t1d’s picture

StatusFileSize
new763 bytes

Hello,
I figured out that the propertyDefinitions were setting the Label as something that is NULL.
It doesn't seem to take the value defined in the field basic_cart_content of the node type basic_cart_order.

I looked in the other modules, a translatable element is defined in place of that.

Here is my patch. I don't know if it is really a problem, if you have renamed this field, but for me it fixes the issue.

hs@henrikstrindberg.se’s picture

The patch #16 worked for me.
The error message is gone ("Tokens or token types missing name property
$info['tokens']['node-basic_cart_content']['quantity'])

Thanks

chucksimply’s picture

Status: Needs work » Reviewed & tested by the community

#16 fixes the issue for me. Thanks!

  • l0ke committed c99f59c2 on 8.x-2.x
    Issue #3019432 by t1d: Quantity token missing name property' --author="...

  • l0ke committed 0f651620 on 8.x-2.x
    Issue #3019432 by t1d, l0ke: Quantity token missing name property
l0ke’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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