class FormCache implements FormCacheInterface (View source)

Encapsulates the caching of a form and its form state.

Properties

protected KeyValueExpirableFactoryInterface $keyValueExpirableFactory

The factory for expirable key value stores used by form cache.

protected CsrfTokenGenerator $csrfToken

The CSRF token generator to validate the form token.

protected AccountInterface $currentUser

The current user.

protected ModuleHandlerInterface $moduleHandler

The module handler.

protected LoggerChannelInterface $logger

Logger channel.

protected ConfigFactoryInterface $configFactory

The config factory.

protected RequestStack $requestStack

The request stack.

protected RequestPolicyInterface $requestPolicy

A policy rule determining the cacheability of a request.

protected string $root

The app root.

Methods

__construct(string $root, KeyValueExpirableFactoryInterface $key_value_expirable_factory, ModuleHandlerInterface $module_handler, AccountInterface $current_user, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, RequestStack $request_stack, RequestPolicyInterface $request_policy)

Constructs a new FormCache.

getCache(string $form_build_id, FormStateInterface $form_state)

Fetches a form from the cache.

loadCachedFormState(string $form_build_id, FormStateInterface $form_state)

Loads the cached form state.

setCache(string $form_build_id, array $form, FormStateInterface $form_state)

Stores a form in the cache.

deleteCache(string $form_build_id)

Deletes a form in the cache.

Details

__construct(string $root, KeyValueExpirableFactoryInterface $key_value_expirable_factory, ModuleHandlerInterface $module_handler, AccountInterface $current_user, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, RequestStack $request_stack, RequestPolicyInterface $request_policy)

Constructs a new FormCache.

Parameters

string $root

The app root.

KeyValueExpirableFactoryInterface $key_value_expirable_factory

The key value expirable factory, used to create key value expirable stores for the form cache and form state cache.

ModuleHandlerInterface $module_handler

The module handler.

AccountInterface $current_user

The current user.

CsrfTokenGenerator $csrf_token

The CSRF token generator.

LoggerInterface $logger

A logger instance.

RequestStack $request_stack

The request stack.

RequestPolicyInterface $request_policy

A policy rule determining the cacheability of a request.

getCache(string $form_build_id, FormStateInterface $form_state)

Fetches a form from the cache.

Parameters

string $form_build_id

The unique form build ID.

FormStateInterface $form_state

The current state of the form.

protected loadCachedFormState(string $form_build_id, FormStateInterface $form_state)

Loads the cached form state.

Parameters

string $form_build_id

The unique form build ID.

FormStateInterface $form_state

The current state of the form.

setCache(string $form_build_id, array $form, FormStateInterface $form_state)

Stores a form in the cache.

Parameters

string $form_build_id

The unique form build ID.

array $form

The form to cache.

FormStateInterface $form_state

The current state of the form.

deleteCache(string $form_build_id)

Deletes a form in the cache.

Parameters

string $form_build_id

The unique form build ID.