You are here

protected function Formatter::createCacheController in RESTful 7.2

Gets a cache controller based on the data to be rendered.

Parameters

mixed $data: The data to be rendered.

Return value

\Drupal\restful\RenderCache\RenderCacheInterface;

The cache controller.

3 calls to Formatter::createCacheController()
Formatter::getCachedData in src/Plugin/formatter/Formatter.php
Gets the cached computed value for the fields to be rendered.
Formatter::getCacheHash in src/Plugin/formatter/Formatter.php
Gets the cached computed value for the fields to be rendered.
Formatter::setCachedData in src/Plugin/formatter/Formatter.php
Gets the cached computed value for the fields to be rendered.

File

src/Plugin/formatter/Formatter.php, line 217
Contains \Drupal\restful\Plugin\formatter\Formatter

Class

Formatter
Class Formatter.

Namespace

Drupal\restful\Plugin\formatter

Code

protected function createCacheController($data) {
  if (!($cache_fragments = $this
    ->cacheFragments($data))) {
    return NULL;
  }

  // Add the formatter fragment because every formatter may prepare the data
  // differently.

  /* @var \Doctrine\Common\Collections\ArrayCollection $cache_fragments */
  $cache_fragments
    ->set('formatter', $this
    ->getPluginId());

  /* @var \Drupal\restful\Plugin\resource\Decorators\CacheDecoratedResource $cached_resource */
  if (!($cached_resource = $this
    ->getResource())) {
    return NULL;
  }
  if (!$cached_resource instanceof CacheDecoratedResourceInterface) {
    return NULL;
  }
  return RenderCache::create($cache_fragments, $cached_resource
    ->getCacheController());
}