Updated as per #19

Problem/Motivation

RSS feed of term page contains local URL.

Proposed resolution

We can fix it either way.

  1. Add RSS link formatter to taxonomy.
  2. Add option to taxonomy link formatter to show absolute url.
  3. If view mode is RSS change the taxonomy link formatter url to absolute.

Remaining tasks

Agree on the solution.
Patch for solution:

  1. 1 is in #5
  2. 2 is in #18
  3. 3 is in #19

User interface changes

For option:

  1. 1 field_tags formatter should be changed.
  2. 2 field_tags formatter should check the absolute URL option.
  3. 3 None.

API changes

For option:

  1. 1 adds new taxonomy formatter.
  2. 2 adds new option to the existing taxonomy link formatter.
  3. 3 just converts the url to absolute if view mode is RSS.

Original report by @wuinfo

When generating taxonomy feed under "taxonomy/term/%taxonomy_term/feed", Drupal rendered tag URL without using absolute URL. As result, RSS feed contains local URL of the taxonomy terms.

This cause other sites using the feed have problem of "404 page not found" on those taxonomy terms.

Here are example links from Acquia Drupal Planet.

https://www.drupal.org/aggregator/sources/174

https://www.drupal.org/resources/drupal-sprint (404 page not found)
https://www.drupal.org/resources/global-sprint-weekend (404 page not found)
https://www.drupal.org/resources/acquia-drupal-planet (404 page not found)

I have attached a patch to this issue.

The patch adds a new field format that render the link in absolute format.

Before

After

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Unfrozen changes Unfrozen because it is a bug fix
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wuinfo - Bill Wu’s picture

Issue summary: View changes
wuinfo - Bill Wu’s picture

Issue summary: View changes
wuinfo - Bill Wu’s picture

Status: Active » Needs review
wuinfo - Bill Wu’s picture

Images of before and after fix uploaded.

wuinfo - Bill Wu’s picture

Version: 7.x-dev » 8.0.x-dev
FileSize
2.26 KB

This is the patch for 8.0.x

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Needs backport to D7, +Needs tests

@wuinfo confirmed that the problem exists in both D8 and D7. Thanks!

Something we definitely need here is an automated test that fails with the bug in HEAD, and passes with the patch applied.

It'd also help to have step-by-step testing instructions and before/after samples of the feed contents (screenshots, whatever). Another thing that's also not clear to me is whether this only affects taxonomy feed items -- can we confirm that the problem does not exist elsehwere? Are there other items in core we should check? Thanks!

wuinfo - Bill Wu’s picture

Thanks @xjm.

The problem is the default field link is rendered relative url into feed.

The patch is give an option of "Rss Link". The new option will render the taxonomy term link into absolute URL.

xjm’s picture

Issue summary: View changes

Oops, I missed that screenshots are already attached! Embedding them here.

Before

After

wuinfo - Bill Wu’s picture

Issue tags: -Needs tests
FileSize
78.38 KB

Hi @xjm, I removed "Needs tests" tag for this issue.

Interface of the configuration

This patch adds "RSS Link" option in admin/structure/types/manage/article/display . There are no test script for existing options like "Link" and "Plain text".

wuinfo - Bill Wu’s picture

Title: Add feed link display for taxonomy term reference field » Add "RSS Link" formatter for taxonomy term reference field
xjm’s picture

@wuinfo, there are definitely gaps in our existing test coverage. However, per our core testing gate, bugfixes need to be accompanied by a test that will prevent the bug from regressing in the future.

Thanks for the screenshot!

xjm’s picture

Issue tags: +Needs tests

Confirmed with @alexpott that a bug fix here would need a test.

jibran’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.85 KB
1.85 KB

I think creating a new formatter is not a good solution. I think we should add absolute option to existing link formatter to show the absolute url.

jibran’s picture

FileSize
3.91 KB

:/

The last submitted patch, 13: 2428147-13-test-only.patch, failed testing.

The last submitted patch, 13: 2428147-13.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 14: 2428147-14.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
1.81 KB
5.75 KB

I thought I had also added the schema changes.

jibran’s picture

Title: Add "RSS Link" formatter for taxonomy term reference field » taxonomy/term/%taxonomy_term/feed should so absolute URL
Issue summary: View changes
Issue tags: +Field API
FileSize
678 bytes
2.51 KB

Here is new and simple fix. Updated IS and added BE.

jibran’s picture

Title: taxonomy/term/%taxonomy_term/feed should so absolute URL » Taxonomy term feed in not showing absolute URL
Issue summary: View changes

Better title. FWIW I think #19 is much better option then all others.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

nice

wuinfo - Bill Wu’s picture

Thanks @xjm, Thanks jibran.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/taxonomy/src/Plugin/Field/FieldFormatter/LinkFormatter.php
@@ -56,6 +56,10 @@ public function viewElements(FieldItemListInterface $items) {
+        if ($this->viewMode == 'rss') {
+          $elements[$delta]['#url']->setAbsolute();
+        }
+

I don;t think this is the correct fix. There could be other view modes that need absolute urls.

wuinfo - Bill Wu’s picture

FileSize
1.58 KB

Hi @alexpott,

Patches at in #5 and #18 let other view modes to use the absolute URLs. Both for Drupal 8

Here is the patch for Drupal 7 attached to this comment. This Drupal 7 patch is a similar solution to #5 patch for Drupal 8.

wuinfo - Bill Wu’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: taxonomy_term_feed_url.patch, failed testing.

wuinfo - Bill Wu’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Needs work » Needs review

In order to check the patch at #24 with Drupal 7 version. Change the version to 7.x-dev, will change it back later.

wuinfo - Bill Wu’s picture

Version: 7.x-dev » 8.0.x-dev
jibran’s picture

Version: 8.0.x-dev » 7.x-dev
Issue tags: -Needs backport to D7, -Field API

From EntityReferenceTaxonomyTermRssFormatter::viewElements()


  public function viewElements(FieldItemListInterface $items) {
    $parent_entity = $items->getEntity();
    $elements = array();

    foreach ($this->getEntitiesToView($items) as $delta => $entity) {
      $parent_entity->rss_elements[] = array(
        'key' => 'category',
        'value' => $entity->label(),
        'attributes' => array(
          'domain' => $entity->id() ? \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $entity->id()], array('absolute' => TRUE)) : '',
        ),
      );
    }

See absolute => true it is fixed in D8 HEAD
Moving back to D7.

ron_s’s picture

The patch in #24 works for us, but it should be modified to match the changes being made in this issue: https://www.drupal.org/node/2128265

I'm including a new patch for review that makes these updates.

ron_s’s picture

FYI, issue #2128265 is postponed, so the patch I created for #31 is no longer valid. Please review patch #24 instead.