How to prevent email address from displaying on edit profile page? I have set up my site so that some users with a specific role can't edit their email address. This works fine - users with role type A can navigate to the edit tab on their profile and edit their email address, and users with role type B are unable to edit their email address. However, these users can still view their email address field on the edit tab, it just appears disabled. I do not want this to be the case.

I used the User Protect and Field Permissions modules to achieve this. For all of the other fields that I prevented users with role type B from editing (e.g. their name), the fields did not appear at all on the edit tab. I have used the same settings in field permissions for these fields and the email field but for some reason the email field appears under the edit tab but the others don't. How can I prevent the email field from displaying when users don't have permission to edit it?
You can to this using hook_form_FORM_ID_alter(), like this:

function MY_MODULE_form_user_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if (in_array('role_B', \Drupal::currentUser()-&gt;getRoles())) {
    // We restrict access if the field is disabled.
    $form['account']['mail']['#access'] = FALSE;
  }
}