Problem/Motivation

When you need to display Default User form programmatically (for example, in some block on page), it causes the error:
Error: Call to a member function id() on null in force_password_change_form_alter() (line 106 of modules/contrib/force_password_change/force_password_change.module)
Because, it gets an account object from the Route, not from Form State.

Steps to reproduce

1. Install the module and enable it.
2. Create custom block and display User Default form programmatically.

      $formObject = $this->entityTypeManager->getFormObject('user', 'default')->setEntity($user);
      $form = $this->formBuilder->getForm($formObject);

3. Add the block to some custom page, where url not uses User ID.

Comments

allaprishchepa created an issue. See original summary.

allaprishchepa’s picture

Here is a patch.

allaprishchepa’s picture

Patch is updated.
Because error appears also in validate function.

allaprishchepa’s picture

larisse’s picture

Version: 8.x-1.3 » 2.0.x-dev

This still a problem in 2.0.x version?

mistrae’s picture

I use the 2.0 version and patch is needed, yes.

larisse’s picture

larisse’s picture

Assigned: Unassigned » larisse
Status: Active » Needs review

I'll take a look on this.

larisse’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
larisse’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new19.39 KB

  • larisse committed 1899d8d on 2.0.x
    Issue #3184484 by allaprishchepa, larisse, Mistrae: Error: Call to a...
larisse’s picture

Assigned: larisse » Unassigned
Status: Needs review » Fixed

I committed in 2.0.x branch and will release a new version soon.

Thanks to everyone for working on this!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.