Exemple #1
0
 /**
  * Inherits the cacheability of the other access result, if any.
  *
  * @param \Drupal\Core\Access\AccessResultInterface $other
  *   The other access result, whose cacheability (if any) to inherit.
  *
  * @return $this
  */
 public function inheritCacheability(AccessResultInterface $other)
 {
     if ($other instanceof CacheableInterface) {
         $this->setCacheable($other->isCacheable());
         $this->addCacheContexts($other->getCacheKeys());
         $this->addCacheTags($other->getCacheTags());
         // Use the lowest max-age.
         if ($this->getCacheMaxAge() === Cache::PERMANENT) {
             // The other max-age is either lower or equal.
             $this->setCacheMaxAge($other->getCacheMaxAge());
         } else {
             $this->setCacheMaxAge(min($this->getCacheMaxAge(), $other->getCacheMaxAge()));
         }
     } else {
         $this->setCacheable(FALSE);
     }
     return $this;
 }
Exemple #2
0
 /**
  * Inherits the cacheability of the other access result, if any.
  *
  * @param \Drupal\Core\Access\AccessResultInterface $other
  *   The other access result, whose cacheability (if any) to inherit.
  *
  * @return $this
  */
 public function inheritCacheability(AccessResultInterface $other)
 {
     if ($other instanceof CacheableDependencyInterface) {
         if ($this->getCacheMaxAge() !== 0 && $other->getCacheMaxAge() !== 0) {
             $this->setCacheMaxAge(Cache::mergeMaxAges($this->getCacheMaxAge(), $other->getCacheMaxAge()));
         } else {
             $this->setCacheMaxAge($other->getCacheMaxAge());
         }
         $this->addCacheContexts($other->getCacheContexts());
         $this->addCacheTags($other->getCacheTags());
     } else {
         $this->setCacheMaxAge(0);
     }
     return $this;
 }
 /**
  * Inherits the cacheability of the other access result, if any.
  *
  * @param \Drupal\Core\Access\AccessResultInterface $other
  *   The other access result, whose cacheability (if any) to inherit.
  *
  * @return $this
  */
 public function inheritCacheability(AccessResultInterface $other)
 {
     if ($other instanceof CacheableInterface) {
         $this->setCacheable($other->isCacheable());
         $this->addCacheContexts($other->getCacheContexts());
         $this->addCacheTags($other->getCacheTags());
         $this->setCacheMaxAge(Cache::mergeMaxAges($this->getCacheMaxAge(), $other->getCacheMaxAge()));
     } else {
         $this->setCacheable(FALSE);
     }
     return $this;
 }