In a custom module I am trying to hook into custom profile fields on the user registration form. In the custom_module.module file I am using custom_module_form_user_register_form_alter to use an ajax callback to autofill one profile field based on the content of another field. But I have not been able to hook into the profile fields on the user registration form. I am able to access the basic user fields like so:
function custom_module_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form['account']['mail']['#required'] = TRUE;
$form['account']['mail']['#title'] = 'Changed title';
The above works but I have tried several different methods but can't touch the profile fields with my code. I tried:
$form['account']['field_registration_code']['#title'] = "Change this";
and
$form['account']['survey_participants_profiles[0][entity][field_registration_code][0][value]']['#title'] = "Change this`";
and
$form['survey_participants_profiles[0][entity][field_registration_code][0][value]']['#title'] = "Change this";
and several variations of the above. How do I call the custom profile fields from hook_form_alter?
Here is what finally worked after hours of guesswork:
$form['survey_participants_profiles']['widget'][0]['entity']['field_registration_code']['widget'][0]['value']['#title'] = 'blurg';