Skip to main content
Category:

User Login Persistent Destination in drupal 

 

/**
 * Implements hook_menu_local_tasks_alter().
 */
function Module_local_tasks_alter(array &$data, $route_name, RefinableCacheableDependencyInterface $cacheability) {
  if ($route_name == 'user.login' || $route_name == 'user.register') {
    // Vary cache by ?destination query argument.
    $cacheability->addCacheContexts(['url.query_args:destination']);

    // Get the 'destination' query argument from current request.
    $destination = \Drupal::request()->query->get('destination');
    if (empty($destination)) {
      // No destination set for current request - we can exit now.
      return;
    }
    foreach ($data['tabs'] as $items) {
      foreach ($items as $item) {
        /** @var \Drupal\Core\Url $url */
        $url = $item['#link']['url'];
        $query_arguments = $url->getOption('query');
        if (is_null($query_arguments)) {
          $query_arguments = [];
        }
        $query_arguments['destination'] = $destination;
        $url->setOption('query', $query_arguments);
      }
    }
  }
}

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook