contextual.js produces an undesireable URL when a contextual link has a fragment in it

Created on 5 July 2016, almost 8 years ago
Updated 8 February 2024, 4 months ago

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

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Contextual 

Last updated 6 days ago

Created by

🇨🇦Canada m4olivei Grimsby, ON

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024