function ViewsData::get

Same name in other branches
  1. 9 core/modules/views/src/ViewsData.php \Drupal\views\ViewsData::get()
  2. 8.9.x core/modules/views/src/ViewsData.php \Drupal\views\ViewsData::get()
  3. 11.x core/modules/views/src/ViewsData.php \Drupal\views\ViewsData::get()

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.

File

core/modules/views/src/ViewsData.php, line 135

Class

ViewsData
Class to manage and lazy load cached views data.

Namespace

Drupal\views

Code

public function get($key) {
    if (!$key) {
        throw new \InvalidArgumentException('A valid cache entry key is required. Use getAll() to get all table data.');
    }
    if (!isset($this->storage[$key])) {
        // Prepare a cache ID for get and set.
        $cid = $this->baseCid . ':' . $key;
        $from_cache = FALSE;
        if ($data = $this->cacheGet($cid)) {
            $this->storage[$key] = $data->data;
            $from_cache = TRUE;
        }
        elseif (!$this->fullyLoaded) {
            $this->allStorage = $this->getData();
        }
        if (!$from_cache) {
            if (!isset($this->allStorage[$key])) {
                // Write an empty cache entry if no information for that table
                // exists to avoid repeated cache get calls for this table and
                // prevent loading all tables unnecessarily.
                $this->storage[$key] = [];
                $this->allStorage[$key] = [];
            }
            else {
                $this->storage[$key] = $this->allStorage[$key];
            }
            // Create a cache entry for the requested table.
            $this->cacheSet($cid, $this->allStorage[$key]);
        }
    }
    return $this->storage[$key];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.