diff --git a/humanstxt.module b/humanstxt.module index 69f589c..0c880da 100644 --- a/humanstxt.module +++ b/humanstxt.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Url; /** * Implements hook_help(). @@ -47,3 +48,17 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) { } } +/** + * Implements hook_page_attachments(). + */ +function humanstxt_page_attachments(array &$attachments) { + // Testing the current value of the config item to insert the link. + if (\Drupal::config('humanstxt.settings')->get('display_link')) { + + // Getting the absolute path to the humans.txt file. + $humanstxt_path = Url::fromRoute('humanstxt.content', [], ['absolute' => TRUE])->toString(); + + // Adding new head link tag as in RenderAttachedTestController::htmlHeaderLink + $attachments['#attached']['html_head_link'][] = [['rel' => 'author', 'type' => 'text/plain', 'hreflang' => 'x-default', 'href' => $humanstxt_path], TRUE]; + } +}