Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
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 (Drupal & Laravel)

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

Web Posts

Search

Page Facebook