v1/vendor/chi-teck/drupal-code-generator/templates/service/cache-context/cache-context.twig

46 lines
1.0 KiB
Twig

<?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();
}
}