- Status changed to Needs review
over 1 year ago 12:09pm 12 April 2023 - Status changed to Needs work
over 1 year ago 11:10pm 12 April 2023 - 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
+++ b/core/modules/node/tests/src/FunctionalJavascript/ContextualLinksTest.php @@ -106,6 +106,10 @@ public function testRevisionContextualLinks() { + // Confirm that the "Delete" contextual link doesn't contain + // the destination parameter. + $this->assertStringNotContainsString('?destination=', $links[1]->getAttribute('href'));
I think we can use built in PHP APIs to be a bit more precise here.
Something like this
$query = parse_url($links[1]->getAttribute('href'), PHP_URL_QUERY); parse_str($query, $parsed_query); $this->assertArrayNotHasKey('destination', $parsed_query);
+++ b/core/modules/contextual/js/contextual.js @@ -104,7 +104,12 @@ + if (url.match(/(node\/\d+\/delete$|node\/\d+\/delete\?.+$)/g) === null) { + this.setAttribute('href', url + glue + destination); + } else { + this.setAttribute('href', url); + }
Unfortunately, we can't hardcode node specific logic in contextual module.
What happens if another module has a delete contextual link (e.g. media) and we want similar logic.
So I think we need to go back to the drawing board here.
We need an API to allow an individual link to override its destination.
Firstly, I think we replace the string based concatenation of URL params in contextual.js with UrlSearchParams which is now available in D10 because we don't support IE anymore.
Then I think we should check if the destination is already set before we blindly add it.
Then I think the node contextual link should declare 'options' for the delete plugin, which would be
['query' => ['destination' => '/']]
Something like that anyway. We might take a few iterations to get to a workable API
- Issue was unassigned.