0

I want a custom route to the normal user form. So, I've added an entry to the routing file that directs my custom route to the canonical form of the User entities:

my_profile_form:
  path: '/user/{user}/my-profile-form'
  defaults:
    _form: '\Drupal\user\ProfileForm'
    _title: 'My profile form'
  requirements:
    _role: 'administrator'

When I try to open /user/1/my-profile-form with my browser, I see the following error message:

Error: Call to a member function getEntityTypeId() on null in Drupal\Core\Entity\EntityForm->getBaseFormId() (line 106 of ...web/core/lib/Drupal/Core/Entity/EntityForm.php)

It seems that with my custom route the form does not know who the user is.

What magic must happen to inform the form about the user?

1
  • 1
    Have you tried adding type: entity:my_entity_type as mentioned here? Commented Feb 20, 2020 at 18:28

2 Answers 2

1

You can try using _entity_access

my_profile_form:
....
  requirements:
    _role: 'administrator',
    _entity_access: user.update
   user: \d+

See EntityAccessCheck

1

Custom access check is written to check whether the logged in user is same as of user id passed in the parameter

my_module.user.profile:
  path: '/user/{user}/profil'
  defaults:
    _entity_form: 'user.profil'
    _title: 'Profil'
  requirements:
    _entity_access: 'user.update'
    _custom_access: '\Drupal\my_module\Access\MyModuleUserAccess::editProfil'
    user: \d+
  options:
    _admin_route: FALSE
1
  • Hallo, @sudesh-solaskar! Thank you for your answer! The argument _entity_form is the the solution. Entity forms need this argument in the route definition, instead of _form. We can confirm this when setting a breakpoint here: git.drupalcode.org/project/drupal/blob/… . Maybe, you could clarify your answer. Commented Feb 21, 2020 at 20:15

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.