Tags/topics: 
3
Answers
Vote up!
0
Vote down!

How to hide Customer Profile custom fields?

I have added some fields to the Customer Profile shipping and billing types. They are ID fields to maintain consistency with a backoffice system that I am trying to link with Drupal Commerce. Consequently, they mustn't be editable and they don't need to be visible. I have set them as Hidden in Manage Display, but it makes no difference, they are still visible and editable in the Customer Profile edit page. How do I make these fields hidden or at least non-editable by a user editing their profile?

Asked by: Bruno Prior
on September 28, 2014

Comments

I've hidden them with CSS, but it would be better if they weren't part of the form, rather than using styling to make them not show.

- Bruno Prior on September 28, 2014

3 Answers

Vote up!
1
Vote down!

Yes, that would be the core way to do it. I have installed the Field Permissions module as an easier option for now. It allows me to prevent individual fields from being viewed and/or edited by specified roles. It's not as flexible as hook_form_alter, which I guess (for instance) would let me disable editing of fields that were nevertheless viewable in a form, which isn't possible with Field Permissions, so far as I can tell.
It just seemed like the default behaviour was not as you would expect.

Answer by: Bruno Prior
Posted: Oct 4, 2014
Vote up!
1
Vote down!

hook_form_alter()?

That's my quick guess. Any form in Drupal can be modified by hook_form_alter()s.

Josh Miller
Answer by: Josh Miller
Posted: Oct 3, 2014
Vote up!
0
Vote down!

This code should work (and works outside drupal commerce)

function mymodule_form_alter(&$form, $form_state, $form_id) {

if ( $form_id == 'user_profile_form' ) {
$form[OSC_FIELD_NAME]['#access'] = FALSE;
}
}

However when drupal commerce is installed $form_id gets set to views_exposed_form so my code doesn't work. Has anyone found a solution to this outside installing yet another module or hiding the field via css?

senorbond
Answer by: senorbond
Posted: Jul 1, 2015