As like in drupal.org, I want to link comments related to the corresponding node's alias i.e., /node-alias#comment-id, instead of seperate link /comment/id.
For Drupal 7, comment_fragment module does the job.

Is there any possibilities to achieve the same in Drupal 8/9 via theme or template hook?

Please guide me.

Comments

mkrkarthi created an issue. See original summary.

cilefen’s picture

Related issues: +#3095144: D8 Version?

I think this is a duplicate 🧐

mkrkarthi’s picture

Title: How to change comment permalinks from comment/ to alias as like drupal.org? » Changing comment permalinks from comment/ to alias as like drupal.org?

@cilefen, That issue was created for a contributed module. I expect a solution from Drupal core itself. Since, it is implemented in Drupal.org, I hope there is a way to do it via theme.

in comment.html.twig

 <div{{ content_attributes.addClass('comment__content') }}>
    {% if title %}
      {{ title_prefix }}
      <h3{{ title_attributes }}>{{ title }}</h3>
      {{ title_suffix }}
    {% endif %}
    {{ content }}    
  </div>

{{title}} sample output is
<a href="/comment/41#comment-41" class="permalink" rel="bookmark" hreflang="und">Sample Comment</a>
It needs to be changed like
<a href="#comment-41" class="permalink" rel="bookmark" hreflang="und">Sample Comment</a>
Or
<a href="/node-alias#comment-41" class="permalink" rel="bookmark" hreflang="und">Sample Comment</a>

cilefen’s picture

mkrkarthi’s picture

Yes, drupal.org uses comment_fragment
https://www.drupal.org/project/drupalorg/issues/2677860#comment-13980109

Not yet ported to Drupal 8/9.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

cilefen’s picture

Status: Active » Closed (works as designed)