ViewsData::get

public ViewsData::get($key = NULL)

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.

Deprecated

NULL $key deprecated in Drupal 8.2.x and will be removed in 9.0.0. Use getAll() instead.

See also

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

File

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

Class

ViewsData
Class to manage and lazy load cached views data.

Namespace

Drupal\views

Code

public function get($key = NULL) {
  if (!$key) {
    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;
    }
    // If there is no cached entry and data is not already fully loaded,
    // rebuild. This will stop requests for invalid tables calling getData.
    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];
}
doc_Drupal
2016-10-29 09:54:59
Comments
Leave a Comment

Please login to continue.