Drupal-NYC / drupalcampnyc

Site
GNU General Public License v2.0
7 stars 5 forks source link

Set $primary_domain to Pantheon Live. #189

Closed hotwebmatter closed 3 years ago

hotwebmatter commented 3 years ago

Temporarily disable the redirect from Pantheon Live domain to static site.

hotwebmatter commented 3 years ago

So simple! Unfortunately I think this would redirect folks visiting www or bare domain to live- (they should go to 2020 for now)

Good catch -- I thought that seemed too simple! This is why we have code review.

I think I have an idea that would make it work correctly, but I'll need to check getHost().

I did this in a service class recently, but I used dependency injection:

use Symfony\Component\HttpFoundation\RequestStack;

[skip a bunch of DI boilerplate]

$host = $this->requestStack->getCurrentRequest()->getHost();
switch ($host) {
  case 'live-drupalcampnyc.pantheonsite.io':
    $primary_domain = 'live-drupalcampnyc.pantheonsite.io';
    break;
  default:
    $primary_domain = '2020.drupalcamp.nyc';
    break;
}

I'm not sure what's the best practice for service injection in settings.php, but I suspect it is outside of a class context (like the .module file) so services must be loaded statically.

Usually, host environment variables are sufficient for this sort of thing. It's rare to have conditional logic depending on hostname.

I could make a case for implementing these redirects as a custom module, rather than in settings.php.

Or I could just try something like this:

$host = \Drupal::request()->getCurrentRequest()->getHost();

Does that look like it should work? I hesitate to do that in the production environment without testing it in a lower environment.

jdleonard commented 3 years ago

I think we might find a simpler solution :)

Could we just replace:

if ($_SERVER['HTTP_HOST'] != $primary_domain) {

with

if ($_SERVER['HTTP_HOST'] != $primary_domain && $_SERVER['HTTP_HOST'] != 'live-drupalcampnyc.pantheonsite.io') {