Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\book\Cache;
|
||||
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Cache\Context\CacheContextInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
@ -14,6 +15,8 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||
/**
|
||||
* Defines the book navigation cache context service.
|
||||
*
|
||||
* Cache context ID: 'route.book_navigation'.
|
||||
*
|
||||
* This allows for book navigation location-aware caching. It depends on:
|
||||
* - whether the current route represents a book node at all
|
||||
* - and if so, where in the book hierarchy we are
|
||||
|
@ -65,7 +68,27 @@ class BookNavigationCacheContext extends ContainerAware implements CacheContextI
|
|||
// If we're looking at a book node, get the trail for that node.
|
||||
$active_trail = $this->container->get('book.manager')
|
||||
->getActiveTrailIds($node->book['bid'], $node->book);
|
||||
return 'book.' . implode('|', $active_trail);
|
||||
return implode('|', $active_trail);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheableMetadata() {
|
||||
// The book active trail depends on the node and data attached to it.
|
||||
// That information is however not stored as part of the node.
|
||||
$cacheable_metadata = new CacheableMetadata();
|
||||
if ($node = $this->requestStack->getCurrentRequest()->get('node')) {
|
||||
// If the node is part of a book then we can use the cache tag for that
|
||||
// book. If not, then it can't be optimized away.
|
||||
if (!empty($node->book['bid'])) {
|
||||
$cacheable_metadata->addCacheTags(['bid:' . $node->book['bid']]);
|
||||
}
|
||||
else {
|
||||
$cacheable_metadata->setCacheMaxAge(0);
|
||||
}
|
||||
}
|
||||
return $cacheable_metadata;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue