WidgetBase::form() / FormatterBase::view() both take care of nesting the generated render arrays in a wrapper keyed after the field name.
This matches the common use case of entity forms and entity views ($form['field_foo'] / $form_values['field_foo'] / $content['field_foo'])
However:
- In some other cases, that wrapper is not wanted, and needs to be manually unwrapped
- This being done in base methods, there is no guarantee that some widgets / formatters don't override it, and this results in unpredictability.
Widgets / formatters shouldn't do the wrapping themselves, they job should just be to return their own specific render array. The wrapping should be done by the calling code if needed.
Comment | File | Size | Author |
---|---|---|---|
#4 | interdiff.txt | 727 bytes | plopesc |
#4 | remove_wrappers-2151693-4.patch | 3.98 KB | plopesc |
#2 | remove_wrappers-2151693-2.patch | 3.99 KB | plopesc |
Comments
Comment #1
yched CreditAttribution: yched commentedSimilar : #2151699: Move #access responsibility from formatters/widgets to EntityViewDisplay/EntityFormDisplay
Comment #2
plopescRemoving $element wrappers in WidgetBase::form() / FormatterBase::view().
Given that
WidgetBase::form()
is called fromfield_invoke_method()
, I changed a bit its logic, but does not affect other methods called through this function.I made some local tests and it works, let's see what testbot says...
Comment #3
yched CreditAttribution: yched commentedCool!
Minor: it would be slightly clearer to do
$build[$key][$field_name] = $formatter->view();
Hah - true, a bit tedious.
That function is going away in #2095195: Remove deprecated field_attach_form_*() anyway, at which point it's going to be up to EntityFormDisplay to add the $field_name key (like EntityViewDisplay does here)
Once 1. above is changed, this is RTBC IMO.
Comment #4
plopescImproving patch in #2
Comment #5
yched CreditAttribution: yched commentedThanks !
Comment #6
catchMuch nicer. Committed/pushed to 8.x, thanks!
Comment #7
catchI think this got smushed in with another commit, but don't have time to find that right now. If that's what happened please link the commit here and I'll revert and sort it out.
Comment #8
plopescSorry, I only read the git log and I missed the commit related to this issue.
I found that this patch was committed in 0aa59382b25792ae46f6df193abe8abc0bf1ca0b, related to #2192649: Remove drupal_set_title() from installation and update process.
Regards