Field Default Value not working with Entity Reference Fields

Created on 8 November 2016, over 7 years ago
Updated 21 April 2024, about 2 months ago

Hi there! First I wanted to say thank you so much for the port. It is working great for text fields and a few others. I might have missed something but filing this issue for posterity. ^_^

Problem/Motivation

The Field Default Token module is not correctly working for Entity Reference Fields. When you save a token in a field of type entity reference and go back to the field edit screen you will see the token has not been saved. Other fields do not have this problem.

Proposed resolution

In hook_field_config_presave the following logic doesn't seem to work for entity reference fields and the $has_token never gets set to true.

  /** @var \Drupal\field\FieldConfigInterface|\Drupal\Core\Field\FieldConfigInterface $field_config */
  $has_tokens = FALSE;
  foreach ($field_config->getDefaultValueLiteral() as $item) {

The getDefaultValueLiteral doesn't work for entity reference items and returns empty.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada sylus

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024