diff --git a/src/Drupal/Driver/Fields/Drupal8/LinkHandler.php b/src/Drupal/Driver/Fields/Drupal8/LinkHandler.php index a6c87bf..1eb8e1b 100644 --- a/src/Drupal/Driver/Fields/Drupal8/LinkHandler.php +++ b/src/Drupal/Driver/Fields/Drupal8/LinkHandler.php @@ -13,6 +13,20 @@ class LinkHandler extends AbstractHandler { public function expand($values) { $return = []; foreach ($values as $value) { + $uri = $value[1]; + + // If the uri has no scheme (and is not protocol relative) attempt to find + // a node with that label. + if (empty($uri_parts['scheme']) && strpos($uri, '//') !== 0) { + $entity_type_id = 'node'; + $query = \Drupal::entityQuery($entity_type_id)->condition('title', $uri); + $entities = $query->execute(); + if (!empty($entities)) { + $nid = array_shift($entities); + $uri = 'entity:' . $entity_type_id . '/' . $nid; + } + } + // 'options' is required to be an array, otherwise the utility class // Drupal\Core\Utility\UnroutedUrlAssembler::assemble() will complain. $options = []; @@ -22,7 +36,7 @@ public function expand($values) { $return[] = [ 'options' => $options, 'title' => $value[0], - 'uri' => $value[1], + 'uri' => $uri, ]; } return $return;