Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Updated: Comment #0
Problem/Motivation
Currently WidgetBase::formSingleElement()
wrongly passes to context a flag indicating that default value used for widget by examining property that never set so there's no way for widgets' alter implementation to detect field_ui usage of widget.
$context = array(
...
'default' => !empty($entity->field_ui_default_value),
Proposed resolution
Replace this with $element['#field_parents'] != array('default_value_input')
at least
Remaining tasks
Suggest proper method for widget to detect default value usage
User interface changes
no
API changes
no
Related Issues
tbd
Comment | File | Size | Author |
---|---|---|---|
#20 | 2084987-followup.patch | 1.04 KB | andypost |
#16 | 2084987-field-default-16.patch | 2.99 KB | andypost |
Comments
Comment #1
andypostThere's only one left, probably needs tests
Comment #2
andypostThis is major because alter functions will always get
FALSE
so no way to detect widget usage for field instance settings form!Comment #3
andypostWith test
PS: the coverage for form already done in /FormTest::testFieldFormSingle()
Comment #4
jibranWell issue has fail patch and pass patch so bug is fixed but I don't know a lot about this issue leaving it for @swentel or @yched to RTBC.
Comment #5
andypostre-roll
Comment #8
andypostre-roll
Comment #9
yched CreditAttribution: yched commentedin_array('default_value_input', $form['#parents'])
is one way to differentiate, yes.Alternatively, we could also use
if (empty($form_state['default_value_widget'])
, that's what I did for LinkWidget in #2293723: Generate lighter $form[$field] structures.I hesitated between the two back then in that issue, and considered that a condition on $form_state['default_value_widget'] was a bit more telling (and not dependent on the form tree structure). No big difference I guess, but we should be consistent.
Comment #10
yched CreditAttribution: yched commented"But we should be consistent"...
I guess one way would be to encapsulate this check once and for all in a isDefaultValueWidget() method on WidgetBase.
- widgets that need this info, like LinkWidget, can call it directly instead of doing an obscure test
- we can pass that as
$context['default'] = $this->isDefaultValueWidget()
when calling hook_field_widget_form_alter()Comment #11
Jalandhar CreditAttribution: Jalandhar commentedPatch needs to be updated.
Comment #12
Jalandhar CreditAttribution: Jalandhar commentedHere is the updated patch.
Comment #13
jhedstromI was a little confused what this code was testing. Instead of
hook_field_widget_form_alter()
, could the comment mentionfield_test_field_widget_form_alter()
?Comment #14
jhedstromAlso, from #10
should be addressed I think.
Comment #15
andypost#10 fixed
Comment #16
andypostuh, phpdoc clean-up
Comment #17
yched CreditAttribution: yched commentedLooks good. Thanks folks :-)
Comment #18
catchCommitted/pushed to 8.0.x, thanks!
Comment #20
andypostFollow-up to clean-up the comment widget usage
Comment #21
tstoecklerComment #22
catchFollow-up looks good but please open a new issue. Two patches means two commit hashes.
Comment #23
andypostFiled follow-up with the same patch #2390013: Follow-up comment widget should properly detect default value input