Problem/Motivation
User story:
As a user with a views jump menu displayed on a dashboard
I want an option to open items selected in the jump menu in a new window/tab
So that I don't lose my place on the dashboard
Proposed resolution
Exact details to be determined - likely we'd have to modify the HTML or pass a flag through drupalSettings, to indicate to the code in js/views-jump-menu.js that it should try to open the link in a new window/tab instead of the current one.
Remaining tasks
Write a patch- Review and feedback
- RTBC and feedback
- Commit
User interface changes
Idea: Adds an "Open in new window/tab" checkbox to the Views Jump Menu format settings.
API changes
To be determined; likely none.
Data model changes
Idea: Adds an new_window boolean to the jump menu views schema, to track whether clicking an item in the views jump menu should open the link in a new window/tab.
Original report by markdc
How about an option in the Views formatter settings for opening links in a new window?
I tried playing around with the twig template to get this to work with javascript in the select element:
onchange="window.open(this.options[this.selectedIndex].data-url);
It doesn't work.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 3101397-12--option-to-open-link-in-new-window.patch | 12.93 KB | mparker17 |
| #9 | 3101397-9--option-to-open-link-in-new-window.patch | 12.84 KB | mparker17 |
Comments
Comment #2
mparker17Comment #3
mparker17Here's a patch. Not sure yet how to add automated tests; but manual testing suggests this works.
Note its update hook will conflict with the one added in #3077459: Integration with chosen or select2 js; this cannot be avoided until either this issue or 3077459 is committed.
Comment #4
mparker17This patch adds some Functional [PHP] tests to verify the HTML output.
I wasn't able to add Functional JavaScript tests for this feature, because the version of the Selenium driver that Drupal core/testbot uses doesn't appear to properly support multiple windows... so the tests failed. Although I turned some of that work into #3163621: Add a FunctionalJavascript test.
Comment #5
mparker17Apparently the test error is because Testbot couldn't clone Drupal. I daresay that's not an issue with the code in the patch. I'll try to get Testbot to retry that later.
***
In the meantime, I need to apply both #3077459-9: Integration with chosen or select2 js and this patch, so I'm adding another,
3101397-5--new-window--on-3077459-9.do-not-test.patchpatch here which assumes that patch has already been applied. Note the "do-not-test" so it doesn't trigger Testbot. Also note that since this is the same code as #4 (just rebased onto something different), there is no interdiff.Comment #6
colanMost of this looks good.
I wouldn't say that this is a critical security issue because it's the same origin, but given the document relationship vulnerability, it would probably be a good idea to update this anyway as "there's still some mischief that can be done" (Use window.open but block use of window.opener).
Comment #7
mparker17Here's an updated patch and interdiff; and also another patch on #3077459-12: Integration with chosen or select2 js.
Reviews welcome!
Comment #8
colanLooks good to me. Thanks!
Comment #9
mparker17Here are new patches, rerolled upon the changes in
8a2cc17e.I had to make a manual merge conflict resolution; see the interdiff.
Comment #11
colanComment #12
mparker17Okay, here's a patch that should fix the failed test; and updates the code comment to better describe what is being tested.
Reviews are welcome.
The breakage was caused because the change in commit 8a2cc17e made the test a bit more fragile.
The change in commit 8a2cc17e looks like (I've reordered the lines slightly and added an extra newline for clarity)...
The old code asserted that there was at least one option with the correct data URL. The new code asserts that the 3rd option in the array of options (i.e.:
[2]is the third item after[1]and[0]) has the correct data URL.This is fragile, because if any of the test's ancestor classes (
ViewTestBase,BrowserTestBase, etc.) change the number of users they add in their fixture functions (setUpBeforeClass(),setUp(), orassertPreConditions()), or another test inStyleJumpMenuTesthappens to add a user and also run before this test, then the option with the correct URL will switch places, which will break the test again.The patch in this issue refactored StyleJumpMenuTest, so that instead of both methods adding a user, the setUp function added one user instead, so the user with the data URL we wanted to test went from position 3 to position 2.
I've changed the test in this patch to look at [1], but it might be worth going back to the original test logic (i.e.: that there is at least one option with the correct data URL), and testing the order of the items in the jump menu in a separate class so that (a) you can have tighter control over the order that users are created in, (b) you aren't introducing subtle dependencies into existing test logic, and (c) you can be more explicit about what you're testing, which will make debugging failures in the new class easier.
Comment #14
replicaobscuraThis is looking good to me. Sorry for taking so long to look at it! Merged in dev. I agree the tests could perhaps be improved in general, but your changes make sense to get them working here.
Comment #15
mparker17Thanks very much @bmcclure!