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:
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?
Issue fork project_browser-3298575
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:
Comments
Comment #3
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedMarking 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.
Comment #4
srishtiiee CreditAttribution: srishtiiee at Acquia commentedTested the patch manually, all the relative URL's are converted to absolute. Marking RTBC.
Comment #7
tim.plunkett@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!
Comment #8
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Drupal Association commentedI 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.