As reported in #19 on the related bug: #1558830: media_element_validate() has hardcoded $form_state values reference and does not work with unlimited
The error message shown when an unlimited cardinality file field using the media widget is left empty is merely " is required". The field label is not shown.
This is because the #title attribute is not added to the child elements in media_field_widget_form(), so media_element_validate() has no info to grab.
I've only looked into this briefly. I see two fairly simple options:
- Just pull the field label from the $form_state array (or field_get_instance)
- Set $element['#title'] in media_field_widget_form(), then hide the element title on those child form elements in media_element_process() (so the extra titles on the child elements don't display).
I'm not sure of the best solution. Core file field widget attaches the title to each child element which makes me think #2's likely to be the best approach (core file field widget also provides its own multiple values behavior handling but I don't think Media needs to do anything that complex). Perhaps there are other modules or parts of core that rely on the existence of the title attribute on these child elements which would make #2 preferable to the simpler #1.
Thoughts?
Comment | File | Size | Author |
---|---|---|---|
#3 | 2024609-media-multiple-field-title.patch | 1.16 KB | Dave Reid |
#2 | media-missing-validation-label-2024609-2.patch | 1.09 KB | azinck |
#1 | media-missing-validation-label-2024609-1.patch | 1.09 KB | slucero |
Comments
Comment #1
sluceroI've attached a patch to implement approach #2:
An opportunity for improvement on this might be to find a different method in
media_element_process()
to determine if the title should be hidden without storing the field cardinality in the element.Comment #2
azinck CreditAttribution: azinck commentedLittle typo. Here's a fix.
Comment #3
Dave ReidRevised patch that doesn't require any #cardinality to be passed into the media element, and only passes in #title_display.
Comment #4
crazybutable CreditAttribution: crazybutable commentedThis patch solves the issue for me.
Comment #5
Dave ReidThanks! Committed #3 to 7.x-2.x. http://drupalcode.org/project/media.git/commit/2e68439