- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Running into this over at #3324140-22: Convert field_storage_config and field_config's form validation logic to validation constraints → .
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
And TIL I was pinged to review/provide feedback on https://git.drupalcode.org/project/drupal/-/merge_requests/3926#note_189783 2 days ago, and that happens to run into exactly this problem space, but not
\Drupal\field\Entity\FieldConfig::preSave()
specifically:field_field_config_presave()
is doing things that are critical for certainFieldConfig
entities (those that are for Entity Reference fields) to be correct/saveable.Increasing priority.
- First commit to issue fork.
- last update
over 1 year ago Custom Commands Failed - @lauriii opened merge request.
- 🇫🇮Finland lauriii Finland
Committed a version of the patch that doesn't lead into WSOD to see how many test fails it causes. I expect there will be a lot of test fails because normalizing the config in preSave could be the expected behavior.
- last update
over 1 year ago Build Successful - First commit to issue fork.
- last update
over 1 year ago Build Successful - 🇺🇸United States phenaproxima Massachusetts
Hiding patches in favor of the merge request.
- last update
over 1 year ago 29,662 pass, 150 fail - last update
over 1 year ago 29,662 pass, 150 fail - last update
over 1 year ago 29,684 pass, 140 fail - last update
over 1 year ago 29,691 pass, 136 fail - last update
over 1 year ago 29,722 pass, 126 fail - last update
over 1 year ago 29,725 pass, 122 fail - last update
over 1 year ago 29,755 pass, 82 fail - last update
over 1 year ago 29,805 pass, 2 fail - last update
over 1 year ago 29,805 pass, 2 fail - last update
over 1 year ago 29,809 pass, 1 fail - last update
over 1 year ago 29,806 pass, 2 fail - last update
over 1 year ago 29,819 pass - 🇺🇸United States phenaproxima Massachusetts
I watched with increasing bafflement as @lauriii and @catch got into the weeds discussing this issue's backwards compatibility concerns on Slack. After that, I finally Zoomed with @lauriii to get the executive summary and understand it for myself.
The plan is this: we want the calling code to be responsible for merging the default settings into FieldConfigStorage::$settings (and its counterparts in BaseFieldOverride and FieldConfig). postCreate() will do this for you when it creates a new entity (by calling the $this->initSettings() method). In other situations, you need to do it yourself, and preSave() will check your homework -- $this->settings must contain every key in the default settings, or you'll get a deprecation notice (and maybe, in Drupal 11, an exception). postLoad()'s behavior will be unchanged.
- last update
over 1 year ago 29,718 pass, 10 fail - last update
over 1 year ago 29,728 pass, 9 fail - 🇧🇪Belgium borisson_ Mechelen, 🇧🇪
Left a couple of comments on the MR, the remaining fails are all because of the new deprecation. Do we solve those in this issue as well?
- Assigned to phenaproxima
- 🇺🇸United States phenaproxima Massachusetts
Assigning to myself to fix the tests and find out which code paths are triggering these deprecations.
- last update
over 1 year ago 29,826 pass - Issue was unassigned.
- Status changed to Needs review
over 1 year ago 4:39pm 20 July 2023 - last update
over 1 year ago 29,826 pass - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,642 pass, 51 fail - last update
over 1 year ago 29,639 pass, 52 fail - 🇨🇭Switzerland berdir Switzerland
Did a review. issue summary definitely needs an update.
What I don't quit understand is why we plan to enforce that settings are passed in, we have the default settings, we can complete them, why not keeping doing that? That's how plugins work as well (19 instances of
$this->configuration = $configuration + $this->defaultConfiguration();
in core, I think a ConfigurablePluginBase would be neat ;))IMHO, this is going to hurt us down the line. This would make adding a new setting to a field type plugin a BC break as all existing code who creates fields of that type is going to break.
Less sure about invalid settings, I can see how that's more sensible to enforce, but we would have the same problem then if we remove a setting from a field type, then that's suddenly invalid too.
- Status changed to Needs work
over 1 year ago 4:40pm 21 July 2023 - 🇺🇸United States smustgrave
#43 mentioned an issue summary update.
And number of test failures in MR.
- last update
over 1 year ago 29,759 pass, 40 fail - last update
over 1 year ago 29,777 pass, 30 fail - last update
over 1 year ago 29,820 pass, 23 fail - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,878 pass - Status changed to Needs review
over 1 year ago 6:15pm 24 July 2023 - 🇺🇸United States phenaproxima Massachusetts
Updating the issue summary with the proposed resolution. I'm also tagging this for a change record, which I'm pretty sure will be needed.
- last update
over 1 year ago 29,877 pass - 🇫🇮Finland lauriii Finland
There's one more soft blocker to 📌 Save FieldStorageConfig at the same time as FieldConfig Fixed related to invalid config which should be resolved either by this issue or a follow-up. The
field_field_config_presave
normalizes the selection handle plugin IDs and we need to manually duplicate that so that we can run it earlier. Thoughts on whether we should address that here or in a follow-up issue? - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,819 pass, 34 fail - last update
over 1 year ago 29,879 pass - 🇺🇸United States phenaproxima Massachusetts
Re #48, I think we should do this in a follow-up. As you can see, I did a little experimentation around this but it seems rather tricky, and I'm not sure that experimental approach was the right one anyway.
- Status changed to Needs work
over 1 year ago 1:03pm 26 July 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
First: AWESOME progress here! 🤩
Thanks for #39, that's really crucial context wrt BC concerns and release manager guidance! Linking it from the issue summary 👍 Makes sense that we don't want to modify
postLoad()
at all in particular, because that would have the biggest BC (runtime) impact.I have to agree with @Berdir in #43: that simple approach seems preferable and less disruptive. But AFAICT since then, that was largely adopted. In reviewing this, I did spot a few more BC concerns though. 😅 Or at least, potential ones — hopefully you can show why none of them are actual BC concerns! 😄
Regarding @lauriii's remark in #48: I think that if we're making the behavior of
Field(Storage)Config
's creation/saving logic sane & centralized, that it makes sense to considerfield_field_config_presave()
in scope too — it's touching the same problem space. - last update
over 1 year ago 29,879 pass - last update
over 1 year ago 29,879 pass - Assigned to wim leers
- Status changed to Needs review
over 1 year ago 3:49pm 26 July 2023 - 🇺🇸United States phenaproxima Massachusetts
Reassigning to Wim for another round of review.
- last update
over 1 year ago 29,885 pass - last update
over 1 year ago 29,885 pass - last update
over 1 year ago 29,840 pass, 27 fail - last update
over 1 year ago 29,724 pass, 73 fail - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,840 pass, 27 fail - last update
over 1 year ago 29,880 pass, 2 fail - Assigned to phenaproxima
- Status changed to Needs work
over 1 year ago 11:33am 28 July 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
This feels much closer now thanks to your work on
FieldConfigBase::set('settings', …)
! It allows us to revert a LOT of changes.I see that you commented many times that that was impossible, but … I think you wrote those comments before you did that work? 😅 In my spot testing, it sure does work every single time!
- last update
over 1 year ago 29,881 pass, 2 fail - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Also figured out why there was a weird deprecation-testing-related test failure. The root cause is simple: thanks to the excellent work you did on
FieldConfigBase::set('settings', …)
, the deprecation errorSaving a field_config with incomplete settings is deprecated in drupal:10.2.0 and will throw an exception in drupal:11.0.0. Adjust your code to ensure that all supported settings are provided. See https://drupal.org/node/3375334.
simply cannot ever occur anymore! 😅
6:12 5:55 Running- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Before this can be RTBC'd, this definitely needs an issue summary update.
Also, thanks to
FieldConfigBase::set('settings', …)
, I think the CR needs to be updated? 🤓 - last update
over 1 year ago 29,785 pass, 13 fail - last update
over 1 year ago 29,785 pass, 13 fail - last update
over 1 year ago 29,872 pass, 3 fail - last update
over 1 year ago 29,886 pass - last update
over 1 year ago 29,886 pass - Assigned to wim leers
- Status changed to Needs review
over 1 year ago 6:06pm 28 July 2023 - last update
over 1 year ago 29,886 pass - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago CI aborted - last update
over 1 year ago 29,908 pass - last update
over 1 year ago 29,908 pass 57:19 53:10 Running- last update
over 1 year ago CI error - last update
over 1 year ago CI error - last update
over 1 year ago 29,907 pass, 1 fail - last update
over 1 year ago 29,907 pass, 1 fail - last update
over 1 year ago 29,907 pass, 1 fail - 🇺🇸United States phenaproxima Massachusetts
Do we still need a follow-up here?
I ask because...as far as I can tell, it's no longer possible to put incomplete settings on a field or field storage config entity, unless you use reflection. So rather than deprecate, we can just throw an exception.
- last update
over 1 year ago 29,911 pass - last update
over 1 year ago 29,911 pass - Assigned to phenaproxima
- Status changed to Needs work
over 1 year ago 11:25am 1 August 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Looking great!
But in doing a thorough final review, I made one very startling discovery:
\Drupal\Core\Field\FieldItemInterface::fieldSettingsToConfigData()
has existed since 2014 and AFAICT does exactly the same thing as the new\Drupal\Core\Field\FieldItemInterface::normalizeSettings()
we're adding?! 😳 - last update
over 1 year ago 29,912 pass - last update
over 1 year ago 29,904 pass, 1 fail - Assigned to wim leers
- Status changed to Needs review
over 1 year ago 12:04pm 1 August 2023 - Assigned to phenaproxima
- Status changed to Needs work
over 1 year ago 1:33pm 1 August 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
I see a way forward thanks to https://www.drupal.org/node/3376455 → ! 🥳
Also still needs a change record for the migration change.
Those are the only 2 remaining threads 👍
- last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,772 pass, 12 fail - last update
over 1 year ago 29,946 pass - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
This is ready, but still needs change record updates, as well as 2 additional change records (the new interface argument and the modified migration destination). It also still needs a follow-up for the
@todo
that was just added for Drupal 11.Once those things are done … this will be RTBC! 😄🥳
- 🇺🇸United States phenaproxima Massachusetts
Okay, the change records have been added/updated.
- last update
over 1 year ago 29,946 pass - Assigned to wim leers
- Status changed to Needs review
over 1 year ago 12:18pm 3 August 2023 - 🇺🇸United States phenaproxima Massachusetts
Opened 📌 [Drupal 11] Require $field_definition to be passed to FieldItemInterface::fieldSettingsToConfigData() Closed: outdated to change the interface method in Drupal 11, and linked to it in the todos.
- Status changed to RTBC
over 1 year ago 1:31pm 3 August 2023 - 🇧🇪Belgium borisson_ Mechelen, 🇧🇪
I have read trough the PR several times, in the hope to find something that was not clear, could use better documentation or can otherwise be improved. I can't seem to find anything.
I also read through the Change Records, those are very clear as well.
I think that means this can go to rtbc, but I would feel more comfortable with one of the field or entity api maintainers +1 here as well. Do we need to tag this as needs subsystem maintainer review? - Status changed to Needs review
over 1 year ago 3:31pm 3 August 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Agreed with @borisson_; tagged 😊
Refined the migration destination CR → , added link to 📌 [Drupal 11] Require $field_definition to be passed to FieldItemInterface::fieldSettingsToConfigData() Closed: outdated to the fieldSettingsToConfigData() CR → .
The third CR (for field config/storage settings) → sounds … a bit like it's breaking quite a lot of things? 😅🙈
So let's see if all those
*Test.php
changes are necessary, by reverting all modified tests. It's easy to get those by comparing to the last upstream commit that was merged in:git checkout 2327883-field-storage-config git pull git diff e72fa7b3759972013c3e943372baaae85722fbfe HEAD -- **/**Test.php
Because if we could show that none of those test changes are necessary, then we simultaneously prove that the risk of disruption/BC break is extremely low. And … unless I made a mistake, every single one of the tests still passes if I revert all test changes! 🤩 The changes were definitely necessary at an earlier iteration of this merge request, but now they're no longer necessary: thanks to
core/lib/Drupal/Core/Field/Entity/CompleteFieldSettingsTrait.php
, and the updates tocore/lib/Drupal/Core/Field/FieldConfigBase.php
and subclasses, everything is guaranteed to be complete, always! 😊The sole exception:
\Drupal\KernelTests\Core\Field\FieldSettingsTest
. But that makes sense: it's literally testing the updated behavior in a unit-like kernel test that checks howField(Storage)Config
entities are created and how their settings are saved 👍 - last update
over 1 year ago 29,947 pass - last update
over 1 year ago 29,947 pass - Issue was unassigned.
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
**Test.php
didn't catch everything. Reverting the changes inFileFieldTestBase.php
andImageFieldCreationTrait
appears to work fine too 🤓Now, to be fair, the code that I reverted in the last 2 commits was:
- actually more accurate, even though unnecessary
- going to be reused in its entirety in 📌 [PP-1] Convert field_storage_config and field_config's form validation logic to validation constraints Postponed or one of its child issues, because then those invalid settings should start triggering validation errors!
But AFAICT this means that the third CR ( https://www.drupal.org/node/3375334 → ) can simply be deleted — or at least associated with 📌 [PP-1] Convert field_storage_config and field_config's form validation logic to validation constraints Postponed instead of this issue! 😊 IOW: none of the work was in vain, but let's keep this issue's scope as tight as possible and hence make it easier to get this issue committed 🤞
This also should make subsystem maintainer review a lot simpler.
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Still green. This is IMHO RTBC now.
I would like explicit confirmation for the 2 commits I pushed from @phenaproxima and @borisson_. After that, we need subsystem maintainer review.
- 🇺🇸United States phenaproxima Massachusetts
I have no objections to Wim's changes. Fewer files touched is good, and indeed, we can delete the third change record -- even nicer!
- 🇧🇪Belgium borisson_ Mechelen, 🇧🇪
Fewer touched files is indeed more better.
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Associated the 3rd CR with #3324140 instead 👍 2 CRs left here.
- Status changed to Needs work
over 1 year ago 11:15am 10 August 2023 - 🇷🇴Romania amateescu
Posted a couple of comments in the MR.
I think a possible solution to the first problem (calling
fieldSettingsToConfigData()
inFieldConfigBase::postCreate()
) is to move the code which sets the handler setting for ER fields fromfield_field_config_presave
to ahook_entity_create()
implementation. - Assigned to phenaproxima
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Thanks, @amateescu! 😊🙏
Assigning to @phenaproxima to address your remarks, but … I did ask 2 clarifying follow-up questions on the MR, and I have one other question for you here: 🤓
[…] move the code which sets the handler setting for ER fields from
field_field_config_presave
to ahook_entity_create()
implementation.It sounds like this means that my discovery/"aha" moment in #59 was wrong? 😅 @phenaproxima was actually first adding a new
FieldItemInterface::normalizeSettings()
method, and then in doing a final review, I discovered::fieldSettingsToConfigData()
, which I'd never heard of before, and it seemed to be doing the exact same thing. - 🇷🇴Romania amateescu
@Wim Leers, unfortunately.. yes :) I learned about
fieldSettingsToConfigData()
from this issue, but then I read the issue where it was introduced and realized that it should only be used prior to saving a field to config.As for a test case about not calling
fieldSettingsToConfigData()
inpostCreate()
, a very good example is\Drupal\options\Plugin\Field\FieldType\ListItemBase::storageSettingsToConfigData()
and\Drupal\options\Plugin\Field\FieldType\ListItemBase::storageSettingsFromConfigData()
, which show how/why a field type might need to have a certain structure for its settings in the runtime object, and a different settings structure when stored in config. - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Okay, great, thank you SO MUCH for confirming that!
Sounds like we should restore the
::normalizeSettings()
approach! 😇 - last update
over 1 year ago 29,955 pass, 1 fail - Assigned to wim leers
- Status changed to Needs review
over 1 year ago 2:27pm 10 August 2023 - last update
over 1 year ago 29,959 pass - Issue was unassigned.
- Status changed to RTBC
over 1 year ago 7:53am 11 August 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
This is ready now, although an explicit confirmation from @amateescu sure would be nice! 😇
- Status changed to Needs review
over 1 year ago 7:58am 11 August 2023 - 🇷🇴Romania amateescu
Sounds like we should restore the
::normalizeSettings()
approach!Is there a problem with the
hook_entity_create()
suggestion for setting the handler setting of ER fields? A hook implementation has the advantage that it can be removed at any time if we refactor the code around selection plugins and their special handling of plugin IDs, while a new method onFieldItemInterface
would take a major release cycles to deprecate and remove. - Assigned to amateescu
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Is there a problem with the
hook_entity_create()
suggestion for setting the handler setting of ER fields? A hook implementation has the advantage […]Yes, there is a significant problem with that: it gets us the same exact problem that
field_field_config_presave()
causes today: modules like https://github.com/jibran/dynamic_entity_reference then have to hack their way around it withhook_module_implements_alter()
because these hooks cause the field's (entity reference selection handler) settings processing to happen at the wrong level!See #33, which points to @larowlan's comments, and most critically, to https://git.drupalcode.org/project/drupal/-/merge_requests/3926#note_194955. See https://git.drupalcode.org/project/dynamic_entity_reference/-/blob/3.1.0....
Basically: while we're touching this code, we might as well make it so that core won't be breaking contrib modules in this way anymore.
- 🇷🇴Romania amateescu
it gets us the same exact problem that field_field_config_presave() causes today: modules like https://github.com/jibran/dynamic_entity_reference then have to hack their way around it
That's very easy to fix though: we can just check if the field type provides a
target_type
storage setting and return early if it doesn't. - Assigned to phenaproxima
- Status changed to Needs work
over 1 year ago 2:03pm 14 August 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
#80: Aha, no, because
target_type
is the only additional key that\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::defaultStorageSettings()
specifies! So yes, then this could totally work, and we avoid increasing the API surface.I think the solution that we had arrived at here is nice & fine. It seems that @larowlan, @jibran, @phenaproxima and I were all fine with it (maybe @lauriii too, not sure). But it does mean expanding the Field API more, and if we can avoid that, that'd be better. It'll also mean a simpler upgrade path from Drupal 10 to 11, which in its own is worth a lot (i.e. no field type implementation changes necessary!).
So: +1 to restoring
field_field_config_presave()
and returning early iftarget_type
is absent from the default storage settings. Thank you for helping keep scope & impact as minimal as possible, @amateescu! 😊🙏🙏🙏 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
After these twists and turns, the IS became outdated again, and we're missing a change record for the solution that @amateescu helped us arrive at. Tagging for both.
- last update
over 1 year ago 29,960 pass - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,959 pass, 1 fail - last update
over 1 year ago 29,960 pass - 🇷🇴Romania amateescu
Thanks for the updates, this looks much cleaner now. Left two more comments on the MR then this can be set to RTBC.
@Wim Leers, if you mean that we need a change record for the
field_field_config_presave()
update, we can just tell @larowlan and @jibran about it and save a few hundred people from reading stuff they'll never have to care about :)This CR → needs to be deleted though.
- last update
over 1 year ago 29,960 pass - Assigned to wim leers
- Status changed to Needs review
over 1 year ago 4:07pm 14 August 2023 - 🇺🇸United States phenaproxima Massachusetts
OK, I've made the requested changes here. Re-assigning to Wim for a final review, now that we have subsystem maintainer approval, and for change record/issue summary updates.
- last update
over 1 year ago 29,960 pass - Assigned to phenaproxima
- Status changed to Needs work
over 1 year ago 9:52am 15 August 2023 - 🇫🇮Finland lauriii Finland
If I read #72 and #78 correctly, it's proposing moving the entity reference normalization from
hook_field_config_presave
tohook_field_config_create
which should be sufficient to ensure that entity reference fields are valid after creation.However, the MR currently keeps the normalization in
hook_field_config_presave
which is insufficient because it means that the handler is normalized only at the saving stage. It also looks like tests are passing which means that we have insufficient test coverage.I confirmed that the MR as it is is not sufficient by confirming that
\Drupal\Tests\field\Functional\EntityReference\EntityReferenceAdminTest
fails with the current MR and a version of 📌 Save FieldStorageConfig at the same time as FieldConfig Fixed that doesn't have the hard coded normalization as part of field creation. - 🇫🇮Finland lauriii Finland
Discussed with @phenaproxima on Slack because there were some confusion between comments #72 and #81. As I mentioned in #86, I understood #72 and #78 so that @amateescu is proposing to move the entity reference normalization from
hook_field_config_presave
tohook_field_config_create
. I said in #86 that it should be sufficient to ensure that entity reference fields are valid after creation.However, @phenaproxima pointed out that it won't be sufficient because the handler settings may change during the life cycle of the field config. This is why we would need at least
hook_field_config_presave
andhook_field_config_create
to normalize the config. However, this defeats the whole purpose of this issue because the intent is also to be able to validate the config before saving it. For this reason, we would need the normalization to happen on a separate layer, that could be triggered before saving.I'm wondering if this provides sufficient justification for the new API that we were proposing to add until #72 😊
- last update
over 1 year ago 29,960 pass - Issue was unassigned.
- Status changed to Needs review
over 1 year ago 1:36pm 15 August 2023 - 🇫🇮Finland lauriii Finland
Discussed with @amateescu on Slack and he said that even with the justification in #87, he would prefer to introduce the new API as part of 📌 Combine field storage and field instance forms Fixed . I can see how that makes sense because then we can make sure that the API is flexible enough to support the needs of that issue.
Doing the entity reference normalization both, on
hook_field_config_create
andhook_field_config_presave
addresses the bug where field config entities are invalid after creation which blocks both 📌 [PP-1] Convert field_storage_config and field_config's form validation logic to validation constraints Postponed and 📌 Save FieldStorageConfig at the same time as FieldConfig Fixed . We can't removehook_field_config_presave
without introducing the new normalization API because existing code may be relying on it, e.g.field_field_storage_config_update
in core.I think it would be great if we could add test coverage that I asked in #86 to make sure that this doesn't regress until we have the additional test coverage from 📌 Save FieldStorageConfig at the same time as FieldConfig Fixed .
- last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago Custom Commands Failed - 🇨🇦Canada jibran Toronto, Canada
Does that mean DER can remove the hook implementation alter and implement it's own
hook_field_config_create
and update existinghook_field_config_presave
? - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,901 pass, 1 fail - last update
over 1 year ago 29,961 pass - 🇫🇮Finland lauriii Finland
@jibran yes, the current implementation would allow you to remove
hook_module_implements_alter
from DER once 10.1.x is EOL 😊 - Status changed to RTBC
over 1 year ago 12:10pm 16 August 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
- #86 + #87: nice deciphering of this very complex situation! 🕵️♀️
- @amateescu's commit (https://git.drupalcode.org/project/drupal/-/merge_requests/4371/diffs?co...) looks great 👍
This is ready, just needs a change record. Since this is blocking high-impact usability issues, and the CR would affect so few people, I think it'd be fine to land this ahead of the CR existing 😇
- 🇺🇸United States tim.plunkett Philadelphia
I'm not sure if we'll get away with not having a CR but it would be nice to have an updated IS 😇
- Assigned to amateescu
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
@phenaproxima will tackle the issue summary update + change record tomorrow.
But more importantly, @Berdir has surfaced concerns with the current approach, which was proposed by his fellow subsystem maintainer @amateescu 😄 So, I think we really need @amateescu's input now.
(I did point @Berdir to the relevant comments though, so maybe that is already enough? 😇) - last update
over 1 year ago 29,963 pass - 🇨🇭Switzerland berdir Switzerland
We discussed my feedback in slack and I'm fine with addressing that in a follow-up.
In short, the situation for DER is indeed improved as I realized in my second comment due to the target_type check, I still think this should target specific field types only or at least give subclasses a way to customize it, but it is in line with the existing logic and behavior and that's exactly what the follow-up is about.
- Issue was unassigned.
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
IS looks great! https://www.drupal.org/node/3379013 → is still relevant.
- 🇺🇸United States phenaproxima Massachusetts
Change record written and the issue summary is rounded out. https://www.drupal.org/node/3381705 →
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Thanks for https://www.drupal.org/node/3381705 → !
Let's do this :D 🚢
- last update
over 1 year ago 29,748 pass, 70 fail - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
🧐 Let's see if the deprecation @lauriii and I thought would make sense triggers failures in core's test suite. Note that for now, I did not yet do the conditional part. If there are failures specifically for
FieldStorageConfig
settings being set onFieldConfig
, the commit I just pushed should fail tests. - Status changed to Needs review
over 1 year ago 11:07am 18 August 2023 - 🇫🇮Finland lauriii Finland
Moving to needs review because there has been changes to the MR that would benefit from further review.
- last update
over 1 year ago 29,757 pass, 70 fail - last update
over 1 year ago 29,757 pass, 70 fail - last update
over 1 year ago 29,757 pass, 70 fail - Status changed to Needs work
over 1 year ago 3:02pm 21 August 2023 - 🇫🇮Finland lauriii Finland
Discussed with @Wim Leers, @phenaproxima, @tedbow, and @tim.plunkett.
First of all, there are 2 hard requirements:
- We absolutely cannot break BC (meaning ANY change in behavior) at any point in the life cycle of Field(Storage)Config
- We absolutely need the ability to have complete Field(Storage)Config before saving
We cannot normalize in
::setSettings()
because it's possible for any contrib module to call::set('settings', …)
instead. (Plus,\Drupal\Core\Entity\EntityForm::copyFormValuesToEntity()
also calls::set(…)
!)👆 Hence the current approach in the MR: to normalize during both
::set()
and::setSettings()
.⚠️ However, we discovered that we cannot do it in
::set()
, ⚠️ because it could introduce very complex issues to debug. The key challenge is that::set()
is being called- At SAVE time by
\Drupal\Core\Config\Entity\ConfigEntityStorage::doSave
after it has called\Drupal\Core\Config\Entity\ConfigEntityStorage::mapToStorageRecord
and\Drupal\Core\Config\Entity\ConfigEntityStorage::mapFromStorageRecords
- But it's not called at LOAD time by
\Drupal\Core\Config\Entity\ConfigEntityStorage::doLoadMultiple
… meaning that normalizing in
::set()
does lead to differences in settings depending on where in the life cycle the config entity is, i.e. after saving the entity, it would be in the normalized state, but after loading it from the database, it would NOT be in the normalized state. This is highly confusing, and breaking BC for\Drupal\Core\Config\Entity\ConfigEntityStorage::mapFromStorageRecords
during save.This leaves only one option that we can see: restore
FieldItemInterface::normalizeSettings()
, make it a public method, so that it can be called e.g.A tangentially related problem is that the sole thing in Drupal core testing this is
\Drupal\field_test\Plugin\Field\FieldType\TestItem::storageSettingsToConfigData()
+\Drupal\KernelTests\Core\Field\FieldSettingsTest::testConfigurableFieldSettings()
, butTestItem
methods are adding NEW keys instead of transforming the values of EXISTING keys. The latter was always the intent — see #2293773: Field allowed values use dots in key names - not allowed in config → . So we should fix the test coverage aroundTestItem::class
because it's currently asserting things that do not make sense.
In the absurd case that something in contrib is relying on this: we can and should detect incorrect implementations oftoConfigData()
andfromConfigData()
: any key-value pairs that it returns MUST also exist in\Drupal\field_test\Plugin\Field\FieldType\TestItem::defaultStorageSettings()
. If that's not the case, that should trigger a\LogicException
or at least a deprecation.See [#2307365]!
- 🇫🇮Finland lauriii Finland
Discussed with @amateescu on Slack: https://drupal.slack.com/archives/C1BMUQ9U6/p1692622430919759.
The key insight is that @amateescu pointed out that we provide an API that allows runtime field [storage] config entities to NOT be valid config. The API that allows this is
\Drupal\Core\Field\FieldItemInterface::storageSettingsToConfigData
and\Drupal\Core\Field\FieldItemInterface::fieldSettingsToConfigData
, because these are required to have run for some field types before they can be valid config entities to store. Given that there is a difference between the stored config entity, and the runtime entity, he also pointed out that he doesn't see why the solution in #2293773: Field allowed values use dots in key names - not allowed in config → should be limited to massaging existing values.Given this, to be able to validate field [storage] config, we'll need to trigger
\Drupal\Core\Field\FieldItemInterface::storageSettingsToConfigData
and\Drupal\Core\Field\FieldItemInterface::fieldSettingsToConfigData
before triggering config validation. This could be done in an ephemeral object used for validating the config.The proposed changes to the current MR:
- Merge default settings only in
postCreate
- Stop doing it on
set
,setSetting
,setSettings
to avoid introducing changes with the runtime field config object - Move the current
trigger_error
code from\Drupal\Core\Field\FieldConfigBase::mergeDefaultSettings
to\Drupal\Core\Field\FieldConfigStorageBase::mapToStorageRecord
. This should be run after\Drupal\Core\Field\FieldItemInterface::storageSettingsToConfigData
and\Drupal\Core\Field\FieldItemInterface::fieldSettingsToConfigData
to make the callbacks responsible for normalizing the settings before saving.
- Merge default settings only in
- last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,829 pass, 55 fail - last update
over 1 year ago 30,058 pass - Status changed to Needs review
over 1 year ago 5:47pm 23 August 2023 - 🇫🇮Finland lauriii Finland
Implemented #104 with the exception that I left the
preSave
changes to a follow-up. There's around 50 tests failing if we introduce the deprecation. I think we may want implement the changes topreSave
, but that's not needed for either of the blocked issues. I think we could open a follow-up for that.I'm wondering if we could now revert the migration related changes too and move them to a follow-up? Maybe @phenaproxima could confirm that.
On top of that, we need to update CRs and the issue summary.
- last update
over 1 year ago 30,057 pass, 1 fail - last update
over 1 year ago 30,057 pass, 1 fail - 🇫🇮Finland lauriii Finland
Updated the issue summary and the change records.
Not going to file an explicit follow-up: we can define what we need in 📌 [PP-1] Convert field_storage_config and field_config's form validation logic to validation constraints Postponed .
30:59 27:17 Running- Status changed to RTBC
over 1 year ago 3:23pm 24 August 2023 - 🇷🇴Romania amateescu
Thanks for the updates, @lauriii, let's move forward! :)
- last update
over 1 year ago Custom Commands Failed - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
I dug through this in detail with @laurii and I'm confident that we can make this work for config validation support in
Field(Storage)Config
+BaseFieldOverride
.One thing I definitely hadn't thought of yet so far is how config entity objects may have different values in their runtime state vs their storage state, thanks to
\Drupal\Core\Config\Entity\ConfigEntityStorage::mapToStorageRecord()
! 😳 Fortunately, only 3 classes in core override it:\Drupal\Core\Field\FieldConfigStorageBase::mapToStorageRecord()
\Drupal\field\FieldStorageConfigStorage::mapToStorageRecord()
\Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage::mapToStorageRecord()
… plus 6 in contrib, 5 of which are virtually identical to core's Layout Builder one.
This means that for config entity validation to work, the infrastructure that provides validation for config entities must also be able to call
mapToStorageRecord()
not just prior to save, but prior to validation. But that method is currentlyprotected
😅 So we need some way to get config entities into the same state as just before saving. We may want to do that as part of 📌 Split validation-related methods from FieldableEntityInterface into a separate ValidatableInterface Needs work or in another issue.In any case, it's clear that it's possible, that this change won't block it. That's the thing we wanted to make sure.
This has been very thoroughly reviewed, and the end result after >100 comments is a far smaller patch with a tighter scope than before subsystem maintainers started reviewing it. Special thanks to @amateescu & @Berdir! 😊
EDIT: cross-post RTBC 😅🥳
- last update
over 1 year ago 30,060 pass - Status changed to Needs work
over 1 year ago 5:37pm 25 August 2023 - 🇺🇸United States effulgentsia
Overall, I think this patch makes a lot of sense. I'm glad it ended up with a fairly simple implementation. Since there might be some subtle BC breaks here, before committing it I want to read through the comment history to see what's been discussed as far as that goes. In the meantime, these are the only two things that jumped out at me:
- From the IS:
If settings are changed any point (either by setSettings(), setSetting(), or set('settings', ...)), the default settings will be merged in automatically
Where is this done?
-
+ // Filter out any unknown (unsupported) settings. + $supported_settings = array_intersect_key($this->getSettings(), $default_settings); + $this->set('settings', $supported_settings + $default_settings);
We need a change record for this (either added to https://www.drupal.org/node/3381705 → , or in my opinion it would be better as a separate CR).
- From the IS:
- Status changed to RTBC
over 1 year ago 5:44pm 25 August 2023 - 🇫🇮Finland lauriii Finland
Something that's worth noting is that the deleting of unsupported keys is currently done in
\Drupal\field\Entity\FieldConfig::preSave
so adding that step to thepostCreate()
might not be as big of change as it seems. -
effulgentsia →
committed e8787136 on 11.x
Issue #2327883 by phenaproxima, lauriii, Wim Leers, yched, amateescu,...
-
effulgentsia →
committed e8787136 on 11.x
- Status changed to Fixed
over 1 year ago 7:04pm 25 August 2023 - 🇺🇸United States effulgentsia
I read through this issue's comments, and I didn't see anything in them that concerned me about committing this as an interim improvement. The issue summary mentions that additional changes/APIs are likely needed, but those can happen in their respective issues.
Therefore, pushed this to 11.x! Great work, everyone!
Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
8 months ago 3:28pm 21 May 2024 - 🇭🇺Hungary mxr576 Hungary
It is more and more likely that the commited change breaks site install from existing config when Content Moderation is in use...
More details in #3441962-15: Call to a member function getSettings() on null in Drupal\Core\Field\FieldConfigBase->getSettings() →