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.
The PrivateTempStore service does not yet offer a possibility to set the expiration of a key/value pair, other then creating the object itself instead of just using the service.
The attached patch adds an optional parameter to the setter of the object. It also includes code from issue https://www.drupal.org/project/drupal/issues/2743931 that enables anonymous users to use the store.
Comment | File | Size | Author |
---|---|---|---|
#26 | 2928639-26.patch | 2.39 KB | tomasbarej |
#19 | 2928639-19.patch | 2.36 KB | nlisgo |
#19 | 2928639-19-interdiff.txt | 1.05 KB | nlisgo |
#19 | 2928639-19-testonly.patch | 1.05 KB | nlisgo |
#13 | 2743931-108.patch | 1.31 KB | markwittens |
Comments
Comment #2
borisson_We should remove the code that was in #2743931: Saving to the private tempstore doesn't start a session for anonymous users.
I think this could also benefit from tests.
Comment #3
mayurjadhav CreditAttribution: mayurjadhav at Blisstering Solutions commentedComment #5
markwittens CreditAttribution: markwittens commentedNew patch for core version 8.5.1. I don't have much time for this so if someone with experience in writing tests could write a test that would be great.
Comment #6
yogeshmpawarComment #8
yogeshmpawarComment #9
yogeshmpawarUpdated patch attached for 8.6.x branch.
Comment #10
borisson_Back to needs work for tests.
Comment #12
markwittens CreditAttribution: markwittens commentedMaybe someone with experience in testing can point me in the right direction on how to write tests for this or maybe even write the tests. I've looked into writing them but I don't see how I can test if the passed expiration actually is used.
Comment #13
markwittens CreditAttribution: markwittens commentedAttached is a new patch that works for Drupal 8.6.1
Comment #14
borisson_\Drupal\Tests\Core\TempStore\PrivateTempStoreTest::testSet
already tests something similar:The
setWithExpire
arguments should be different when this argument is passed in.Comment #15
yuseferi CreditAttribution: yuseferi as a volunteer commentedThis is exactly what I need. set expire time for PrivateTempStore. what is remaining ? I want to help to this feature goes to core.
Comment #17
HbtTundar CreditAttribution: HbtTundar commentedHow set Expiry Time for PrivateTempStore In drupal 8.0 , i can not find any sloution yet ?
Comment #18
nlisgo CreditAttribution: nlisgo commentedI will look at extending the tests to cover the new optional parameter.
Comment #19
nlisgo CreditAttribution: nlisgo commentedComment #21
Krzysztof DomańskiI changed the expiration time for 1 week in
testSetExpire()
.Test also pass. The
testSetExpire()
only tests a successful set() call. We should also check that the data is correctly expired.Comment #26
tomasbarej CreditAttribution: tomasbarej commentedComment #29
grathbone CreditAttribution: grathbone at VMLY&R commentedWhat is still needed on this ticket? Is this ready for Needs Review again? This functionality would be very useful if it made it into core.
Comment #30
Krzysztof Domański#26 is just a re-roll. We need to resolve #21.