Skip to content

Instantly share code, notes, and snippets.

@maciejzgadzaj
Last active November 7, 2015 09:08
Show Gist options
  • Save maciejzgadzaj/41022acc23ced950f1c7 to your computer and use it in GitHub Desktop.
Save maciejzgadzaj/41022acc23ced950f1c7 to your computer and use it in GitHub Desktop.
Domain Access on Platform.sh
/**
* Implements hook_domain_default_domains().
*/
function MYMODULE_domain_default_domains() {
$domains = array();
$domains['wipe-domain-tables'] = 'wipe-domain-tables';
$routes = (array) json_decode(base64_decode(getenv('PLATFORM_ROUTES')));
if (!empty($routes) && is_array($routes)) {
$weight = -1;
foreach ($routes as $url => $route) {
if (
$route->upstream == 'drupal'
&& preg_match('/^(https?):\/\/([a-z0-9\.-]+)\/$/', $url, $matches)
&& preg_match('/^https?:\/\/([a-z]+).{default}\/$/', $route->original_url, $matches2)
) {
$scheme = $matches[1];
$domain_name = $matches[2];
$machine_name = $matches2[1];
$domains[$machine_name] = array(
'subdomain' => $domain_name,
'sitename' => MYMODULE_get_sitename($machine_name),
'scheme' => $scheme,
'valid' => 1,
'weight' => $weight++,
'is_default' => ($machine_name == 'www' ? 1 : 0),
'machine_name' => $machine_name,
);
}
}
}
return $domains;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment