@@ -19,8 +19,8 @@ function unity_internal_link_checker_entity_presave(EntityInterface $entity) {
19
19
}
20
20
if ($entity instanceof ContentEntityInterface) {
21
21
if ($entity->hasField('body')) {
22
- $body = $entity->get('body')->value ?? '' ;
23
- $format = $entity->get('body')->format ?? '' ;
22
+ $body = $entity->get('body')->value;
23
+ $format = $entity->get('body')->format;
24
24
25
25
$matches = [];
26
26
// Look for all anchors in the body field.
@@ -37,8 +37,7 @@ function unity_internal_link_checker_entity_presave(EntityInterface $entity) {
37
37
$body = _convert_absolute_link($body, $original_link);
38
38
}
39
39
}
40
-
41
- $entity->set('body', ['value' => $body, 'format' => $format]);
40
+ $entity->body->setValue(['value' => $body, 'format' => $format]);
42
41
}
43
42
}
44
43
}
@@ -84,9 +83,14 @@ function _convert_absolute_link(&$body_text, $original_link) {
84
83
function _urls_to_replace(): string {
85
84
// Get the host name of the site and remove the domain extension.
86
85
$host = \Drupal::request()->getHost();
87
- if (preg_match('/\S*?(uk|org |com|net|eu)/', $host, $matches)) {
86
+ if (preg_match('/\S*?\. (uk|com|net|eu)/', $host, $matches)) {
88
87
$host = $matches[0];
89
88
}
89
+ else {
90
+ if (preg_match('/\S*?\.(org)/', $host, $matches)) {
91
+ $host = $matches[0];
92
+ }
93
+ }
90
94
// List all domain protocols and extensions for our platform and local environments.
91
95
$protocols = ['http://', 'http://www.', 'https://', 'https://www.'];
92
96
$extensions = [
0 commit comments