Commit b859d900 authored by Tawny Bartlett's avatar Tawny Bartlett Committed by Yaroslav Samoilenko
Browse files

Issue #3258961: Module checks for "/user" path rather than route name

parent 23d5668e
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -202,8 +202,10 @@ function multiple_registration_form_alter(&$form, FormStateInterface $form_state
    }
  }

  $route = \Drupal::routeMatch()->getRouteObject();
  if ($route !== NULL && $route->getPath() === '/user/register/{rid}') {
  $route_match = \Drupal::routeMatch();
  $route = $route_match->getRouteObject();
  $route_name = $route_match->getRouteName();
  if ($route !== NULL && $route_name == 'multiple_registration.role_registration_page') {
    $rid = \Drupal::routeMatch()->getParameter('rid');

    // Hidden field to pass the rid.
@@ -359,21 +361,23 @@ function multiple_registration_block_view_user_login_block_alter(array &$build,
 * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
 */
function multiple_registration_entity_form_display_alter(EntityFormDisplayInterface &$form_display, array $context) {
  $route = \Drupal::routeMatch()->getRouteObject();
  $route_match = \Drupal::routeMatch();
  $route = $route_match->getRouteObject();
  $route_name = $route_match->getRouteName();
  if ($route !== NULL) {
    $is_user_register_form = $route->getPath() === '/user/register/{rid}' && $context['form_mode'] === 'register';
    $is_user_edit_form = $route->getPath() === '/user/{user}/edit' && $context['form_mode'] === 'default';
    $is_user_register_form = $route_name === 'multiple_registration.role_registration_page' && $context['form_mode'] === 'register';
    $is_user_edit_form = $route_name === 'entity.user.edit_form' && $context['form_mode'] === 'default';

    if ($context['entity_type'] === 'user' && ($is_user_register_form || $is_user_edit_form)) {
      $config = \Drupal::config('multiple_registration.create_registration_page_form_config');

      switch ($route->getPath()) {
        case '/user/register/{rid}':
      switch ($route_name) {
        case 'multiple_registration.role_registration_page':
          $rid = \Drupal::routeMatch()->getParameter('rid');
          $custom_form_mode = $config->get('multiple_registration_form_mode_register_' . $rid) ?: 'register';
          break;

        case '/user/{user}/edit':
        case 'entity.user.edit_form':
          // Current user id from the route context.
          $user_entity_from_route = \Drupal::routeMatch()->getParameters()->all()['user'];
          /** @var \Drupal\user\Entity\User $user_entity_from_route */