Skip to content

Commit 8e3b562

Browse files
authored
Merge pull request #3 from dof-dss/development
Release to main
2 parents 7ba31d8 + 9db3d20 commit 8e3b562

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

unity_internal_link_checker/src/Form/LinkCheckerForm.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function getFormId() {
3232
public function buildForm(array $form, FormStateInterface $form_state) {
3333
$config = $this->config('unity_internal_link_checker.linksettings');
3434

35-
$message = "List all domain names here that must be stripped out of absolute links and changed to relative as they are saved.";
35+
$message = "All environment domains (Local, Edge, UAT, Main) are already being stripped of absolute links and changed to relative for this site.";
36+
$message .= "<br/>List any extra domain names here that must be stripped out of absolute links and changed to relative as they are saved.";
3637
$message .= "<br/>For example adding 'http://uregni.gov.uk' here will cause any links starting with that domain name to be saved as relative links instead.";
3738
$message .= "<br/>You may add as many domain names as you like, along with the appropriate 'http' or 'https' protocol.";
3839

unity_internal_link_checker/unity_internal_link_checker.module

+31-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
use Drupal\Core\Entity\ContentEntityInterface;
99
use Drupal\Core\Entity\EntityInterface;
10-
use Drupal\migrate\MigrateException;
11-
use Drupal\views\Entity\View;
1210

1311
/**
1412
* Implements hook_entity_presave().
@@ -54,9 +52,10 @@ function _convert_absolute_link(&$body_text, $original_link) {
5452
// (these have been added at
5553
// /admin/config/unity_internal_link_checker/link_checker_form )
5654
$config = \Drupal::config('unity_internal_link_checker.linksettings');
57-
$replace_url_list = $config->get('site_url_list');
55+
$replace_url_list = _urls_to_replace() . $config->get('site_url_list');
5856
if (strlen($replace_url_list) == 0) {
59-
\Drupal::messenger()->addMessage(t("Please set some URLs at /admin/config/unity_internal_link_checker/link_checker_form"), "error");
57+
\Drupal::messenger()
58+
->addMessage(t("Please set some URLs at /admin/config/unity_internal_link_checker/link_checker_form"), "error");
6059
return $body_text;
6160
}
6261
$replace_url_list = explode(PHP_EOL, $replace_url_list);
@@ -77,3 +76,31 @@ function _convert_absolute_link(&$body_text, $original_link) {
7776
}
7877
return $body_text;
7978
}
79+
80+
/**
81+
* Utility function to add all domains and extensions for the current site.
82+
*/
83+
function _urls_to_replace(): string {
84+
// Get the host name of the site and remove the domain extension.
85+
$host = \Drupal::request()->getHost();
86+
if (preg_match('/\S*?(uk|org|com|net|eu)/', $host, $matches)) {
87+
$host = $matches[0];
88+
}
89+
// List all domain protocols and extensions for our platform and local environments.
90+
$protocols = ['http://', 'http://www.', 'https://', 'https://www.'];
91+
$extensions = [
92+
'.lndo.site/',
93+
'.d8un-edge-xerfxyi-6tlkpwbr6tndk.uk-1.platformsh.site/',
94+
'.d8un-uat-qhl74ni-6tlkpwbr6tndk.uk-1.platformsh.site/',
95+
'.main-bvxea6i-6tlkpwbr6tndk.uk-1.platformsh.site/',
96+
'/',
97+
];
98+
$urls_to_replace = '';
99+
// Loop through and add all protocols and extensions to the current site.
100+
foreach ($protocols as $protocol) {
101+
foreach ($extensions as $extension) {
102+
$urls_to_replace .= $protocol . $host . $extension . "\r\n";
103+
}
104+
}
105+
return $urls_to_replace;
106+
}

0 commit comments

Comments
 (0)