I created a custom module with hook_form_alter to change the weight of the address fields (from the address field module). However, when you activate the module, the address field goes beyond the edit form, it only works if the profile2_page module is enabled in the profile. The problem is that I do not want to use profile2_page. Can someone help me?

Comments

wesleybpereira created an issue. See original summary.

rickj’s picture

I don't understand why you need custom code to change the weight. What can you not do using "Manage Fields" and "Manage Display" in the profile configuration?

wesleybpereira’s picture

It's because the address field module does not allow changing the position of the fields by the manager. The only way I found it was by using a custom module with hook_form_alter.

rickj’s picture

Ah, so you mean the ordering of the fields within the address field module itself? That's really an issue for the address field module, not very much to do with profile2.

The address field widget controls the layout of the whole address block. It's not trivial, because the fields shown, and their position, depends on the selected country. A lot of it is done by Javascript, and is largely the point of the module.

If I understand you right, then you need to be looking at address field. I use address field myself, but I haven't needed to do what you're suggesting.

wesleybpereira’s picture

Ricky, I did it! I used "hook_form_profile2_edit_PROFILE_TYPE_form_alter ()" and it worked. I do not know if the way I did is the right one, but it worked. Thank you so much for everything! Hug!

This was the code I used in a custom module.

function address_order_fields_profile2_form_profile2_edit_meu_perfil_profissional_form_alter(&$form, &$form_state){


    $form['profile_meu_perfil_profissional']['field_endereco_profissional']['und'][0]['name_block']['#weight'] = -100;

    $form['profile_meu_perfil_profissional']['field_endereco_profissional']['und'][0]['organisation_block']['#weight'] = -90;

    $form['profile_meu_perfil_profissional']['field_endereco_profissional']['und'][0]['locality_block']['#weight'] = -90;

    $form['profile_meu_perfil_profissional']['field_endereco_profissional']['und'][0]['locality_block']['postal_code']['#weight'] = -80;

    $form['profile_meu_perfil_profissional']['field_endereco_profissional']['und'][0]['country']['#disabled'] = true;

    $form['profile_meu_perfil_profissional']['field_endereco_profissional']['und'][0]['country']['#prefix'] = '<div style="display:none;">';
 
    $form['profile_meu_perfil_profissional']['field_endereco_profissional']['und'][0]['country']['#suffix'] = '</div>';

    $form['profile_meu_perfil_profissional']['field_endereco_profissional']['und'][0]['locality_block']['administrative_area']['#disabled'] = true;

}
wesleybpereira’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.