Closed (fixed)
Project:
D7 Media
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 May 2012 at 08:15 UTC
Updated:
20 Jun 2013 at 20:59 UTC
Jump to comment: Most recent file
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 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 commented#1: media-element-validate-1558830-1.patch queued for re-testing.
Comment #8
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 commentedswitching to correct status
Comment #10
iamEAP commentedCan confirm this works for me. Switching to RTBC, but obviously the more reviews, the merrier.
Comment #11
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 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 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 commentedpeteruithoven: Try this. Minor change incorporated from #999594: media form elements don't respect '#required' property
Comment #16
aaron commentedThis looks good to me.
Comment #17
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 commentedHere you go.
Comment #19
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 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 commentedI was having problems with an unlimited media field within a field collection and #18 worked for me, thanks!
Comment #24
ParisLiakos commentedthanks aaron for the backport and jibize for reporting back:)
committed!
http://drupalcode.org/project/media.git/commit/0dd8bde
Comment #26
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