Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions domain_source/config/install/domain_source.settings.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
exclude_routes: {}
dont_redirect_on_aliases: 0
3 changes: 3 additions & 0 deletions domain_source/config/schema/domain_source.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ domain_source.settings:
sequence:
type: string
label: 'Route'
dont_redirect_on_aliases:
type: boolean
label: 'Stop redirecting on aliases'
6 changes: 6 additions & 0 deletions domain_source/src/Form/DomainSourceSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#options' => $options,
'#description' => $this->t('Check the routes to disable. Any entity URL with a Domain Source field will be rewritten unless its corresponding route is disabled.'),
];
$form['dont_redirect_on_aliases'] = [
'#type' => 'checkbox',
'#title' => t('Don\'t redirect to the primary domain on aliases'),
'#default_value' => $config->get('dont_redirect_on_aliases')
];
return parent::buildForm($form, $form_state);
}

Expand All @@ -58,6 +63,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('domain_source.settings')
->set('exclude_routes', $form_state->getValue('exclude_routes'))
->set('dont_redirect_on_aliases', $form_state->getValue('dont_redirect_on_aliases'))
->save();

parent::submitForm($form, $form_state);
Expand Down
4 changes: 3 additions & 1 deletion domain_source/src/HttpKernel/DomainSourcePathProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public function __construct(DomainNegotiatorInterface $negotiator, ModuleHandler
* {@inheritdoc}
*/
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
$config = $this->configFactory->get('domain_source.settings');

// Load the active domain if not set.
if (empty($options['active_domain'])) {
$active_domain = $this->getActiveDomain();
Expand Down Expand Up @@ -173,7 +175,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL,
$this->moduleHandler->alter('domain_source_path', $source, $path, $options);
}
// If a source domain is specified, rewrite the link.
if (!empty($source)) {
if (!empty($source) && (!$config->get('dont_redirect_on_aliases') || ($config->get('dont_redirect_on_aliases') && $source->id() != $options['active_domain']->id()))) {
// Note that url rewrites add a leading /, which getPath() also adds.
$options['base_url'] = trim($source->getPath(), '/');
$options['absolute'] = TRUE;
Expand Down