You are here

public function DataProviderDbQuery::getCacheFragments in RESTful 7.2

Gets the entity context.

Parameters

mixed $identifier: The ID.

Overrides DataProvider::getCacheFragments

File

src/Plugin/resource/DataProvider/DataProviderDbQuery.php, line 103
Contains \Drupal\restful\Plugin\resource\DataProvider\DataProviderDbQuery.

Class

DataProviderDbQuery

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

public function getCacheFragments($identifier) {
  if (is_array($identifier)) {

    // Like in https://example.org/api/articles/1,2,3.
    $identifier = implode(ResourceInterface::IDS_SEPARATOR, $identifier);
  }
  $fragments = new ArrayCollection(array(
    'resource' => CacheDecoratedResource::serializeKeyValue($this->pluginId, $this
      ->canonicalPath($identifier)),
    'table_name' => $this
      ->getTableName(),
    'column' => implode(',', $this
      ->getIdColumn()),
  ));
  $options = $this
    ->getOptions();
  switch ($options['renderCache']['granularity']) {
    case DRUPAL_CACHE_PER_USER:
      if ($uid = $this
        ->getAccount()->uid) {
        $fragments
          ->set('user_id', (int) $uid);
      }
      break;
    case DRUPAL_CACHE_PER_ROLE:
      $fragments
        ->set('user_role', implode(',', $this
        ->getAccount()->roles));
      break;
  }
  return $fragments;
}