You are here

public function ViewsData::get in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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.

Return value

array $data An array of table data.

1 call to ViewsData::get()
ViewsData::fetchBaseTables in core/modules/views/src/ViewsData.php
Fetches a list of all base tables available.

File

core/modules/views/src/ViewsData.php, line 126
Contains \Drupal\views\ViewsData.

Class

ViewsData
Class to manage and lazy load cached views data.

Namespace

Drupal\views

Code

public function get($key = NULL) {
  if ($key) {
    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] = array();
          $this->allStorage[$key] = array();
        }
        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];
  }
  else {
    if (!$this->fullyLoaded) {
      $this->allStorage = $this
        ->getData();
    }

    // Set storage from allStorage outside of the fullyLoaded check to prevent
    // cache calls on requests that have requested all data to get a single
    // tables data. Make sure $this->storage is populated in this case.
    $this->storage = $this->allStorage;
  }
  return $this->allStorage;
}