394402af4b8d6d10e2a27bcaffe5aba23ec493b0
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / service / cache-context.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\Cache\Context;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Cache\Context\{{ interface }};
7 {% if base_class %}
8 use Drupal\Core\Cache\Context\{{ base_class }};
9 {% endif %}
10
11 /**
12  * Defines the ExampleCacheContext service.
13  *
14  * Cache context ID: '{{ context_id }}'.
15  *
16  * @DCG
17  * Check out the core/lib/Drupal/Core/Cache/Context directory for examples of
18  * cache contexts provided by Drupal core.
19  */
20 class {{ class }} {% if base_class %}extends {{ base_class }} {% endif %}implements {{ interface }} {
21
22   /**
23    * {@inheritdoc}
24    */
25   public static function getLabel() {
26     return t('{{ context_label }}');
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function getContext({% if calculated %}$parameter = NULL{% endif %}) {
33     // @DCG: Define the cache context here.
34     $context = 'some_string_value';
35     return $context;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getCacheableMetadata({% if calculated %}$parameter = NULL{% endif %}) {
42     return new CacheableMetadata();
43   }
44
45 }