public function DataProvider::getCacheFragments in RESTful 7.2
Gets the entity context.
Parameters
mixed $identifier: The ID.
Overrides DataProviderInterface::getCacheFragments
3 methods override DataProvider::getCacheFragments()
- DataProviderDbQuery::getCacheFragments in src/
Plugin/ resource/ DataProvider/ DataProviderDbQuery.php - Gets the entity context.
- DataProviderEntity::getCacheFragments in src/
Plugin/ resource/ DataProvider/ DataProviderEntity.php - Gets the entity context.
- DataProviderPlug::getCacheFragments in src/
Plugin/ resource/ DataProvider/ DataProviderPlug.php - Gets the entity context.
File
- src/
Plugin/ resource/ DataProvider/ DataProvider.php, line 255 - Contains \Drupal\restful\Plugin\resource\DataProvider\DataProvider.
Class
Namespace
Drupal\restful\Plugin\resource\DataProviderCode
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' => CacheDecoratedResource::serializeKeyValue($this->pluginId, $this
->canonicalPath($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;
}