Problem/Motivation

The tokens undefined object error shows up on the entity page that provides a field of type languagefield.

Notice: Trying to get property 'value' of non-object in languagefield_tokens() (line 120 of ../languagefield/languagefield.tokens.inc).

Steps to reproduce

  1. Add a field of type languagefield for a node with field setting allowing the user to choose languages from what's installed on the site already.
  2. Create a node and choose some language for the field of type languagefield and publish the node .
  3. View the node page and you will see the error as above

Comments

fathima.asmat created an issue. See original summary.

fathima.asmat’s picture

Patch attached.

fathima.asmat’s picture

Status: Active » Needs review
indrapatil’s picture

@fathima.asmat could please add the steps on how to test in the issue summary?
Thank you.

fathima.asmat’s picture

Issue summary: View changes
johnv’s picture

I cannot reproduce the problem.

I guess you have also installed Token module, and some module to add tokens in the view mode, like Automatic Entity Labels?

  • johnv committed 94ffa074 on 8.x-1.x authored by fathima.asmat
    Issue #3347251 by fathima.asmat: Undefined object error from tokens.inc
    
johnv’s picture

Hmm,
I have committed the patch, since it does not hurt.
But there must be something else wrong in your installation. The same code is used in other fields for Token support.
You state it happens with new node, after adding the new field.
Please check if you are not mixing [node:field_language:langcode] and [node:language:langcode]

fathima.asmat’s picture

Thanks @johnv for merging the fix.

I guess you have also installed Token module, and some module to add tokens in the view mode, like Automatic Entity Labels?

If this is the case, shouldn't the module declare the token and the other contrib module as dependencies from the info file and install them as well during the module installation?

The following bit of code checks the token module service to grab the token type and if not available the module skips from setting up the tokens from the token_info hook.

 $token_type = \Drupal::service('token.entity_mapper')->getTokenTypeForEntityType($entity_type_id);
    if (empty($token_type)) {
      continue;
    }

This seems like token is a strict dependency for this module, hence should be defined in info.yml as a dependency, perhaps this needs to be created as a separate issue?

johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.9
Status: Needs review » Fixed

Token module is not required for this module to work properly.
It is/was however my impression that the hook_tokens was only called by the Token module (Which is not, it is a core hook: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Utility%2... )

I still cannot reproduce your problem.
Upon saving and displaying a node, you need some extra step in the test script in order to make it reproducable.
It seems you installation is requesting for delta values that do not exist.
What is the cardinality of your field?

Status: Fixed » Closed (fixed)

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