Needs work
Project:
Drupal core
Version:
main
Component:
field system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
28 Sep 2014 at 14:39 UTC
Updated:
1 Jul 2025 at 16:16 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
effulgentsia commentedI don't know how much of this qualifies as critical, but setting it as such for now, because this seems like too much fragility for something as fundamental as the site's data model.
Comment #2
berdirI've closed #2225961: Introduce "controlled" setters on FieldDefinitionInterface to avoid special-casing FieldDefinition and #2143297: setters on FieldDefinitionInterface as a duplicate of that this, they might have information that could be relevant.
Comment #3
effulgentsia commentedComment #4
xjmDiscussed with @effulgentsia and @alexpott. This is definitely buggy (@effulgentsia pointed out that we have an invalid code example for
hook_entity_base_field_info_alter()in entity.api.php even), but the actual functional failures are likely edgecases that have workarounds, so this shouldn't block the release of Drupal 8.0.0.Comment #5
heddnThis is still a major issue for all the reasons in #4. But it needs a beta eval and some architectural insight.
Also tagging as related: #2225961: Introduce "controlled" setters on FieldDefinitionInterface to avoid special-casing FieldDefinition
Comment #6
heddnComment #7
heddnComment #8
chx commentedhttp://drupal.stackexchange.com/questions/156999/creating-account-type-w...
Comment #9
tim.plunkettWe still have in-code @todos pointing to #2225961: Introduce "controlled" setters on FieldDefinitionInterface to avoid special-casing FieldDefinition, which is marked as a dupe of this. Just FYI.
Comment #10
dawehnerCan't you copy an existing one and recreate one?
Comment #11
chx commentedFor that we would need something like a toArray that you can pass to a factory to facilitate an easier copying.
Comment #15
tstoecklerDiscussed this today with @xjm, @plach, @amateescu and @Berdir and we agreed to downgrade this. There is no functional bug that has been pointed out here, nothing that is actually known not to work, neither in core or in contrib. So we should definitely fix this in some way, but the objects that you get passed do actually have various methods that you need, it's just not typehinted.
We also explicitly agreed that this would be re-raised to major if someone can point out a case where something is being passed that actually does not have the proper methods that you need.
Oh, I think this no longer needs a beta evaluation, by the way ;-)
Comment #16
tstoecklerComment #18
avpadernoComment #19
avpadernoComment #21
sam152 commentedThese kind of issues are quite complex to unpick, I think it would almost be worth dealing with them in two separate issues. Trying to tackle base fields first.
Reading over the implementation of
EntityFieldManager::buildBaseFieldDefinitions, things happen in roughly this order:$entity_class::baseFieldDefinitionsis invoked to get the initial list of fields (this hintsFieldDefinitionInterface).entity_base_field_infois invoked (also hintsFieldDefinitionInterface).entity_base_field_info_alteris invoked (also hintsFieldDefinitionInterface).Here is my analysis of what the current state of this issue is:
FieldDefinitionInterface, it doesn't assumeBaseFieldDefinitionoutside of a bug in some documentation.BaseFieldDefinitionbecause that's what everything uses at the moment.FieldDefinitionInterfacethat had no setters, except that alter hook implementations would be left scratching their head.I don't believe any of the alter hooks are any less useful hinting
FieldDefinitionInterfaceinterface. You are still completely able to replace the implementation of a field using setters in an API way like so:Perhaps the issue should be to fix all documentation to make it clear an implementation of
FieldDefinitionInterfaceis the ONLY thing required to define a base field and that the interface is what should be expected during alterations.BaseFieldDefinition::createFromFieldStorageDefinitionexists as a helper to create base fields from storage definitions. Perhaps we could create the same thing forFieldDefinitionInterface. However, given how there aren't many concrete examples of people actually using this flexibility, it might not be worth it.The "special casing" in
EntityFieldManagerseems like it's mostly providing some defaults to BaseFieldDefinitions. I think that's a good enough reason by itself to add setters to the interface, given I don't think it's known yet that an alternative implementation would require such defaults in the first place.Comment #22
sam152 commentedSo here is a proof of concept for essentially a "wont fix" approach.
The alternative I see is extra setters on
FieldDefinitionInterfacebut that could possibly compromise the flexibility of fields coming from a source this is completely immutable. A field definition could start its life out as an instance ofCantBeChangedFieldDefinitionand something could replace it with an instance ofFancyMutableBaseFieldand while they are both implementingFieldDefinitionInterface(and other code expects this), things could continue to work.This is the part of the patch which I think best addresses the concerns which raised this issue in the first place, that is adding special casing for
BaseFieldDefinitioneverywhere.Instead of seeing the special casing as a required part of base fields, it'd essentially become a helper for that one type of implementation.
Comment #26
barrapontoRe-rolling #22, fixes a couple of test failures by properly updating $fields array in
language_entity_base_field_info_alter.Also fixes
BaseFieldDefinition::createFromFieldDefinitionto only use methods available inFieldDefinitionInterface.Comment #29
avpadernoComment #30
hash6 commentedComment #31
xjmI think this would be a minor-only change. Since 8.9.x and 9.0.x are now in beta, I'm moving this to 9.1.x. Thanks!
Comment #32
kishor_kolekar commentedI've re-rolled patch for 9.1
Comment #35
avpadernoThe patch failed for Drupal 9.2.x because an unused
usestatement in /core/modules/language/language.module, which hasn't be changed from the patch.Comment #36
joachim commentedThanks for the analysis! Tagging as novice as it sounds like a simple thing to deal with.
Comment #37
suresh prabhu parkala commentedRe-roll against 9.2.x. Please review.
Comment #38
avpaderno@Suresh We need a patch for Drupal 9.3.x.
Comment #39
karishmaamin commentedRe-rolled patch for Drupal 9.3.x.
Comment #40
daffie commentedMissing the parameter in the docblock.
This new method is not used in core anywhere. At least we should add some testing for it.
Comment #44
nikhil_110 commentedAttached patch against Drupal 10.1.x
Comment #46
spadxiii commentedrerolled against 9.5.x
Comment #49
solideogloria commentedI converted patch #44 to a merge request and rerolled against 11.x
Note that from @daffie in #40, a test still needs to be added for the newly added
BaseFieldDefinition::createFromFieldDefinition(the wrong function was referenced in the comment above, ascreateFromFieldStorageDefinitionis actually used in core)Comment #50
solideogloria commentedComment #53
xjmAdding credits from @tstoeckler's triage credit in #15.
Comment #55
xjmAnd adding credit from the triage in #4.