You are here

public function ViewsData::get in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/ViewsData.php \Drupal\views\ViewsData::get()

Gets data for a particular table, or all tables.

Parameters

string|null $key: The key of the cache entry to retrieve. Defaults to NULL, this will return all table data. NULL $key deprecated in Drupal 8.2.x and will be removed in 9.0.0. Use getAll() instead.

Return value

array An array of table data.

See also

https://www.drupal.org/node/2723553

https://www.drupal.org/node/3090442

File

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

Class

ViewsData
Class to manage and lazy load cached views data.

Namespace

Drupal\views

Code

public function get($key = NULL) {
  if (!$key) {
    @trigger_error('Calling get() without the $key argument is deprecated in drupal:8.2.0 and is required in drupal:9.0.0. See https://www.drupal.org/node/3090442', E_USER_DEPRECATED);
    return $this
      ->getAll();
  }
  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];
}