Problem/Motivation

If I
create three entity types of Email (easy_email), Customer and Organisation
the Email entity type has an entity reference field to the Customer entity type
the Customer entity type has a reference field to the Organisation entity type

I should be able to see Organisation filed tokens if the token browser is invoked with:

    $form['customize']['tokens']['tokens'] = [
      '#theme' => 'token_tree_link',
      '#token_types' => ['easy_email'],
      '#show_restricted' => TRUE,
      '#recursion_limit' => 6,
    ];

But this does not work.

Proposed resolution

The problem occurs because of:

      if (empty($token_parents)) {
        // If the parents array is currently empty, assume the token type is its
        // parent.
        $token_parents[] = $token_type;
      }
      elseif (in_array($token, array_slice($token_parents, 1), TRUE)) {
        // Prevent duplicate recursive tokens. For example, this will prevent
        // the tree from generating the following tokens or deeper:
        // [comment:parent:parent]
        // [comment:parent:root:parent]
        continue;
      }

in \Drupal\token\TreeBuilder::getTokenData(). When it is processing the association entity $token will equal entity but we'll already have a parent called entity from the customer entity reference field.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3160735-2.patch713 bytesalexpott
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
713 bytes

Here's a fix - let's see what breaks.

Berdir’s picture

Status: Needs review » Fixed

Committed.

  • Berdir committed 635cbfc on 8.x-1.x authored by alexpott
    Issue #3160735 by alexpott: Nested entity reference fields are not...
Berdir’s picture

Status: Needs review » Fixed

Huh, that bug still exists.

Status: Fixed » Closed (fixed)

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