How to utilize custom form modes to edit a user entity? My project requires two different pages to edit a user. The first one being at /settings/{user}/my-profile, where the user updates their name, address, etc. The other page is at /settings/{user}/login-credentials, where the user updates their username, password, etc. 

After navigating to /admin/structure/display-modes/form, I have created a custom form mode called "My Profile" which has the id user.my_profile, and activated it at the bottom of admin/config/people/accounts/form-display.

Now I need to create a page that utilizes this new custom form mode, and I'm a bit lost. 

I looked into how the standard user edit route is created at /user/{user}/edit, and I found the code in the route provider at namespace Drupal\user\Entity;. This is what is in that method (other routes have been removed)...

public function getRoutes(EntityTypeInterface $entity_type) {
  $route_collection = new RouteCollection();

  $route = (new Route('/user/{user}/edit'))
    -&gt;setDefaults([
      '_entity_form' =&gt; 'user.default',
      '_title_callback' =&gt; 'Drupal\user\Controller\UserController::userTitle',
    ])
    -&gt;setOption('_admin_route', TRUE)
    -&gt;setRequirement('user', '\d+')
    -&gt;setRequirement('_entity_access', 'user.update');
  $route_collection-&gt;add('entity.user.edit_form', $route);

  return $route_collection;
}


Then I did some research on the routing system, and I've created a routing.yml file. The name of my module is sc, and the file is at modules/custom/sc/sc.routing.yml.

sc.routing.yml

sc.my_profile.edit:
  path: '/settings/{user}/my-profile'
  defaults:
    _entity_form: 'user.my_profile'
    _title_callback: 'Drupal\user\Controller\UserController::userTitle'
  requirements:
    user: '\d+'
    _entity_access: 'user.update'
    _permission: 'access content'


I'm logged in as user1, cleared the cache, and when I navigate to /settings/1/my-profile, I get "Page Not Found". Am I on the right track? How do I create these pages with different form modes?
You have to add the form mode in the handlers section of the user entity:

/**
 * Implements hook_entity_type_build().
 */
function mymodule_entity_type_build(array &amp;$entity_types) {
  $entity_types['user']-&gt;setFormClass('my_profile', 'Drupal\user\ProfileForm');
}


Use the standard class ProfileForm as you only want a set new form mode, not a new form class.

Then you can use this new handler in place of user.default in the routing file:

'_entity_form' =&gt; 'user.my_profile',