- Issue created by @nickdickinsonwilde
- @nickdickinsonwilde opened merge request.
- Status changed to Needs review
about 2 years ago 2:23pm 22 March 2023 - 🇪🇸Spain fjgarlin
The "/api" is heavily ingrained in the module (both D7 and D10). It's not just the link generation, but also the whole routing system (see api.routing.yml) for the module.
Your EventSubscriber solution is a good way to get around it, but as you say, that's only part of it. For the generated links, you could also create an OutboundPathProcessor to alter the links to have the desired path prefix. I think that will get you 100% there with just a few files.
I'm not sure if it's worth putting all the effort on refactoring routes, code, tests on the module when there is a workaround, but I'm happy to hear more thoughts.
- 🇪🇸Spain fjgarlin
From the example provided here https://www.drupal.org/node/2238759 → , and your code, here is an (untested) suggestion:
function processOutbound($path, &$options = array(), Request $request = NULL) { if (strpos($path, '/api/') === 0) { return str_replace('/api/', '/work/drupal-api/', $path); } return $path; }
- Status changed to Closed: works as designed
almost 2 years ago 8:43am 28 April 2023 - 🇨🇦Canada nickdickinsonwilde Victoria, BC (T'So-uke lands)
Thanks for the feedback. I personally feel that it is very much better to not presume paths and use proper Urls instead of strings for paths.
That said, yes, I was able to switch to using both an inbound and outbound path processor and made it work for my personal use case without patching the module. So calling it works as designed.
- Status changed to Fixed
over 1 year ago 2:11pm 23 August 2023 - 🇪🇸Spain fjgarlin
While working on some other tasks related to test failures, I needed to change a few things regarding path generation, which made me remember this issue.
The MR was missing a few places where ::objectUrl was being used, but the principle and the proof of concepts were still valid, so I am actually including a bunch of the changes suggested here in the work that I am doing.
I don't know if I'll be able to include all of them, but I am definitely trying to. I need to test things all over the place (and good thing we also have functional tests!!).
The MR with the work and commit history that I am doing is here: https://git.drupalcode.org/project/api/-/merge_requests/12/diffs
I am going to mark this issue as Fixed and give credit as the changes will be in the module very soon.
Thanks! Automatically closed - issue fixed for 2 weeks with no activity.