You are here

public function CachePluginBase::getRowId in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/cache/CachePluginBase.php \Drupal\views\Plugin\views\cache\CachePluginBase::getRowId()

Returns a unique identifier for the specified row.

Parameters

\Drupal\views\ResultRow $row: A result row.

Return value

string The row identifier.

1 call to CachePluginBase::getRowId()
CachePluginBase::getRowCacheKeys in core/modules/views/src/Plugin/views/cache/CachePluginBase.php
Returns the row cache keys.

File

core/modules/views/src/Plugin/views/cache/CachePluginBase.php, line 355

Class

CachePluginBase
The base plugin to handle caching.

Namespace

Drupal\views\Plugin\views\cache

Code

public function getRowId(ResultRow $row) {

  // Here we compute a unique identifier for the row by computing the hash of
  // its data. We exclude the current index, since the same row could have a
  // different result index depending on the user permissions. We exclude also
  // entity data, since serializing entity objects is very expensive. Instead
  // we include entity cache tags, which are enough to identify all the
  // entities associated with the row.
  $row_data = array_diff_key((array) $row, array_flip([
    'index',
    '_entity',
    '_relationship_entities',
  ])) + $this
    ->getRowCacheTags($row);

  // This ensures that we get a unique identifier taking field handler access
  // into account: users having access to different sets of fields will get
  // different row identifiers.
  $field_ids = array_keys($this->view->field);
  $row_data += array_flip($field_ids);

  // Finally we compute a hash of row data and return it as row identifier.
  return hash('sha256', serialize($row_data));
}