hook_form_user_alter not called

Created on 16 April 2020, about 4 years ago
Updated 7 April 2024, 3 months ago

I am using Commerce which prints a login and register form for anonymous users, when activated this setting in the checkout flow. The form is printed with this function

namespace Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane;
...
class Login extends CheckoutPaneBase implements CheckoutPaneInterface, ContainerFactoryPluginInterface {
...
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
...

    /** @var \Drupal\user\UserInterface $account */
    $account = $this->entityTypeManager->getStorage('user')->create([]);
    $form_display = EntityFormDisplay::collectRenderDisplay($account, 'register');
    $form_display->buildForm($account, $pane_form['register'], $form_state);

If you print $form_display you notice that the function password_policy_form_user_form_alter was not fired at all because this is a commerce_checkout_pane form and not a user form. I implemented a hook_form_alter in my theme and this gets fired but there is not $form['field_last_password_reset'] beeing set so i can not overwrite it with

  $account = \Drupal::currentUser();

  if (!$account->hasPermission('manage password reset')) {
    $form['field_last_password_reset']['#access'] = FALSE;
    $form['field_password_expiration']['#access'] = FALSE;
  }

Currenty i overwritten the buildPaneForm function and manually unset both fields but maybe this module should also hide the 2 field when fireing the collectRenderDisplay function above.

πŸ› Bug report
Status

Postponed: needs info

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany fox_01

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States Kristen Pol Santa Cruz, CA, USA

    Thanks to everyone for the work on this issue.

    I'm going through all the 8.x issues.

    As the 8.x is no longer supported, I'm postponing this issue for now and need feedback as to whether or not this issue is relevant to 4.0.x.

    If it is, please reopen and change the version, make sure the issue summary is clear and complete, including concrete steps to reproduce, and reroll the patch. If it's not, please close.

    If there is no response to this in a month addressing the above, it can be closed.

Production build 0.69.0 2024