'Camelids', 'type' => 'camelids', ])->save(); // Create a "Llama" node. $node = Node::create(['type' => 'camelids']); $node->setTitle('Llama') ->setPublished() ->save(); return $node; } /** * {@inheritdoc} */ protected function getDefaultCacheContexts() { $defaults = parent::getDefaultCacheContexts(); // @see \Drupal\node\Controller\NodeViewController::view() $defaults[] = 'user.roles:anonymous'; return $defaults; } /** * {@inheritdoc} */ protected function getAdditionalCacheContextsForEntity(EntityInterface $entity) { return ['timezone']; } /** * {@inheritdoc} * * Each node must have an author. */ protected function getAdditionalCacheTagsForEntity(EntityInterface $node) { return ['user:' . $node->getOwnerId(), 'user_view']; } /** * {@inheritdoc} */ protected function getAdditionalCacheContextsForEntityListing() { return ['user.node_grants:view']; } }