You are here

public function DataProviderPlug::getCacheFragments in RESTful 7.2

Gets the entity context.

Parameters

mixed $identifier: The ID.

Overrides DataProvider::getCacheFragments

File

src/Plugin/resource/DataProvider/DataProviderPlug.php, line 247
Contains \Drupal\restful\Plugin\resource\DataProvider\DataProviderPlug.

Class

DataProviderPlug
Class DataProviderPlug.

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

public function getCacheFragments($identifier) {

  // If we are trying to get the context for multiple ids, join them.
  if (is_array($identifier)) {
    $identifier = implode(',', $identifier);
  }
  $fragments = new ArrayCollection(array(
    'resource' => $identifier,
  ));
  $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;
}