public function LoginDestinationManager::prepareDestination in Login Destination 8.2
Same name and namespace in other branches
- 8 src/LoginDestinationManager.php \Drupal\login_destination\LoginDestinationManager::prepareDestination()
Prepare request destination provided by login destination rule.
Parameters
\Drupal\login_destination\Entity\LoginDestination $destination: Login destination rule.
Overrides LoginDestinationManagerInterface::prepareDestination
File
- src/
LoginDestinationManager.php, line 176
Class
- LoginDestinationManager
- Defines a login destination manager service.
Namespace
Drupal\login_destinationCode
public function prepareDestination(LoginDestination $destination) {
// Get config with settings.
$config = $this->configFactory
->get('login_destination.settings');
if ($config
->get('preserve_destination')) {
// Get current destination value.
$drupal_destination = $this->requestStack
->getCurrentRequest()->query
->get('destination');
if (UrlHelper::isExternal($drupal_destination)) {
$drupal_destination = NULL;
}
// Determine if a destination exist in the URL.
if (!empty($drupal_destination)) {
return;
}
}
// Prepare destination path.
$path = $this->token
->replace($destination
->getDestination());
// Check if rules refers to the current page.
if ($destination
->isDestinationCurrent()) {
$request = $this->requestStack
->getCurrentRequest();
$query = $request
->get('current');
$path_destination = !empty($query) ? $query : '';
}
else {
$path_destination = Url::fromUri($path)
->toString();
}
// Set destination to current request.
$this->requestStack
->getCurrentRequest()->query
->set('destination', $path_destination);
}