Version 1
[yaffs-website] / web / core / modules / config / tests / config_override_integration_test / src / Cache / ConfigOverrideIntegrationTestCacheContext.php
diff --git a/web/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php b/web/core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php
new file mode 100644 (file)
index 0000000..de9fefc
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+namespace Drupal\config_override_integration_test\Cache;
+
+use Drupal\Core\Cache\CacheableMetadata;
+use Drupal\Core\Cache\Context\CacheContextInterface;
+
+/**
+ * A cache context service intended for the config override integration test.
+ *
+ * Cache context ID: 'config_override_integration_test'.
+ */
+class ConfigOverrideIntegrationTestCacheContext implements CacheContextInterface {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getLabel() {
+    return t('Config override integration test');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getContext() {
+    // Default to the 'disabled' state.
+    $state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE) ? 'yes' : 'no';
+    return 'config_override_integration_test.' . $state;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheableMetadata() {
+    // Since this depends on State this can change at any time and is not
+    // cacheable.
+    $metadata = new CacheableMetadata();
+    $metadata->setCacheMaxAge(0);
+    return $metadata;
+  }
+
+}