Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / service / cache-context.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/service/cache-context.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/service/cache-context.twig
new file mode 100644 (file)
index 0000000..394402a
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Cache\Context;
+
+use Drupal\Core\Cache\CacheableMetadata;
+use Drupal\Core\Cache\Context\{{ interface }};
+{% if base_class %}
+use Drupal\Core\Cache\Context\{{ base_class }};
+{% endif %}
+
+/**
+ * Defines the ExampleCacheContext service.
+ *
+ * Cache context ID: '{{ context_id }}'.
+ *
+ * @DCG
+ * Check out the core/lib/Drupal/Core/Cache/Context directory for examples of
+ * cache contexts provided by Drupal core.
+ */
+class {{ class }} {% if base_class %}extends {{ base_class }} {% endif %}implements {{ interface }} {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getLabel() {
+    return t('{{ context_label }}');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getContext({% if calculated %}$parameter = NULL{% endif %}) {
+    // @DCG: Define the cache context here.
+    $context = 'some_string_value';
+    return $context;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheableMetadata({% if calculated %}$parameter = NULL{% endif %}) {
+    return new CacheableMetadata();
+  }
+
+}