Version 1
[yaffs-website] / web / core / modules / outside_in / src / Cache / Context / OutsideInCacheContext.php
diff --git a/web/core/modules/outside_in/src/Cache/Context/OutsideInCacheContext.php b/web/core/modules/outside_in/src/Cache/Context/OutsideInCacheContext.php
new file mode 100644 (file)
index 0000000..4a24671
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+namespace Drupal\outside_in\Cache\Context;
+
+use Drupal\Core\Cache\CacheableMetadata;
+use Drupal\Core\Cache\Context\CacheContextInterface;
+use Drupal\outside_in\OutsideInManagerInterface;
+
+/**
+ * Defines the OutsideInCacheContext service, for "Outside-In or not" caching.
+ *
+ * Cache context ID: 'outside_in_is_applied'.
+ */
+class OutsideInCacheContext implements CacheContextInterface {
+
+  /**
+   * The Outside-In manager.
+   *
+   * @var \Drupal\outside_in\OutsideInManagerInterface
+   */
+  protected $outsideInManager;
+
+  /**
+   * OutsideInCacheContext constructor.
+   *
+   * @param \Drupal\outside_in\OutsideInManagerInterface $outside_in_manager
+   *   The Outside-In manager.
+   */
+  public function __construct(OutsideInManagerInterface $outside_in_manager) {
+    $this->outsideInManager = $outside_in_manager;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getLabel() {
+    return t('Settings Tray');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getContext() {
+    return $this->outsideInManager->isApplicable() ? '1' : '0';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheableMetadata() {
+    return new CacheableMetadata();
+  }
+
+}