The $form[$field_name] structure prepared by WidgetBase::formSingleElement() contains lots of #custom_properties
that can now be obtained through other ways :
- The $items parameter in Widget::formElement()
- The $context parameter for hook_field_widget_form_alter()
- The main entity for form_alters on the whole form.
$form[$field_name]['#entity']
$form[$field_name]['#entity_type']
$form[$field_name]['#bundle']
$form[$field_name]['#language']
$form[$field_name]['#field_name']
Interestingly, '#entity' was added very late in D7 (only a little more than 2 years ago, post 7.0) to support #1541792: Enable dynamic allowed list values function with additional context.
It was only needed so that the widgets for "list" field types could pass the $entity to the "give me the list of allowed values" function.
Comment | File | Size | Author |
---|---|---|---|
#13 | 2293723-doc_followup-13.patch | 2.77 KB | yched |
#7 | interdiff.txt | 1004 bytes | yched |
#7 | 2293723-simplify_field_form-7.patch | 7.81 KB | yched |
#6 | interdiff.txt | 958 bytes | yched |
#6 | 2293723-simplify_field_form-6.patch | 6.83 KB | yched |
Comments
Comment #1
yched CreditAttribution: yched commentedSome of those properties might be used by widget specific #process or #submit FAPI callbacks - FileWidget does that.
But those are very specific use cases, those widgets can totally take care of placing the #custom_properties their helper callbacks need. FileWidget does it already for a couple properties.
Other than that, brute force patch, let's see what breaks...
Comment #3
yched CreditAttribution: yched commentedSo, LinkWidget uses $element['#entity'] to figure whether we are on the "default value" widget in the instance edit form.
Not sure that even works, and need to mull a bit more on the right alternative.
Meanwhile, fixed the other fails.
Comment #5
andypostnice clean-up! much less data to serialize for entity forms!
PS: the default values for comment field still have hacks, so I re-opened #1919834-13: Field instance got no default value when created in field UI
Comment #6
yched CreditAttribution: yched commentedBetter way to check for "are we on the default value widget ?" in LinkWidget.
Should hopefully be green.
+ more accurate title.
Comment #7
yched CreditAttribution: yched commentedRemoving those properties from the docs too.
Comment #8
andypostawesome clean-up
Comment #9
yched CreditAttribution: yched commentedCreated a draft change notice : https://www.drupal.org/node/2294629
Comment #10
catchCommitted/pushed to 8.x, thanks!
Comment #12
yched CreditAttribution: yched commentedThanks !
Published the CR at https://www.drupal.org/node/2294629.
Comment #13
yched CreditAttribution: yched commentedQuick doc followup : EntityFormDisplayInterface::buildForm() documented this structure too - and was in fact a bit stale already.
Attached patch makes it to date.
Comment #14
andypostHm, missed this too
Comment #16
catchCommitted/pushed the follow-up, thanks!
Comment #17
yched CreditAttribution: yched commentedThanks @catch. You might also be interested in #2200355: Move functions in field.form.inc into Core/Field :-)