Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davidjguru created an issue. See original summary.

davidjguru’s picture

I provide this patch with a solution adapted to Drupal 8, using the property #attached from inside a hook page_attachments() in a .module file.

davidjguru’s picture

Status: Active » Needs review
pcambra’s picture

Status: Needs review » Needs work

Many thanks! here are a few nitpicks with the patch.

  1. +++ b/humanstxt.module
    @@ -6,6 +6,8 @@
    +use Drupal\Core\Link;
    

    This seems unused

  2. +++ b/humanstxt.module
    @@ -47,3 +49,31 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) {
    +  $display_link_in_header = \Drupal::config('humanstxt.settings')
    

    This doesn't need to be break into multiple lines.

  3. +++ b/humanstxt.module
    @@ -47,3 +49,31 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) {
    +  if($display_link_in_header == TRUE) {
    

    Nitpick, missing space after "if" and it's not needed to compare with TRUE, maybe you could directly do "if ($display_link_in_header = \Drupal::config('humanstxt.settings')->get('display_link')) {" instead

  4. +++ b/humanstxt.module
    @@ -47,3 +49,31 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) {
    +    $current_front_url = Url::fromRoute('<front>');
    +    $current_front_path = $current_front_url->toString();
    +
    +    // Adding the filename to the path.
    

    No need of all these variables, you could do the string concatenation in one or two lines.

  5. +++ b/humanstxt.module
    @@ -47,3 +49,31 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) {
    +    $humanstxt_path = $current_front_path . "humans.txt";
    

    Shouldn't this be ".humans.txt"?

  6. +++ b/humanstxt.module
    @@ -47,3 +49,31 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) {
    +    $attachments['#attached']['html_head_link'][] = [$link_description];
    

    Again, the $link description variable is not reused, you could just assign the array directly without extra variables.

pcambra’s picture

After reviewing #3102492: Make some small adjustments in Routing, I think it would be useful to create a humans.txt route in the routing files, what do you think?

davidjguru’s picture

Hi,
I've revised the former patch and prepared a new version, just a lighter iteration based on all the notes and 'nitpicks' from the feedback.
This works fine and creates the link to the file using less code.

Greetings,

David.

davidjguru’s picture

Status: Needs work » Needs review
pcambra’s picture

Status: Needs review » Needs work

Thanks, a couple of comments below:

  1. +++ b/humanstxt.module
    @@ -47,3 +47,20 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) {
    +    $humanstxt_path =  \Drupal::request()->getSchemeAndHttpHost(). "/humans.txt";
    

    This is what I meant with the route, we probably want to create a route in the routing.yml so we don't need to do this.

  2. +++ b/humanstxt.module
    @@ -47,3 +47,20 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) {
    +    $attachments['#attached']['html_head_link'][] = [['rel' => 'author',
    +                                                     'link' => $humanstxt_path,
    +                                                     ]];
    

    Please review the coding standards regarding arrays as I don't think this follows them.

davidjguru’s picture

I just uploaded a new version of the patch using the new route from the routing file and building the link to the humans.txt file using the format marked as in: web/core/modules/system/tests/modules/render_attached_test/src/Controller/RenderAttachedTestController.php
(https://api.drupal.org/api/drupal/core%21modules%21system%21tests%21modules%21render_attached_test%21src%21Controller%21RenderAttachedTestController.php/function/RenderAttachedTestController%3A%3AhtmlHeaderLink/8.8.x)

davidjguru’s picture

Status: Needs work » Needs review
pcambra’s picture

Status: Needs review » Postponed
Related issues: +#3119943: Define a new controller

Postponing this until we get the controller in

pcambra’s picture

Status: Postponed » Needs work

I think this is unlocked now, not sure if the patch needs to be changed, feel free to change the status to NR.

davidjguru’s picture

I'm reloading the patch, I've reduced a string in a comment.
You can test with this.

davidjguru’s picture

Status: Needs work » Needs review
pcambra’s picture

Status: Needs review » Needs work
+++ b/humanstxt.module
@@ -47,3 +48,18 @@ function humanstxt_help($route_name, RouteMatchInterface $route_match) {
+    // Getting the current front path and adding the filename to the path.
+    $humanstxt_path =  (\Drupal::request()->getSchemeAndHttpHost()) .
+      (Url::fromRoute('humanstxt.content')->toString());

Now that I look this on detail, you can do fromRoute and then send absolute=>TRUE in the options array for getting the full URL.

davidjguru’s picture

I just reload a new version of the patch with the mentioned changed in the fromRoute method.

Please, review.

Greetings,
David.

davidjguru’s picture

Status: Needs work » Needs review
davidjguru’s picture

Assigned: davidjguru » Unassigned

  • pcambra committed 73a0662 on 8.x-1.x authored by davidjguru
    Issue #3104647 by davidjguru, pcambra: Create the link to humans.txt in...
pcambra’s picture

Status: Needs review » Fixed

Pushed with a few changes, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.