2

I would like to show 2 instances of the User Profile edit form on the same page. One form mode only shows the username/password widget with the submit button. The other form mode only shows the contact information with the submit button.

When I try the following, I get Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException: The "user" entity type did not specify a "user.change_password" form class. Note that I've changed the form class to change_password as well.

$user = User::loadMultiple([$this->account->id()]);
$form = $this->entityFormBuilder->getForm($user[$this->account->id(), 'change_password']

I asked a similar question regarding custom entities but using that solution would require modifying core files.

Is it possible to do this?

1 Answer 1

0

You don't need to modify core files, you can modify the "user" entity type in a hook. This is how you add a form class for the form operation change_password:

mymodule.module

function mymodule_entity_type_build(array &$entity_types) {
  $entity_types['user']->setFormClass('change_password', 'Drupal\user\ProfileForm');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.