- First commit to issue fork.
- 🇺🇸United States justcaldwell Austin, Texas
#6 adds a custom submit handler that avoids storing anything if no EPP config was set.
I elected to keep the config if either setting (
value
oron_update
) is non-empty, rather than just thevalue
as originally proposed. Easy enough to change if desired.In my testing, this solves the issue for new installations (empty data is never saved), and removes existing 'empty' config data if the field config is updated/re-saved. I guess an ideal resolution would also implement an update hook to clean up any existing 'empty' config data. The data isn't really doing any harm, but maybe some kind soul wants to write that update hook. 😀
- 🇺🇸United States justcaldwell Austin, Texas
I edited the IS summary and steps to reproduce a bit. All field config files are not modified immediately upon enabling EPP. Only when a field is added or edited.
- Status changed to Needs review
almost 2 years ago 3:59am 17 March 2023 - Status changed to Needs work
almost 2 years ago 11:00am 17 March 2023 - 🇩🇪Germany geek-merlin Freiburg, Germany
Thanks for working on this!
I agree with how to handle the "empty" check.
I'm fine with having the update hook in a followup issue (can you open that?).The MR needs work in one point:
Using "submit" is too brittle, we've had issues with that, and there is a way better alternative:
Look into \Drupal\Core\Entity\EntityForm::buildEntity, there you see how #entity_builders is used.
Add your #entity_builders instance, and adjust the fieldConfig->getThirdPartySetting() value that was copied there by ::copyFormValuesToEntity. - Status changed to Needs review
almost 2 years ago 4:35pm 17 March 2023 - 🇺🇸United States justcaldwell Austin, Texas
Nice! Thanks for pointing me in the right direction.
Last change uses an entity builder instead of a submit handler. I didn't want to over complicate things, so I explicitly check the two current settings. I can switch to iterating over the settings instead if you think others might be added later making this approach too brittle.
- Status changed to Needs work
almost 2 years ago 4:59pm 17 March 2023 - 🇩🇪Germany geek-merlin Freiburg, Germany
Yes that's the direction. But you should only refer to $fieldConfig (not $formState) in the entity_builder, and can
unsetThirdPartySetting('epp')
so we won't have an empty array left. And nice if you can do a manual test. - 🇺🇸United States justcaldwell Austin, Texas
Sorry, just to be clear, which direction: 1) the current approach with explicit setting, or 2) iterate over the settings?
Also,
unsetThirdPartySetting()
requires a setting key as the second parameter, but ConfigEntityBase::unsetThirdPartySetting removes the empty array if all settings are unset. - 🇩🇪Germany geek-merlin Freiburg, Germany
> Also, unsetThirdPartySetting() requires a setting key as the second parameter, but ConfigEntityBase::unsetThirdPartySetting removes the empty array if all settings are unset.
Yes you are right, i forgot that.
> which direction: 1) the current approach with explicit settings,
Yes, this is well-chosen!
- Status changed to Needs review
almost 2 years ago 6:20pm 17 March 2023 - 🇺🇸United States justcaldwell Austin, Texas
Great, thanks! Latest change removes usage of $form_state.
I've tested this manually on a clean Drupal 9 instance by:
- Setting one, both or neither value on a plain text field
- Export config
- Check the resulting changes to field.field.[content-type].[bundle].[field_name].yml
Works as expected. Relevant bits of the config file excerpted below:
Both values set:
dependencies: config: - field.storage.node.field_test_epp_1 - node.type.page module: - epp third_party_settings: epp: value: '[current-user:display-name]' on_update: 1
Only 'on_update' set:
dependencies: config: - field.storage.node.field_test_epp_1 - node.type.page module: - epp third_party_settings: epp: value: '' on_update: 1
Neither value set:
dependencies: config: - field.storage.node.field_test_epp_1 - node.type.page
I did the same for a base field (body), with the same results.
- Status changed to RTBC
almost 2 years ago 8:10pm 17 March 2023 - 🇩🇪Germany geek-merlin Freiburg, Germany
Yup, we got it, code LGTM, and you did a manual test and described it well.
-
geek-merlin →
committed d06b2da7 on 8.x-1.x authored by
_pratik_ →
Issue #3331366 by justcaldwell, _pratik_, geek-merlin, kopeboy: Remove...
-
geek-merlin →
committed d06b2da7 on 8.x-1.x authored by
_pratik_ →
- Status changed to Fixed
almost 2 years ago 8:16pm 17 March 2023 - 🇩🇪Germany geek-merlin Freiburg, Germany
Thanks for the improvement. It was a pleasure!
Commited and tagged a new version. - 🇺🇸United States justcaldwell Austin, Texas
🙌 Excellent, thanks! I enjoyed working with you.
Automatically closed - issue fixed for 2 weeks with no activity.