Support from Acquia helps fund testing for Drupal Acquia logo

Comments

znerol’s picture

joshi.rohit100’s picture

Should 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.

znerol’s picture

Yes, 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.

znerol’s picture

Mile23’s picture

Sounds good. Be sure it's internally documented and that it has tests. See also: #2209627: [meta] Module Checklist for Examples

joshi.rohit100’s picture

Assigned: Unassigned » joshi.rohit100
joshi.rohit100’s picture

Status: Active » Needs review
FileSize
5.32 KB

First attempt without tests. Don't know what should be there in tests.

joshi.rohit100’s picture

Assigned: joshi.rohit100 » Unassigned
joshi.rohit100’s picture

Adding for clearing the session.

pp’s picture

Add tests and add some menu and task links.

Status: Needs review » Needs work

The last submitted patch, 10: 2502303-session-example-10.patch, failed testing.

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
9.62 KB
3.61 KB

Fixed some white spaces, and tried to fix toolbar test failure. Second test fail, I think is not relevant here.

Status: Needs review » Needs work

The last submitted patch, 12: 2502303-12.patch, failed testing.

pp’s picture

Drupal Core changed. this is a different issue because original Examples module breaks the tests, not this patch.

pp’s picture

Status: Needs work » Postponed
Mile23’s picture

Status: Postponed » Needs work

We can more forward with the scope of this issue, which is making a session example.

Please open a new issue about the toolbar test.

pp’s picture

I made it. The links are in tge #15

Mile23’s picture

Aha.. Well you can add related issues as well. :-)

joshi.rohit100’s picture

So what next ?

joshi.rohit100’s picture

So what next ?

pp’s picture

FileSize
10.06 KB

We 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)

pp’s picture

Status: Needs work » Needs review
znerol’s picture

Re #21: This patch has nothing in common with #12. I'm confused.

znerol’s picture

Status: Needs review » Needs work

Setting this to CNW, if anyone is going to attack this, please pick up from #12.

pp’s picture

Status: Needs work » Postponed
Related issues: +#2548027: Follow-up add back aria-label to toolbar tray

We are waiting for two related issues: #2547627, #2548027

Mile23’s picture

Status: Postponed » Needs work
Issue tags: -Novice

As 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.

Mile23’s picture

Thanks 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 :-)

Mile23’s picture

Also, 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.

pp queued 12: 2502303-12.patch for re-testing.

The last submitted patch, 12: 2502303-12.patch, failed testing.

Mile23’s picture

Status: Needs work » Needs review
FileSize
8.95 KB
685 bytes

OK, 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.

joshi.rohit100’s picture

In 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().

Mile23 queued 31: 2502303_31.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 31: 2502303_31.patch, failed testing.

Torenware’s picture

Getting 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.

Torenware’s picture

Status: Needs work » Needs review

Change status so folks look at it, and the testbot too.

Status: Needs review » Needs work

The last submitted patch, 35: 2502303-35.patch, failed testing.

Torenware’s picture

Status: Needs work » Needs review
FileSize
39.17 KB
11.92 KB

OK, 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.

Mile23’s picture

Status: Needs review » Needs work

Thanks for keeping it alive. :-)

Here's a review. I'll also start up a test to see what broke in the last little while.

  1. +++ b/session_example/session_example.routing.yml
    @@ -0,0 +1,18 @@
    +    _access: 'TRUE'
    ...
    +    _access: 'TRUE'
    

    Maybe these need to be 'access content'

  2. +++ b/session_example/src/Controller/SessionExampleController.php
    @@ -0,0 +1,44 @@
    +    $email = $session->get('session_example.email', $this->t('No EMail'));
    

    'No Email.'

  3. +++ b/session_example/src/Controller/SessionExampleController.php
    @@ -0,0 +1,44 @@
    +      '#cache' => [
    +      'max-age' => 0,
    +      ]
    

    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.

  4. +++ b/session_example/src/Form/SessionExampleForm.php
    @@ -0,0 +1,161 @@
    +  /**
    +   * The Link generator.
    +   *
    +   * @var \Drupal\Core\Utility\LinkGeneratorInterface
    +   */
    +  protected $link_generator;
    ...
    +  public function __construct(RequestStack $request, LinkGeneratorInterface $link_generator) {
    

    FormBase already has LinkGeneratorTrait, so we should remove the $link_generator property and call setLinkGenerator() in the constructor.

  5. +++ b/session_example/src/Form/SessionExampleForm.php
    @@ -0,0 +1,161 @@
    +  /**
    +   * Get the session object from here.
    +   *
    +   * @return \Symfony\Component\HttpFoundation\Session\SessionInterface
    +   */
    +  public function getExampleSession() {
    +    $request = $this->request->getCurrentRequest();
    +    $session = $request->getSession();
    +    return $session;
    +  }
    

    This needs a ton more inline code, since it's the thing we're demonstrating. :-)

  6. +++ b/session_example/src/Tests/SessionExampleTest.php
    @@ -0,0 +1,82 @@
    +class SessionExampleTest extends WebTestBase {
    

    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.

Mile23’s picture

Manual 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.

Mile23’s picture

Status: Needs work » Needs review
Mile23’s picture

Status: Needs review » Needs work

Still 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.

Mile23’s picture

Status: Needs work » Needs review
FileSize
14.62 KB
7.46 KB

Re: #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.

Status: Needs review » Needs work

The last submitted patch, 43: 2502303_43.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Mile23’s picture

Status: Needs work » Needs review
FileSize
17.73 KB
12.76 KB

I 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.

  • Mile23 committed 402390d on 8.x-1.x authored by joshi.rohit100
    Issue #2502303 by Mile23, joshi.rohit100, Torenware, pp, znerol: Add a...
Mile23’s picture

Status: Needs review » Fixed
Issue tags: +Needs followup

One 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.

Mile23’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.