Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Remember the page you were on and take you back there when switching Workspaces.
Proposed resolution
- Set a destination query string for the workspace button in hook_toolbar in workspace.module
- Set a destination query string for the workspace activate form in WorkspaceListBuilder
- Remove the redirect from \Drupal\workspace\Form\WorkspaceActivateForm::submitForm
- Find a way to bypass the caching of the link in hook_toolbar
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#41 | 2984938-41.patch | 5.77 KB | amateescu |
#40 | 2984938-40.patch | 8.3 KB | amateescu |
#35 | 2984938-35.patch | 16.51 KB | jeqq |
#35 | interdiff.txt | 785 bytes | jeqq |
#34 | 2984938-34.patch | 16.52 KB | jeqq |
Comments
Comment #2
Wim LeersI was very confused by this indeed.
Let me know if you need help with
Comment #3
vijaycs85Here is an initial working patch. One note is, the cache context never used because the $item array was missing
+
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedTested #3 manually and it's working great!
Comment #5
timmillwoodI can't believe in #2949991-39: Add workspace UI in top dialog I was just missing that
+
.It looks as though the missing
+
dates back to the original commit, so only if the user doesn't have one of the permissions the cache context is added.I guess we needs tests now for the missing
+
bug fix, and the user redirect.Comment #6
vijaycs85Adding tests (test-only file is inter-diff)...
Comment #10
Gábor HojtsyFix component following module rename.
Comment #11
vijaycs85updated patch for the change in #10.
Not sure why it's failing on toolbar visibility but both test cases are green locally.
Turns out we found a bug (#2987956: Entity queries with sorting and ordering are not working in a non-default workspace) as part of the tests here.
Comment #14
vijaycs851. We are not getting
user.permissions
context because toolbar has content specific to the user (i.e. username) which is more granular. reference from docs:2. I believe test failure because of width wasn't set.
3. Added some access tests.
Comment #17
vijaycs85Comment #19
vijaycs85Comment #21
timmillwoodAwesome work on this @vijaycs85!
Comment #22
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe off-canvas test looks really good to me. Here's a review for the other parts:
This method seems to assert only cache contexts, so not really "access" parts. Can we move all the cache context assertions to the existing
WorkspacePermissionsTest
test?I'm not sure what exactly is being tested here, that a
hook_toolbar()
implementation forces auser
cache context on every page?If so,
\Drupal\Tests\toolbar\Functional\ToolbarCacheContextsTest::testToolbarCacheContextsCaller()
already provides test coverage for that, so I think we can remove this test class altogether :)Is this permission really needed?
Missing a 'we' between 'sure' and 'stay' :P
I don't think this should be removed, our
hook_toolbar()
implementation still depends on the user's permissions, and the fact that other implementations likeshortcut_toolbar()
add the more genericuser
context should not affect us in any way.Comment #23
vijaycs85Thanks for the review @timmillwood & @amateescu. Here is an update for #22
#22.1 - Moved
#22.2 - Removed
#22.3 - Removed
#22.4 - Fixed
#22.5 - Added back. but the "user" context is granular and "user.permissions" is generic. However, I see there is no harm in having it.
Comment #25
vijaycs85Comment #26
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThese cache context are different even though we are basically visiting the same page, so I wonder what exactly are we testing with them?
Comment #28
vijaycs85It's just matter of what's been rendered on that page. first one is 200 which renders something user specific and the second one is 404. just permission level.
Comment #29
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedGot it! I don't have anything else to complain about, great work :)
Comment #30
larowlancan we use some local variables here for assertSession() to avoid creating new objects each time?
we should use
['query' => \Drupal::destination()->getAsArray()]
hereComment #31
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThanks @larowlan for the review :) Addressed #30 and back to RTBC since they were very simple changes.
Comment #34
jeqqFixed the failing test because of the more generic cache context.
Comment #35
jeqqFixed the typo.
Comment #36
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedDiscussed with @jeqq and he told me that we have a test module in core specifically for removing the
user
item from the toolbar (toolbar_disable_user_toolbar.module
), and we could've used it in our test, but he went with the approach of testing both cases for better coverage, and I agree :)Comment #37
rosinegrean CreditAttribution: rosinegrean at PitechPlus commentedComment #39
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedUnrelated error in the tests for the new composer scaffold component.
Comment #40
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@alexpott reviewed this patch and asked why do we need all the changes to
WorkspacePermissionsTest
. Since this patch does not change anything related to cache context, I agree with him that those extra assertions are not really in scope of this issue.So here's a reroll of #35 with all the changes to
WorkspacePermissionsTest
reverted.Comment #41
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedReviewing the patch again, the changes to
WorkspaceSwitcherTest
andWorkspaceTestUtilities
are also not in scope, so I've removed them as well.Comment #43
Gábor HojtsyAdjusting credits.
Comment #45
Gábor HojtsyI verified the removed test parts are indeed unrelated. The patch looks good otherwise and got reviews from @larowlan and @alexpott already.
Committed c2d897e and pushed to 8.8.x. Thanks!
Comment #46
Gábor HojtsyShould be merged to 8.7 once that is out of freeze.
Comment #48
Gábor HojtsyCherry-picked to 8.7.x! Thanks again!
Comment #50
tom.moffett CreditAttribution: tom.moffett commentedI recently started trying out the Workspaces module since it seems like something that would be very helpful for our process. The
destination
that is appended to the Live/Stage URLs appears to be cached for me. So, I'll be on a page, switch my Workspace, and then taken back to some page I was on previously.My expectation is that the destination should be correctly updated to point to the page that the user is on.
I haven't had time to dig into that to see if it's specific to my instance since it's somewhat low priority (although frustrating), but I wanted to post a comment here in case anyone else is seeing that too.
Comment #51
tom.moffett CreditAttribution: tom.moffett commentedNot sure if this is the best way to go about it, but it was quick and got the job done, without having to waste a lot of time debugging. I also didn't bother spending the time to get into why it wasn't working to begin with since I don't have that kind of time for the project I'm working on right now, and I just need to move forward. This worked for me. I hope it helps anyone else running into this same problem.
I implemented this hook in a custom module I have in my Drupal instance:
Make sure to clear your cache once after adding that hook function, and you should see it working with the proper destination being appended.