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);
      }
    }
  }
}

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon