Problem/Motivation

After reviewing #3292996: Create a skeleton for the individual module page, we found out that the body contains many relative URLs which the D7 www.drupal.org does not transform when serving the data, so we should take care of this within the plugin.

I think that a good place to do this would be the "getProjects" method inside the Mock plugin. In there, we massage the data to be in the right format, so we take what the api gives us, and tweak it to what project_browser needs (ie: we transform taxonomy_vocabulary_46 into field_development_status). So I think that'd be a good place to put something like this:

$project['body'] = $this->relativeToAbsoluteLinks($project['body'], 'https://www.drupal.org');

Which would take the body and a base URL and then prepend that to any part of the $project['body']['value'] that contains a relative URL. See the answer to this question in stackoverflow as reference: https://stackoverflow.com/questions/48836281/replace-all-relative-urls-w...

This could be filed as a separate issue altogether, but I think that shipping a page that looks like the below would look weird:
Broken images

Steps to reproduce

See the above image when testing the parent issue.

Proposed resolution

Convert relative URLs to absolute.

Remaining tasks

  • ✅ File an issue about this project
  • ☐ Manual Testing
  • ☐ Code Review
  • ☐ Accessibility Review
  • ☐ Automated tests needed/written?
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fjgarlin created an issue. See original summary.

fjgarlin’s picture

Assigned: fjgarlin » Unassigned
Status: Active » Needs review

Marking as need review.

In order to test:
* Spin up drupalpod or testing environment of choice
* Open up this URL "/drupal-org-proxy/project?page=0&limit=1&search=webform" in a new tab. It should have the "Webform" module information in json format.
* Inspect the body field for "src" attributes on "/files/..." URLs and they should all be absolute.
* If you do the same in an environment without the patch, you'll see that the URLs are relative.

In order to test visually, this #3292996: Create a skeleton for the individual module page would need to be merged, but this issue can go before that one too as we can test with the above instructions.

srishtiiee’s picture

Status: Needs review » Reviewed & tested by the community

Tested the patch manually, all the relative URL's are converted to absolute. Marking RTBC.

tim.plunkett made their first commit to this issue’s fork.

  • tim.plunkett committed 9e66d94 on 1.0.x authored by fjgarlin
    Issue #3298575 by fjgarlin, srishtiiee: URLs in body for projects are...
tim.plunkett’s picture

Status: Reviewed & tested by the community » Fixed

@fjgarlin I hope you're taking notes for the endpoint-based plugin! It may be worth moving this helper to a more shared location later, I'm not sure. But for now, this looks great. Thanks!

fjgarlin’s picture

I sent it to the base class in the jsonapi plugin: https://git.drupalcode.org/project/project_browser/-/merge_requests/95/d...

As you suggest, it might be a useful method for all plugins.

Status: Fixed » Closed (fixed)

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