You are here

class PrivateMessageThreadCacheContext in Private Message 8

Same name and namespace in other branches
  1. 8.2 src/Cache/Context/PrivateMessageThreadCacheContext.php \Drupal\private_message\Cache\Context\PrivateMessageThreadCacheContext

Defines the PrivateMessageThread service, for "per thread" caching.

Cache context ID: 'private_message_thread'.

Hierarchy

Expanded class hierarchy of PrivateMessageThreadCacheContext

1 string reference to 'PrivateMessageThreadCacheContext'
private_message.services.yml in ./private_message.services.yml
private_message.services.yml

File

src/Cache/Context/PrivateMessageThreadCacheContext.php, line 14

Namespace

Drupal\private_message\Cache\Context
View source
class PrivateMessageThreadCacheContext implements CacheContextInterface {

  /**
   * The current route matcher.
   *
   * @var \Drupal\Core\Routing\ResettableStackedRouteMatchInterface
   */
  protected $currentRouteMatcher;

  /**
   * Constructs a new UserCacheContextBase class.
   *
   * @param \Drupal\Core\Routing\ResettableStackedRouteMatchInterface $currentRouteMatcher
   *   The current route matcher.
   */
  public function __construct(ResettableStackedRouteMatchInterface $currentRouteMatcher) {
    $this->currentRouteMatcher = $currentRouteMatcher;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Private Message Thread');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    $thread = $this->currentRouteMatcher
      ->getParameter('private_message_thread');
    if ($thread) {
      return $thread
        ->id();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PrivateMessageThreadCacheContext::$currentRouteMatcher protected property The current route matcher.
PrivateMessageThreadCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
PrivateMessageThreadCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
PrivateMessageThreadCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
PrivateMessageThreadCacheContext::__construct public function Constructs a new UserCacheContextBase class.