Problem/Motivation
contextual.js always adds the destination query string param to the end of the URL, which will produce an undesired result when the URL has a fragment in it. For example, if I have a hook_contextual_links_view_alter() implementation like this:
/**
* Implements hook_contextual_links_view_alter().
*/
function mymodule_contextual_links_view_alter(&$element, $items) {
if (!empty($element['#links']['entitynode-node-form'])) {
$element['#links']['entitynode-node-form']['url']->setOption('fragment', 'some-fragment-id');
}
}
Proposed resolution
Fix contextual.js to take care when fragments are in the URL. Also wondering if there is a url building JS lib available to explode the URL into component parts for alter, and then implode it back for a more robust solution.
Remaining tasks
* Write a patch
* Write a test
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#21 | 2760937-21.patch | 824 bytes | hctom |
Issue fork drupal-2760937
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 #2
m4oliveiThis is the line that has the bug: http://cgit.drupalcode.org/drupal/tree/core/modules/contextual/js/contex...
Comment #3
m4oliveiPatch attached.
Comment #4
Wim LeersThanks! Can you provide a JS test to show that it now works?
Comment #10
Internetter CreditAttribution: Internetter at Code & Content GmbH for Code & Content GmbH commentedI have another patch for version 8.7.5. But I also not know how to wrote a test for javascript.
Comment #15
larowlan#2815199: Add tools and scripts for writing and running javascript unit tests has an example of using Nightwatch for a unit test we might be able to leverage here.
Comment #18
hctomBumping version to 10.1.x-dev because this is still an issue there and patches do not apply anymore.
Comment #19
hctomHere are some new patches for Drupal 10.1.x and 11.x - Tests are still needed
Comment #20
_utsavsharma CreditAttribution: _utsavsharma at OpenSense Labs for DrupalFit commentedFixed CCF in #19.
Comment #21
hctomHere is a new re-roll, that should be applicable for 10.2.x and 11.x. Unfortunately, I was not able to create an interdiff with patch from #20, because of another changed line (
const glue = url.includes('?') ? '&' : '?';
) that landed in core in the meantime.Also bumping the version to 11.x, where all new development happens.
Tests are still needed.
Comment #23
hctomCreated an issue fork for 11.x and applied patch from #21 because DrupalCI tests no longer allow testing for versions > 10.1 - all new development for this issue should happen in there, so I also hide all the patch files except the last one.
Comment #24
hctomHiding forgotten patch files