Problem/Motivation

FieldItemInterface::calculateDependencies() has a parameter FieldDefinitionInterface $field_definition. In EntityReferenceItem, the implementation uses $field_definition->default_value, which only exists on FieldConfigBase. When calling the method with e.g. a BaseFieldDefinition object as parameter, a PHP notice is thrown. I want to do this in #2478507: Schema configs missing dependencies to property and processor providers (collect) where configured field definitions may have been normalized and then denormalized to BaseFieldDefinition objects.

I was going to suggest to use the method getDefaultValue(), but it takes a mandatory $entity parameter. ERItem is bypassing the API here in a way, and for a reason, that are not yet clear to me. It is introduced here: #2271419-34: Allow field types, widgets, formatters to specify config dependencies

Proposed resolution

Add an isset() before using default_value.
Maybe document the API deviation.

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#2 2479257-2-entityreferenceitem.patch1.04 KBtachiinii
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jfarry’s picture

Working on this at the DrupalCon sprints :)

tachiinii’s picture

Patch adds isset() to test for $field_definition->default_value. From DrupalConLA Sprints

RavindraSingh’s picture

Status: Active » Needs review
ericski’s picture

Status: Needs review » Reviewed & tested by the community

Patch completes the requirements and applies cleanly.

Does not mention the API deviation.

jibran’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Can we please add tests for this?

gutagomez’s picture

I going to work on the test following next documentation https://www.drupal.org/contributor-tasks/write-tests

I'm on Barcelona DrupalCon mentoring sprint.

jibran’s picture

yched’s picture

Status: Needs work » Closed (duplicate)

That issue got fixed as part of #2529034: Replace direct access to FieldConfigBase::default_value with methods, which made the property protected, and added a public getDefaultValueLiteral() method to FieldDefinitionInterface