diff --git a/humanstxt.module b/humanstxt.module index 69f589c..3467842 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,19 @@ 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 current front path and adding the filename to the path. + $humanstxt_path = (\Drupal::request()->getSchemeAndHttpHost()) . + (Url::fromRoute('humanstxt.content')->toString()); + + // Adding the new head link tag. + // Looks some weird but respects the form from: RenderAttachedTestController::htmlHeaderLink + $attachments['#attached']['html_head_link'][] = [['rel' => 'author', 'type' => 'text/plain', 'hreflang' => 'x-default', 'href' => $humanstxt_path], TRUE]; + } +}