class ViewsData (View source)

Class to manage and lazy load cached views data.

If a table is requested and cannot be loaded from cache, all data is then requested from cache. A table-specific cache entry will then be created for the requested table based on this cached data. Table data is only rebuilt when no cache entry for all table data can be retrieved.

Properties

protected string $baseCid

The base cache ID to use.

protected CacheBackendInterface $cacheBackend

The cache backend to use.

protected array $storage

Table data storage.

protected array $allStorage

All table storage data loaded from cache.

protected bool $fullyLoaded

Whether the data has been fully loaded in this request.

protected bool $skipCache

Whether or not to skip data caching and rebuild data each time.

protected string $langcode

The current language code.

protected ModuleHandlerInterface $moduleHandler

Stores a module manager to invoke hooks.

protected LanguageManagerInterface $languageManager

The language manager.

Methods

__construct(CacheBackendInterface $cache_backend, ConfigFactoryInterface $config, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager)

Constructs this ViewsData object.

array
getAll()

Gets all table data.

array
get(string $key)

Gets data for a particular table.

mixed
cacheGet(string $cid)

Gets data from the cache backend.

cacheSet(string $cid, mixed $data)

Sets data to the cache backend.

string
prepareCid(string $cid)

Prepares the cache ID by appending a language code.

array
getData()

Gets all data invoked by hook_views_data().

processEntityTypes(array $data)

Links tables with 'entity type' to respective generic entity-type tables.

array
fetchBaseTables()

Fetches a list of all base tables available.

clear()

Clears the class storage and cache.

Details

__construct(CacheBackendInterface $cache_backend, ConfigFactoryInterface $config, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager)

Constructs this ViewsData object.

Parameters

CacheBackendInterface $cache_backend

The cache backend to use.

ConfigFactoryInterface $config

The configuration factory object to use.

ModuleHandlerInterface $module_handler

The module handler class to use for invoking hooks.

LanguageManagerInterface $language_manager

The language manager.

array getAll()

Gets all table data.

Return Value

array

An array of table data.

array get(string $key)

Gets data for a particular table.

Parameters

string $key

The key of the cache entry to retrieve.

Return Value

array

An array of table data.

protected mixed cacheGet(string $cid)

Gets data from the cache backend.

Parameters

string $cid

The cache ID to return.

Return Value

mixed

The cached data, if any. This will immediately return FALSE if the $skipCache property is TRUE.

protected cacheSet(string $cid, mixed $data)

Sets data to the cache backend.

Parameters

string $cid

The cache ID to set.

mixed $data

The data that will be cached.

protected string prepareCid(string $cid)

Prepares the cache ID by appending a language code.

Parameters

string $cid

The cache ID to prepare.

Return Value

string

The prepared cache ID.

protected array getData()

Gets all data invoked by hook_views_data().

This is requested from the cache before being rebuilt.

Return Value

array

An array of all data.

protected processEntityTypes(array $data)

Links tables with 'entity type' to respective generic entity-type tables.

Parameters

array $data

The array of data to alter entity data for, passed by reference.

array fetchBaseTables()

Fetches a list of all base tables available.

Return Value

array

An array of base table data keyed by table name. Each item contains the following keys:

  • title: The title label for the base table.
  • help: The help text for the base table.
  • weight: The weight of the base table.

clear()

Clears the class storage and cache.