Hi, I just had a quick question about working with profile2 fields through hook_form_alter(), in a localization-friendly way (i.e. not hard-coding 'und').

I want to gain access to the actual form array, which is usually buried under 'und' in a #type => 'container' array. I can obviously do something like, $form['my_profile_name']['field_my_really_long_field_name']['#language'] but I am hoping I would actually be able to use something like field_language — or better yet, field_get_items() to get the array. When I tried the usual method of field_get_items('profile2', $form['my_profile_name'], ''field_my_really_long_field_name') I get a EntityMalformedException.

So I'm wondering if there's something I'm missing here? Would love an easy, correct way of accessing this data. Thanks! :)

Comments

kabojnk’s picture

I've worked around the issue with the following pattern:

$profile_language = $form['profile_public_profile']['field_is_professional']['#language'];    
unset($form['profile_public_profile']['field_is_professional'][$profile_language]['#options']['_none']);

AFAIK the #language attribute is bound to the profile2 form field and not the current user's language, which is good.

firfin’s picture

Status: Active » Closed (duplicate)

A better way IMO is to use field_get_items()
For an example see #1328534: EntityMalformedException