Follow up from #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields. That issue introduces the ability to have config-based overrides of base fields via 'base_field_override' config entities. However, it retains HEAD's prior ability to also have code-based overrides via ContentEntityInterface::bundleFieldDefinitions(). If both approaches get used on the same base field for the same bundle, various problems can arise (see comments #142-#146 of that issue). So, to ensure robustness, let's either explicitly remove support for that (i.e., throw an exception when someone tries to add a config-based override of a code-overridden field), or else if we think it's important to support this possibility, then add tests for it and fix what we find.
Comments
Comment #1
effulgentsia commentedComment #2
fagoFrom #2283977-152: Create a new ConfigEntity type for storing bundle-specific customizations of base fields:
So, actually the implemenation could be easily improved to handle all fields by using getStorageFieldDefinition() instead of getBaseFieldDefinitions() to fetch the storage field. Given that, I'd actually agree with effulgentsia that the config (+ entity type) should be
core.field_override.*.ymlthen. I don't think the possible confusion around overriding field instances with config is not an issue - technically, you could do it, but there is no point in overriding a config field with config, so that's why we don't ;-)So depending on what we decide here, we might want to this rename or not. But anyway, I think we shoud have this clarified before beta.
Comment #3
fago@topic:
We've got one usage of code based bundle field overrides left in core after [#9058387]: comment module. It could be moved to config by generating the config overridde upon bundle creation. That's a bit more work to do and maybe not so easy to follow as now, but it should work fine.
Personally, I think it makes sense to keep code-based bundle field overrides for the following reasons:
When keeping it I think we should:
BaseFieldOverridetoFieldOverrideConfigandcore.field_override.*.yml+ remove its coupling to base fields.BaseFieldOverrideclass for code based overrides, which internally can defer to the real base field object and thus has an improved memory footprint.Comment #4
fagoI gave this more thought on whether this is really necessary or it makes sense to work on simplifying things more.
We could achieve that as well by making sure BaseFieldOverrides and FieldInstanceConfigs support varying display configurability setting as well, what means bringing at least default-display settings back to the field instance config (API only). That way, modules could create field instances and or overrides with full display configurability flexibility.
I think for base field overrides that makes much sense anyway, for field instances it depends on whether we have code fields as alternative.
Thinking more about possible use-cases for code fields, I came up with another one:
Comment #5
tstoecklerFirst off, sorry for being a bit late to the party...
I (re-)read this issue as well as (re-)reading most of #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields as well the committed patch.
As I didn't get involved with that issue I'm aware that I can't complain about how it turned out, but since this issue is very much based on that, there's no around taking it into account.
Some background:
I am very adament about our current ability to provide code-based (base) fields via
ContentEntityInterface::baseFieldDefinitions(). Additionally, I very much like the pattern offield.modulenot participating at all in the architectural decisions of the concept but instead simply adding its storage fields inhook_entity_field_storage_info().*I think that pattern is something that we should utilize for more of the Entity API and I think it can perfectly address the problem of this issue and #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields, as well.
The problem with #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields:
#2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields raised one issue with our current base-field/bundle-field architecture but instead of fixing at its root, it implemented a workaround, in my opinion.
The root problem, which was also discussed there, is that bundle fields are (and after #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields mostly were) used for two different things:
field.moduledid to add itsFieldInstanceConfig. To be able to add fields for a specific bundle and being able to store the data somewhere, the concept of storage fields had to be invented.We already had a pattern for the different steps that would happen during the collection of base/storage/bundle fields. That is why I do not understand why we did not implement that in the usual way. The precedent we already had for content entities was:
baseFieldDefinitions()and then extended by a hook (hook_entity_(base_)field_(storage_)info())bundleFieldDefinitions()and then extended by a hook (hook_entity_bundle_field_info())So if we realize we need to introduce a third logical step the most logical thing to do, in my opinion, would have been: 1. Introduce a new method for entity types to provide bundle-specific overrides of base fields. For example
Node'sbundleFieldDefinitions()would be moved to this method. 2. Introduce a new hook so that modules can extend these overrides.content_translation.modulecould then use that hook to override translatability of base fields on a bundle level.Some additional notes:
Nodedoes) vs. how it was before #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields without having to introduce any workarounds (note: the fact #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields introduced workarounds is not my opinion but a fact. See the changes toNodeTypeFormthat issue introduced if you do not believe me)As this approach is the most consistent with our current architecture I think it would be the best for DX (in addition to the DX gain mentioned above). The code that #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields introduced to
EntityManageris just alien to that class when looking at how any other types of fields are collected.* Yes, I know that base field != storage field. Proceed. :-)
Comment #6
alexpottCan be active
Comment #7
catchThe tests/fixes part of this needs to happen after beta if the 'remove support for' doesn't - so only half the issue is beta deadline I guess.
Comment #8
effulgentsia commentedI think what ended up landing works, and even has a test, but don't know if there's enough coverage for various events that can happen along the way.
Comment #22
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #23
smustgrave commentedWanted to bump this one more time.
Comment #24
smustgrave commentedDon't feel comfortable closing so will put back into active.