class EntityController in Render cache 7.2
EntityController - Provides render caching for entity objects.
Hierarchy
- class \Drupal\render_cache\RenderCache\Controller\AbstractBaseController extends \Drupal\Component\Plugin\PluginBase implements ControllerInterface
- class \Drupal\render_cache\RenderCache\Controller\BaseController
- class \Drupal\render_cache\RenderCache\Controller\BaseRecursionController implements RecursionControllerInterface
- class \Drupal\render_cache_entity\RenderCache\Controller\EntityController
- class \Drupal\render_cache\RenderCache\Controller\BaseRecursionController implements RecursionControllerInterface
- class \Drupal\render_cache\RenderCache\Controller\BaseController
Expanded class hierarchy of EntityController
File
- modules/
controller/ render_cache_entity/ src/ RenderCache/ Controller/ EntityController.php, line 16 - Contains \Drupal\render_cache_entity\RenderCache\Controller\EntityController
Namespace
Drupal\render_cache_entity\RenderCache\ControllerView source
class EntityController extends BaseRecursionController {
/**
* {@inheritdoc}
*/
protected function isCacheable(array $default_cache_info, array $context) {
return variable_get('render_cache_' . $this
->getPluginId() . '_' . $context['entity_type'] . '_enabled', TRUE) && parent::isCacheable($default_cache_info, $context);
}
/**
* {@inheritdoc}
*/
protected function getCacheContext($object, array $context) {
// Helper variables.
$entity = $object;
$entity_type = $context['entity_type'];
$context = parent::getCacheContext($object, $context);
// Setup entity context.
list($entity_id, $entity_revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
$context = $context + array(
'entity_id' => $entity_id,
'entity_revision_id' => $entity_revision_id,
'bundle' => !empty($bundle) ? $bundle : $entity_type,
);
return $context;
}
/**
* {@inheritdoc}
*/
protected function getCacheKeys($object, array $context) {
return array_merge(parent::getCacheKeys($object, $context), array(
$context['entity_type'],
$context['view_mode'],
));
}
/**
* {@inheritdoc}
*/
protected function getCacheHash($object, array $context) {
// Helper variables.
$entity = $object;
// Calculate hash to expire cached items automatically.
$hash = parent::getCacheHash($object, $context);
$hash['entity_id'] = $context['entity_id'];
$hash['entity_revision_id'] = $context['entity_revision_id'];
$hash['bundle'] = $context['bundle'];
$hash['langcode'] = $context['langcode'];
// @todo Move to cache tags.
$hash['modified'] = entity_modified_last($context['entity_type'], $entity);
return $hash;
}
/**
* {@inheritdoc}
*/
protected function getCacheTags($object, array $context) {
// Helper variables.
$entity_type = $context['entity_type'];
$entity_id = $context['entity_id'];
$tags = parent::getCacheTags($object, $context);
$tags[] = $entity_type . ':' . $entity_id;
$tags[] = $entity_type . '_view';
return $tags;
}
/**
* {@inheritdoc}
*/
protected function render(array $objects) {
// Helper variables.
$entities = $objects;
$view_mode = $this->context['view_mode'];
$langcode = $this->context['langcode'];
$entity_type = $this->context['entity_type'];
$entity_info = entity_get_info($entity_type);
// If this is a entity view callback.
if (isset($entity_info['render cache storage']['callback'])) {
$build = $entity_info['render cache storage']['callback']($entities, $view_mode, $langcode, $entity_type);
}
else {
$page = $this
->getPageArgument();
$build = entity_get_controller($entity_type)
->view($entities, $view_mode, $langcode, $page);
}
$build = reset($build);
return $build;
}
/**
* Helper function to retrieve missing $page argument from backtrace.
*
* @return bool $page
* The page argument from entity_view() if found - NULL otherwise.
*/
protected function getPageArgument() {
$page = NULL;
// We need the $page variable from entity_view() that it does not pass us.
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
// Get only the stack frames we need (PHP 5.4 only).
$backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
}
elseif (version_compare(PHP_VERSION, '5.3.6', '>=')) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
}
else {
// @see http://php.net/manual/en/function.debug-backtrace.php#refsect1-function.debug-backtrace-parameters
$backtrace = debug_backtrace(TRUE);
}
// As a safety, do not grab an unexpected arg for $page, check that this
// was called from entity_view().
if (isset($backtrace[2]['function']) && $backtrace[2]['function'] === 'entity_view' && isset($backtrace[2]['args'][4])) {
$page = $backtrace[2]['args'][4];
}
return $page;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseController:: |
protected | property | The injected cache backend adapter. | |
BaseController:: |
protected | property | An optional context provided by this controller. | |
BaseController:: |
protected | property | The injected render stack. | |
BaseController:: |
protected | function |
Overrides AbstractBaseController:: |
|
BaseController:: |
protected | function | Determines the caching strategy for a given cache info structure. | |
BaseController:: |
protected | function |
Provides the fully pouplated cache information for a specific object. Overrides AbstractBaseController:: |
|
BaseController:: |
protected | function |
Specific cache info overrides based on the $object. Overrides AbstractBaseController:: |
1 |
BaseController:: |
protected | function | Returns the cache information map for the given objects. | |
BaseController:: |
protected | function |
Overrides AbstractBaseController:: |
|
BaseController:: |
public | function |
Overrides ControllerInterface:: |
|
BaseController:: |
protected | function |
Provides the cache info for all objects based on the context. Overrides AbstractBaseController:: |
2 |
BaseController:: |
protected | function | Get the placeholders from the cache information map. | |
BaseController:: |
public static | function |
Overrides ControllerInterface:: |
|
BaseController:: |
public | function |
Overrides ControllerInterface:: |
|
BaseController:: |
public | function |
Overrides ControllerInterface:: |
1 |
BaseController:: |
public | function |
Overrides ControllerInterface:: |
|
BaseController:: |
public | function | Constructs a controller plugin object. | |
BaseRecursionController:: |
public | function |
Ensures that recursion storage is added to the right cached object. Overrides RecursionControllerInterface:: |
|
BaseRecursionController:: |
protected | function |
Renders uncached objects in a recursion compatible way. Overrides BaseController:: |
|
EntityController:: |
protected | function |
Overrides BaseController:: |
|
EntityController:: |
protected | function |
Overrides BaseController:: |
|
EntityController:: |
protected | function |
Overrides BaseController:: |
|
EntityController:: |
protected | function |
Overrides BaseController:: |
|
EntityController:: |
protected | function | Helper function to retrieve missing $page argument from backtrace. | |
EntityController:: |
protected | function |
Overrides BaseController:: |
|
EntityController:: |
protected | function |
Render uncached objects. Overrides AbstractBaseController:: |