I'm trying to mark fields on the /user/_uid_/edit
screen as disabled.
These are custom fields I've created in /admin/config/people/accounts/fields
in D8.
I have this code for another node entity type...
function MODULENAME_form_node_survey_edit_form_alter(&$form, $form_state, $form_id) {
$form['field_content_type']['widget']['#type'] = 'hidden';
}
This works as expected, and on the node/123/edit screen for a that content type, that field is hidden. (works as expected)
(it gets populated by a migration process, and needs to stay how its set, even if users change other fields...)
My problem is, that I'm trying to disable a field on the USER-EDIT screen, such as /user/123/edit.
I'm trying the EXACT same code structure.
function MODULENAME_form_user_edit_form_alter(&$form, $form_state, $form_id) {
$form['field_organization_reference']['widget'][0]['target_id']['#attributes']['disabled'] = 'disabled';
}
But it doesn't work.
I've tried throwing in class changes, and other things to alter the input fields, but they don't work.
$form['field_organization_reference']['widget'][0]['target_id']['#attributes']['disabled'] = 'disabled';
$form['field_organization_name']['widget'][0]['value']['#attributes']['disabled'] = 'disabled';
$form['field_organization_reference']['#attributes']['class'][] = 'borkbork';
$form['field_organization_name']['#attributes']['class'][] = 'borkbork';
$form['field_organization_name']['widget']['#type'] = 'hidden';
All as attempts to try and change something on the user edit form.
But nothing is working.
Is user-edit
the correct form id? Is there something else I'm missing
Thoughts? Help? Thank you!