Drupal - How to make form field read only?
This can be done via hook_form_alter
function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if($form_id == 'user_register_form') {
$form['field_name']['widget'][0]['value']['#attributes']['readonly'] = 'readonly';
}
}
Add some css:
input:read-only {
background-color: #ddd !important;
}