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.
foreach ($form_state['values'][$field_name][$lang] as $value) {
This doesn't work if the field is e.g. inside a field collection.
Comment | File | Size | Author |
---|---|---|---|
#20 | inline-edit.png | 16.95 KB | andypost |
#18 | media-element-validate-1558830-18.patch | 662 bytes | aaron |
#15 | media-element-validate-1558830-15.patch | 965 bytes | azinck |
#13 | media-element-validate-1558830-13.patch | 909 bytes | ParisLiakos |
#8 | media-to_tip_update-1789720-2.patch | 714 bytes | josefnpat |
Comments
Comment #1
BerdirActually, there are 3 different bugs in that function :)
- the already mentioned $form_state issue, fixed in the patch by using drupal_array_get_nested_value() with the #array_parents of $element. Tested this with field groups, field collections and a bare field.
- It is completely broken for unlimited field items because then there is an array entry "Add another item". And if ($value['fid']) is TRUE because 'fid' is cast to 0 and the string does have a character at index 0. PHP--
- Additionally, the validation error message does not contain the correct field name for multiple values.
I'm not sure if the whole thing shouldn't be in hook_field_validate()...
Comment #2
Dave ReidThis seems to be field-module specific and does this mean it would not be possible to use a media FAPI element in a non-field context?
Comment #3
BerdirYes it is, but the old code asssumes fields and field languages as well:
I guess if it needs to work for non-fields, then this needs to be re-designed completely, maybe two different functions?
Comment #4
Dave ReidMarked #1691500: Validation fails if mediafield is in a nested form - Inline Entity Form as a duplicate of this issue.
Comment #5
ParisLiakos CreditAttribution: ParisLiakos commentedclosed as dups #1801284: Media field validation doesnt work with #required Media Fields in a Field Collection. and #1789720: Required field validation fails with profile2
Comment #6
ParisLiakos CreditAttribution: ParisLiakos commented#1: media-element-validate-1558830-1.patch queued for re-testing.
Comment #8
josefnpat CreditAttribution: josefnpat commentedThe same patch submitted by axel.rutz, but from this commit (hopefully tip):
Someone please also confirm that this patch works for them.
Comment #9
ParisLiakos CreditAttribution: ParisLiakos commentedswitching to correct status
Comment #10
iamEAP CreditAttribution: iamEAP commentedCan confirm this works for me. Switching to RTBC, but obviously the more reviews, the merrier.
Comment #11
ParisLiakos CreditAttribution: ParisLiakos commentedthis doesnt seem quite right to me..
seems $values is being overriden and my guess is that we want to append those values in the array
Comment #12
BerdirNo, it's supposed to work like that, it's working itself through the nested $values array to the one it wants.
However, it should probably drupal_array_get_nested_value() or whatever that was called again ;)
Comment #13
ParisLiakos CreditAttribution: ParisLiakos commentedOk, i think i got it..thanks for the tip Berdir..
i actually took patch @#1..and used $element['#title'] for the label..right?
this way this is not field specific..
Comment #14
peteruithoven CreditAttribution: peteruithoven commentedThe #13 patch doesn't give me a warning when I'm leaving a Media file selector field that is set to unlimited but is required, empty.
Comment #15
azinck CreditAttribution: azinck commentedpeteruithoven: Try this. Minor change incorporated from #999594: media form elements don't respect '#required' property
Comment #16
aaron CreditAttribution: aaron commentedThis looks good to me.
Comment #17
ParisLiakos CreditAttribution: ParisLiakos commentedcommitted to 2.x! thanks all:)
http://drupalcode.org/project/media.git/commit/d10a1ed
anyone up for a backport? should be fairly easy, this function is pretty much the same iirc
Comment #18
aaron CreditAttribution: aaron commentedHere you go.
Comment #19
peteruithoven CreditAttribution: peteruithoven commentedGreat and fast work azinck!
In my installation the error is missing the field label. For some reason $element's title is empty. I was able to retrieve the label from the $form_state. But I'm not sure if that's the way to go.
Comment #20
andypostI think it's related...
I've updated media(2.x) and inline_entity_form(1.1) but for some reason I see all links. Edit link points to /media/0/edit/nojs and thrown error, Add & Remove just scrolls the page.
When I edit products without inline everything works fine
Comment #21
azinck CreditAttribution: azinck commentedandypost: I haven't used inline_entity_form so I'm not sure of the interactions there, but have you updated to the corresponding version of File Entity?
Comment #22
andypost@azinck Thanx, update File Entity helps. I forget that it no more a part of media
Comment #23
jibize CreditAttribution: jibize commentedI was having problems with an unlimited media field within a field collection and #18 worked for me, thanks!
Comment #24
ParisLiakos CreditAttribution: ParisLiakos commentedthanks aaron for the backport and jibize for reporting back:)
committed!
http://drupalcode.org/project/media.git/commit/0dd8bde
Comment #26
azinck CreditAttribution: azinck commentedThe problem reported in #19 still exists. Using the latest dev and a fresh installation of D7 the validation message is not showing the field name:
I've opened a new issue: #2024609: Field label missing from error message when a "required" unlimited cardinality file field is left empty