A form ID does not change when the form is submitted. It does not contains hyphens too; therefore, user-form--hWMonV_OXao is not a form ID.
The Contact module alters the user profile form using the following code. (See contact_form_user_form_alter()
.) It works whenever users enter their current password or not.
function contact_form_user_form_alter(&$form, FormStateInterface $form_state) {
$form['contact'] = [
'#type' => 'details',
'#title' => t('Contact settings'),
'#open' => TRUE,
'#weight' => 5,
];
$account = $form_state->getFormObject()->getEntity();
if (!\Drupal::currentUser()->isAnonymous() && $account->id()) {
$account_data = \Drupal::service('user.data')->get('contact', $account->id(), 'enabled');
}
$form['contact']['contact'] = [
'#type' => 'checkbox',
'#title' => t('Personal contact form'),
'#default_value' => $account_data ?? \Drupal::config('contact.settings')
->get('user_default_enabled'),
'#description' => t('Allow other users to contact you via a personal contact form which keeps your email address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.'),
];
$form['actions']['submit']['#submit'][] = 'contact_user_profile_form_submit';
}
As a side note, the current password is only required when users change their own email or the password. The description for the Current password field says that.
Required if you want to change the Email address or Password below.
The following hook implementation is sufficient.
function demetra_form_user_form_alter(&$form, FormStateInterface $form_state) {
$form['field_first_name']['widget'][0]['value']['#title'] = '';
$form['field_first_name']['widget'][0]['value']['#placeholder'] = t('Enter your name...');
}
As a further side note, an empty string is not translatable: It is still an empty string (''
) in every language.