Skip to content

Commit e5201cb

Browse files
authored
Merge pull request #31 from dof-dss/development
Release 0.1.1
2 parents f8b606e + 1aa1da1 commit e5201cb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

unity_internal_link_checker/unity_internal_link_checker.module

+9-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function unity_internal_link_checker_entity_presave(EntityInterface $entity) {
1919
}
2020
if ($entity instanceof ContentEntityInterface) {
2121
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;
2424

2525
$matches = [];
2626
// Look for all anchors in the body field.
@@ -37,8 +37,7 @@ function unity_internal_link_checker_entity_presave(EntityInterface $entity) {
3737
$body = _convert_absolute_link($body, $original_link);
3838
}
3939
}
40-
41-
$entity->set('body', ['value' => $body, 'format' => $format]);
40+
$entity->body->setValue(['value' => $body, 'format' => $format]);
4241
}
4342
}
4443
}
@@ -84,9 +83,14 @@ function _convert_absolute_link(&$body_text, $original_link) {
8483
function _urls_to_replace(): string {
8584
// Get the host name of the site and remove the domain extension.
8685
$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)) {
8887
$host = $matches[0];
8988
}
89+
else {
90+
if (preg_match('/\S*?\.(org)/', $host, $matches)) {
91+
$host = $matches[0];
92+
}
93+
}
9094
// List all domain protocols and extensions for our platform and local environments.
9195
$protocols = ['http://', 'http://www.', 'https://', 'https://www.'];
9296
$extensions = [

0 commit comments

Comments
 (0)