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
#2488116: Document the session subsystem contains example for the new session subsystem (see also CR).
Proposed resolution
Add a new session example module.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#45 | interdiff.txt | 12.76 KB | Mile23 |
#45 | 2502303_45.patch | 17.73 KB | Mile23 |
| |||
#43 | interdiff.txt | 7.46 KB | Mile23 |
#43 | 2502303_43.patch | 14.62 KB | Mile23 |
#40 | interdiff.txt | 17.27 KB | Mile23 |
Comments
Comment #1
znerol CreditAttribution: znerol commentedComment #2
joshi.rohit100Should this be a simple example for just setting and getting the session or more ? If more, I think we should have a outline of what this module should do.
Comment #3
znerol CreditAttribution: znerol commentedYes, I think we should restrict the scope here to setting/getting stuff in the session. I imagine basically the PHP example translated to Drupal (Symfony) controller/session architecture.
Comment #4
znerol CreditAttribution: znerol commentedComment #5
Mile23Sounds good. Be sure it's internally documented and that it has tests. See also: #2209627: [meta] Module Checklist for Examples
Comment #6
joshi.rohit100Comment #7
joshi.rohit100First attempt without tests. Don't know what should be there in tests.
Comment #8
joshi.rohit100Comment #9
joshi.rohit100Adding for clearing the session.
Comment #10
pp CreditAttribution: pp as a volunteer commentedAdd tests and add some menu and task links.
Comment #12
joshi.rohit100Fixed some white spaces, and tried to fix toolbar test failure. Second test fail, I think is not relevant here.
Comment #14
pp CreditAttribution: pp as a volunteer commentedDrupal Core changed. this is a different issue because original Examples module breaks the tests, not this patch.
Comment #15
pp CreditAttribution: pp as a volunteer commentedWaiting for the following issues:
https://www.drupal.org/node/2547627
https://www.drupal.org/node/2173527#comment-10196477
Comment #16
Mile23We can more forward with the scope of this issue, which is making a session example.
Please open a new issue about the toolbar test.
Comment #17
pp CreditAttribution: pp as a volunteer commentedI made it. The links are in tge #15
Comment #18
Mile23Aha.. Well you can add related issues as well. :-)
Comment #19
joshi.rohit100So what next ?
Comment #20
joshi.rohit100So what next ?
Comment #21
pp CreditAttribution: pp as a volunteer commentedWe are waiting for the answer. https://www.drupal.org/node/2173527#comment-10196477 We must to know it is a core bug, or we must update Drupal\examples\Tests\ExamplesTest test. If this test will be pass, we apply add_language.patch, and then this patch will be good again.
(I attache a patch which contains correction for all issues, do not use)
Comment #22
pp CreditAttribution: pp as a volunteer commentedComment #23
znerol CreditAttribution: znerol commentedRe #21: This patch has nothing in common with #12. I'm confused.
Comment #24
znerol CreditAttribution: znerol commentedSetting this to CNW, if anyone is going to attack this, please pick up from #12.
Comment #25
pp CreditAttribution: pp as a volunteer commentedWe are waiting for two related issues: #2547627, #2548027
Comment #26
Mile23As I mentioned, the issue with the non-passing test about the toolbar is unrelated to this issue. It's yet another branch blocker which we'll deal with. This is how it goes when you're trying to hit a moving target like Drupal 8. Ideally all tests would pass always, but that's not a goal we can shoot for.
So: Let's stay in scope and do reviews of the session example module and not poke around on the toolbar test in this issue. The best way to get some clarity on the aria-text issue is to address it in core, as with #2548027: Follow-up add back aria-label to toolbar tray
Here's an Examples issue for the toolbar test: #2505711: Fix toolbar tests, which will either require a patch or be closed when #2548027: Follow-up add back aria-label to toolbar tray is committed. (This is what I meant in #16 when I said to open another issue.)
Note: If you add square brackets around issue numbers, they magically turn into links to the issue in question: [#number]
Also, it's a very good idea to generate an interdiff, so reviewers can see what you've changed: https://www.drupal.org/documentation/git/interdiff
Setting this issue to Needs Work. Reviews of the module as presented in #12 forthcoming.
Comment #27
Mile23Thanks for all the work.
Some things this module needs:
A test to make sure the menu item appears on the page and leads to the form with a 200.
A test to make sure the session data is stored. For this, the test will need to create and log in a user.
Add a
#placeholder
to the textareas to give instructions rather than providing a default value. Something like 'enter your name here'Some descriptive text on the session form. This should be an 'item' form element telling what will happen to the data being submitted.
Some descriptive text on the view page. Same deal: Tell the user what they're seeing and where it came from.
The name/email combination is pretty good, but let's throw in something like favorite color, just so it stands out that this can be any sort of information.
Needs a module file defining a documentation group, explaining what the module does. We need this so the module will show useful info on api.drupal.org.
And generally: See the checklist:#2209627: [meta] Module Checklist for Examples :-)
Comment #28
Mile23Also, I'm not sure whether it's necessary but we might need to remove the session information in
hook_uninstall()
. This means adding an.install
file as well.Comment #31
Mile23OK, so now that the branch blocker is fixed (more or less... #2505711: Fix toolbar tests) here's #12 without the changes to ExampleTest.
It still needs all the work from #26 through #28.
Comment #32
joshi.rohit100In test, we have 'when session is not present', 'session default value' on view page. But I think, there should also be a test when we submit value in post array. Currently we are submitting empty array in drupalPostForm().
Comment #35
Torenware CreditAttribution: Torenware as a volunteer commentedGetting the ball rolling on this one again.
Did most of mile23's list except for adding the module file. Tests all run; having the user log in during the tests is unnecessary; the problem with the test was that the tab bar is a block, and needed to be explicitly added.
Comment #36
Torenware CreditAttribution: Torenware as a volunteer commentedChange status so folks look at it, and the testbot too.
Comment #38
Torenware CreditAttribution: Torenware as a volunteer commentedOK, looks like HEAD changed a little too much for the good of my patch...
Rerolling. Not sure if I'm doing the interdiff right under the circumstances, but I'm trying to make it against the state of #31.
Comment #39
Mile23Thanks for keeping it alive. :-)
Here's a review. I'll also start up a test to see what broke in the last little while.
Maybe these need to be 'access content'
'No Email.'
Ideally we'd have a cache context for our specific content within the session data, but I don't think we have that capability without creating it. That's too much for this example. But the cache should behave differently for different session IDs, so let's add the session cache context.
FormBase
already hasLinkGeneratorTrait
, so we should remove the$link_generator
property and callsetLinkGenerator()
in the constructor.This needs a ton more inline code, since it's the thing we're demonstrating. :-)
We should have a test that only sets the session without the form or controller.
We should also test a behavior for logging in a user, setting their session, and then logging out. The session data should go away.
Comment #40
Mile23Manual re-roll.
Converted test to BTB.
The routes are no longer admin paths.
Updated some docblocks.
Added .module file with documentation.
Pared down the form and controller classes.
'View' page is now a table.
Comment #41
Mile23Comment #42
Mile23Still needs #39.1, 3, 6.
I changed my mind and want to demonstrate caching the view page.
Also needs:
Docs leading to the core docs for sessions: https://api.drupal.org/api/drupal/core%21core.api.php/group/session/8.5.x
Docs talking about stream_wrapper_example since it adds a session: scheme.
Comment #43
Mile23Re: #39.3, it seems that the cache is invalidated without declaring any #cache metadata. I think it's because changing session values ends up invalidating the user or maybe the cookie context. I'd much rather be able to explicitly state how this works in the example, so we'll finish this up when more research has been done.
Comment #45
Mile23I had only checked the caching locally using Bartik, which the testing system doesn't use, and that explains the fail in #43.
This version manages caching as a cache tag. I hope it's not too complicated.
Comment #47
Mile23One of the problems with a contrib module adding session data is that they should then remove it when the module is uninstalled.
Currently, I'm not entirely sure how to do this. I tried a few things... So I'll open a follow-up about this after committing here.
This is also a problem for the file wrapper example, but the file wrapper example allows arbitrarily large data, limited only by the data column in {session}.
Also need to add a session example component to the dropdown.
Comment #48
Mile23Follow-up: #2985471: Examples fill up your {session} table