Skip to main content
Home

Main navigation

  • Home
  • Blogs
  • Team
  • Jobs
  • Contact

Right Menu

  • Hire

Set user's edit form display mode.

If you need to load a specific form mode for the user's edit-form then you can do like below

Step 1: Create the services file e.g gym_misc.services.yml to register the routing event subscriber

services:
  gym_misc.route_subscriber:
    class: Drupal\gym_misc\Routing\RouteSubscriber
    tags:
      - { name: event_subscriber }

Step 2: Create the event subscriber class src/Routing/RouteSubscriber.php and modify the user edit routing to load your form mode. I am setting it to user.register form mode for edit form.

<?php

namespace Drupal\gym_misc\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get("entity.user.edit_form")) {
      $route->setDefault('_entity_form', 'user.register');
    }
  }
}

 

About us

We are a web development company. We have vast excperience in building web sites in Drupal CMS. We develop simple website to complex system to meet the client requirements.

 

Follow us

  facebook twitter instagram linkedin