diff -u b/src/SerializableTempstore.php b/src/SerializableTempstore.php --- b/src/SerializableTempstore.php +++ b/src/SerializableTempstore.php @@ -5,6 +5,9 @@ use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\user\SharedTempStore; +/** + * An extension of the SharedTempStore system for serialized data. + */ class SerializableTempstore extends SharedTempStore { use DependencySerializationTrait; } diff -u b/src/SerializableTempstoreFactory.php b/src/SerializableTempstoreFactory.php --- b/src/SerializableTempstoreFactory.php +++ b/src/SerializableTempstoreFactory.php @@ -4,14 +4,17 @@ use Drupal\user\SharedTempStoreFactory; +/** + * A factory for creating SerializableTempStore objects. + */ class SerializableTempstoreFactory extends SharedTempStoreFactory { /** * {@inheritdoc} */ function get($collection, $owner = NULL) { - // Use the currently authenticated user ID or the active user ID unless - // the owner is overridden. + // Use the currently authenticated user ID or the active user ID unless the + // owner is overridden. if (!isset($owner)) { $owner = \Drupal::currentUser()->id() ?: session_id(); } only in patch2: unchanged: --- /dev/null +++ b/tests/src/Kernel/SerializableTempstoreTest.php @@ -0,0 +1,44 @@ +installSchema('system', ['key_value_expire']); + } + + /** + * Tests serializing a serializable temp store object. + */ + public function testSerializableTempStore() { + $store = $this->container + ->get('ctools.serializable.tempstore.factory') + ->get('foobar'); + + $this->assertInstanceOf(SerializableTempstore::class, $store); + /** @var SerializableTempstore $store */ + // With a normal tempstore, this would fail because the current request is + // not directly serializable. + $store->set('request', $this->container->get('request_stack')->getCurrentRequest()); + } + +}