class RedirectDestination in Bakery Single Sign-On System 8.2
Hierarchy
- class \Drupal\bakery\RedirectDestination implements RedirectDestinationInterface
Expanded class hierarchy of RedirectDestination
1 string reference to 'RedirectDestination'
1 service uses RedirectDestination
File
- src/
RedirectDestination.php, line 12
Namespace
Drupal\bakeryView source
class RedirectDestination implements RedirectDestinationInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* Bakery settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* Destination service.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $redirectDestination;
/**
* The destination used by the current request.
*
* @var \Drupal\Core\Url|string
*/
protected $destination;
/**
* Constructs a new RedirectDestination instance.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The URL generator.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Configuration factory.
* @param \Drupal\Core\Routing\RedirectDestinationInterface|null $destination
* Core destination redirect destination service.
*/
public function __construct(RequestStack $request_stack, UrlGeneratorInterface $url_generator, ConfigFactoryInterface $config_factory, RedirectDestinationInterface $destination = NULL) {
$this->requestStack = $request_stack;
$this->urlGenerator = $url_generator;
$this->config = $config_factory
->get('bakery.settings');
$this->redirectDestination = $destination ?? \Drupal::destination();
}
/**
* {@inheritdoc}
*/
public function get() {
if (!isset($this->destination)) {
if ($this->config
->get('bakery_is_master')) {
$this->destination = $this
->getChildDestination();
}
else {
$this->destination = $this
->getParentDestination();
}
}
if ($this->destination instanceof Url) {
return $this->destination
->toString();
}
return $this->destination;
}
/**
* Get link to destination on current site for parent.
*
* @return \Drupal\Core\Url
*/
private function getParentDestination() {
$query = $this->requestStack
->getCurrentRequest()->query;
if ($query
->has('bd')) {
// @TODO do something?
}
return Url::fromRoute('<current>')
->setAbsolute(TRUE);
}
/**
* Get link to destination on referring child.
*
* @return \Drupal\Core\Url
*/
private function getChildDestination() {
$query = $this->requestStack
->getCurrentRequest()->query;
if ($query
->has('bd')) {
$external_uri = $query
->get('bd');
if (is_string($external_uri) && ($external_uri = UrlHelper::stripDangerousProtocols($external_uri))) {
foreach ($this->config
->get('bakery_slaves') as $subsite) {
if (str_starts_with($external_uri, $subsite)) {
return Url::fromUri(urldecode($external_uri))
->setAbsolute(TRUE);
}
}
}
}
return Url::fromRoute('<front>')
->setAbsolute(TRUE);
}
/**
* {@inheritdoc}
*/
public function getAsArray() {
// TODO...
return [
'bd' => $this
->get(),
];
}
/**
* {@inheritdoc}
*/
public function set($new_destination) {
$this->destination = $new_destination;
return $this;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RedirectDestination:: |
protected | property | Bakery settings. | |
RedirectDestination:: |
protected | property | The destination used by the current request. | |
RedirectDestination:: |
protected | property | Destination service. | |
RedirectDestination:: |
protected | property | The request stack. | |
RedirectDestination:: |
protected | property | The URL generator. | |
RedirectDestination:: |
public | function |
Gets the destination as a path. Overrides RedirectDestinationInterface:: |
|
RedirectDestination:: |
public | function |
Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. Overrides RedirectDestinationInterface:: |
|
RedirectDestination:: |
private | function | Get link to destination on referring child. | |
RedirectDestination:: |
private | function | Get link to destination on current site for parent. | |
RedirectDestination:: |
public | function |
Sets the destination as URL. Overrides RedirectDestinationInterface:: |
|
RedirectDestination:: |
public | function | Constructs a new RedirectDestination instance. |