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
Comment | File | Size | Author |
---|---|---|---|
#2 | 2479257-2-entityreferenceitem.patch | 1.04 KB | tachiinii |
Comments
Comment #1
jfarry CreditAttribution: jfarry commentedWorking on this at the DrupalCon sprints :)
Comment #2
tachiinii CreditAttribution: tachiinii as a volunteer commentedPatch adds isset() to test for $field_definition->default_value. From DrupalConLA Sprints
Comment #3
RavindraSingh CreditAttribution: RavindraSingh at Srijan | A Material+ Company commentedComment #4
ericski CreditAttribution: ericski as a volunteer commentedPatch completes the requirements and applies cleanly.
Does not mention the API deviation.
Comment #5
jibranCan we please add tests for this?
Comment #6
gutagomez CreditAttribution: gutagomez as a volunteer commentedI going to work on the test following next documentation https://www.drupal.org/contributor-tasks/write-tests
I'm on Barcelona DrupalCon mentoring sprint.
Comment #7
jibranComment #8
yched CreditAttribution: yched commentedThat 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