Closed (fixed)
Project:
Drupal core
Version:
9.2.x-dev
Component:
field system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Apr 2017 at 16:28 UTC
Updated:
1 Feb 2021 at 15:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jian he commentedComment #3
jian he commentedComment #4
jungleComment #5
jungleComment #8
dahousecat commentedWhy does this need work? Patch in #3 works great for me.
Comment #9
msankhala commentedI think we also need to add the test for this.
Comment #10
p4trizio commentedPatch based on #3, including documentation in field.api.php
Comment #12
ceonizm commentedHello,
Patch #10 works fine for me
Comment #13
jian he commentedComment #17
chr.fritschAfter #2940201: hook_field_widget_form_alter() can no longer affect the whole widget for multi-value fields was committed, #2942097: Deprecate hook_field_widget_form_alter() in favor of hook_field_widget_multiple_form_alter() was proposed, but never happened so far.
So I think to prevent some hook mess, we should deprecate
hook_field_widget_form_alterandhook_field_widget_multiple_form_alterin this patch.Comment #18
chr.fritschI discussed this with @alexpott and we would like to propose the following plan:
1. Introduce
hook_field_widget_complete_form_alterThis new hook makes it possible to alter the whole field widget form at the very end.
2. Deprecate
hook_field_widget_multiple_form_alterThis hook is then not needed anymore and having it additionally would just be confusing. Also all use-cases catched by
hook_field_widget_multiple_form_alter, can be realized withhook_field_widget_multiple_form_alteras well.3. Rename
hook_field_widget_form_alterTo prevent further confusion, we should rename
hook_field_widget_form_altertohook_field_widget_single_element_form_alter, by deprecatinghook_field_widget_form_alterand introducinghook_field_widget_single_element_form_alterinstead. We thinkhook_field_widget_single_element_form_alteris still useful because it allows you to just alter a single thing.Also #2942097: Deprecate hook_field_widget_form_alter() in favor of hook_field_widget_multiple_form_alter() should be closed as “Wont’t fix”.
Thoughts?
Comment #19
amateescu commentedSounds like a great plan to me! I'm not 100% sure about renaming
hook_field_widget_form_altertohook_field_widget_single_element_form_alter, but I guess I can live with it :)Comment #21
chr.fritschI probably missed some places, but I want to know how much tests are failing.
Comment #22
alexpottI think this should be like a proper deprecation message. Saying which version the hook is deprecated in and which it will be removed in. And also point to the change record.
$element is a interesting variable name - I think we should be verbose here and use $field_widget_complete_form
I think the alter should field_widget_complete_PLUGIN_ID_form
It's good to be getting rid of this... imagine you have a plugin ID of
completeormultivalue.I think though that we might have a problem if a site did have a plugin ID of
complete. Not sure about the best way of fixing that. Also we have same problem if the ID issingle_element... tricky.I think this should be like a proper deprecation message. Saying which version the hook is deprecated in and which it will be removed in. And also point to the change record.
I think the alter should be field_widget_single_element_PLUGIN_ID_form
Needs an @see to the CR too.
Comment #23
chr.fritschThanks for the review, @alexpott.
I addressed almost all your points. Not sure what to do about the naming issue...
Comment #24
amateescu commentedHere's an initial review:
module -> modules :)
There's an extra empty line here.
We should add type hints for these arguments.
The existing hook that can only alter individual elements has worked fine in most cases for many years, so I don't think we should recommend that people use the new one instead.
It's fine to mention it as an alternative, but not really as the "preferred" one.
The hook example from the comment needs to be updated to match the new name.
'field widgets container' sounds a bit.. vague. I think that the "complete form" of a widget being wrapped in a
containerelement is an implementation detail, so maybe we can come up with a better way to describe what users can alter with this hook :)I'm still thinking through the naming issues...
Comment #25
chr.fritschThanks for the review @amateescu
#24 1-3: Fixed
#24 4: I can change that, but it's the same text we had before on
hook_field_widget_form_alter#24 5-6: Fixed
Comment #26
chr.fritschI looked through http://grep.xnddx.ru and couldn't find an existing field type in contrib that is currently named "complete", "single_value" or "multivalue".
Comment #27
amateescu commentedReviewed the patch once more and it looks ready to go :)
Comment #28
adityasingh commented#25 Patch Failed to Apply.
Reroll the patch for
9.2.x, please review the patch.Comment #29
adityasingh commentedPlease ignore #28.
#25 'Patch Failed to Apply'.
Reroll the patch for
9.2.x, please review the patch.Comment #30
chr.fritsch#29 contained some unrelated changes in the dictionary.
I rerolled #25
Comment #31
chr.fritschOk, fixed the coding style issues
Comment #32
volkerk commentedLooked at the diff between 2872162-25.patch and 2872162-31.patch. Changes were regarding assertions and cs.
Lgtm.
Comment #33
alexpottCommitted 81e2d9c and pushed to 9.2.x. Thanks!
Comment #35
chr.fritschIn case someone needs a patch that applies on D8.9. Here it is