Updated: Comment #0

Problem/Motivation

In #2143069: Add getProvider() and hasCustomStorage to FieldDefinitionInterface we introduced yet another place where we check whether our field definition extends FieldDefinition, in this case to avoid the need of adding a setter on the FieldDefinitionInterface. This is problematic because right now our system is working correctly only for configurable fields and classes extending FieldDefinition, any other class implementing the interface is SOL. In this particular case the latter would not get their provider key populated, which may lead to all sort of broken behaviors.

Proposed resolution

Add the required setters on the FieldDefinitionInterface, remove the FieldDefinition checks, and provide an implementation in Field(Instance)Config that will throw an exception if a value differing from the expected/hard-coded value is passed.

Remaining tasks

  • Find consensus on the solution
  • Write a patch

User interface changes

None

API changes

None, just an API addition.

Comments

plach’s picture

This could be even considered a bug report actually.

fago’s picture

Having an interface means people are free to use their own field definition classes if they really want to - but for that to work out the entity manager needs to set some basic stuff for them as well. Thus, I could see us adding only those setters used by manager to the interface + throw exception if someone tries to use them to set something other than the hard-coded value on configurable fields?

plach’s picture

Issue summary: View changes
plach’s picture

Issue summary: View changes
tstoeckler’s picture

Yes, I actually did not at all understand what the problem with adding those methods on the interface is.

I have nothing against throwing exceptions in addition to that, where it makes sense.

YesCT’s picture

Priority: Normal » Critical
Issue tags: +EntityField API

The critical #2143291: Clarify handling of field translatability is postponed on this. I think that makes this critical.

Also tagging. Not sure what other tags this might need.

plach’s picture

Currently the only places where we are checking FieldDefinitions are EntityManager and (guess who) Content Translation. If we fix the former, as per #2, we need to add the following setters:

  • setProvider()
  • setName()
  • setTargetEntityTypeId()

If we want to fix also the CT case we need to add also the (guess what) setTranslatable() method. I have the feeling that in this case the logic behind what gets a setter becomes quite arbitrary, OTOH we really need that setter to properly fix #2143291: Clarify handling of field translatability. Maybe we should just add a setter for each property, unless there's a hard reason to make it read-only?

The main problem with CT is that it was designed to work with definition arrays, which are natively mutable, objects broke this assumption badly unfortunately, as now field definitions are no longer alterable in a strict sense. At least not reliably alterable.

plach’s picture

Assigned: Unassigned » fago
Issue tags: +Needs architectural review
plach’s picture

larowlan’s picture

Berdir’s picture

Status: Active » Closed (duplicate)

Duplicate of #2346329: hook_entity_base_field_info_alter() and hook_entity_bundle_field_info_alter() are documented to get a parameter that doesn't implement an interface with setter methods I think. This has more info, but the other is based on a discussion that we had today and reflects the latest plans.

I've also already closed #2143297: setters on FieldDefinitionInterface as a duplicate of that one.

fago’s picture

Assigned: fago » Unassigned
heddn’s picture