Chris@5
|
1 {% import 'lib/di.twig' as di %}
|
Chris@0
|
2 <?php
|
Chris@0
|
3
|
Chris@0
|
4 namespace Drupal\{{ machine_name }}\Plugin\views\argument_default;
|
Chris@0
|
5
|
Chris@5
|
6 {% sort %}
|
Chris@0
|
7 use Drupal\Core\Cache\Cache;
|
Chris@0
|
8 use Drupal\Core\Cache\CacheableDependencyInterface;
|
Chris@5
|
9 {% if configurable %}
|
Chris@0
|
10 use Drupal\Core\Form\FormStateInterface;
|
Chris@5
|
11 {% endif %}
|
Chris@0
|
12 use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
|
Chris@5
|
13 {% if services %}
|
Chris@5
|
14 {{ di.use(services) }}
|
Chris@0
|
15 use Symfony\Component\DependencyInjection\ContainerInterface;
|
Chris@5
|
16 {% endif %}
|
Chris@5
|
17 {% endsort %}
|
Chris@0
|
18
|
Chris@0
|
19 /**
|
Chris@5
|
20 * {{ plugin_label }} argument default plugin.
|
Chris@0
|
21 *
|
Chris@0
|
22 * @ViewsArgumentDefault(
|
Chris@0
|
23 * id = "{{ plugin_id }}",
|
Chris@0
|
24 * title = @Translation("{{ plugin_label }}")
|
Chris@0
|
25 * )
|
Chris@0
|
26 */
|
Chris@0
|
27 class {{ class }} extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
|
Chris@0
|
28
|
Chris@5
|
29 {% if services %}
|
Chris@5
|
30 {{ di.properties(services) }}
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * Constructs a new {{ class }} instance.
|
Chris@0
|
34 *
|
Chris@0
|
35 * @param array $configuration
|
Chris@5
|
36 * The plugin configuration, i.e. an array with configuration values keyed
|
Chris@5
|
37 * by configuration option name. The special key 'context' may be used to
|
Chris@5
|
38 * initialize the defined contexts by setting it to an array of context
|
Chris@5
|
39 * values keyed by context names.
|
Chris@0
|
40 * @param string $plugin_id
|
Chris@0
|
41 * The plugin_id for the plugin instance.
|
Chris@0
|
42 * @param mixed $plugin_definition
|
Chris@0
|
43 * The plugin implementation definition.
|
Chris@5
|
44 {{ di.annotation(services) }}
|
Chris@0
|
45 */
|
Chris@5
|
46 public function __construct(array $configuration, $plugin_id, $plugin_definition, {{ di.signature(services) }}) {
|
Chris@0
|
47 parent::__construct($configuration, $plugin_id, $plugin_definition);
|
Chris@5
|
48 {{ di.assignment(services) }}
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 /**
|
Chris@0
|
52 * {@inheritdoc}
|
Chris@0
|
53 */
|
Chris@0
|
54 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
Chris@0
|
55 return new static(
|
Chris@0
|
56 $configuration,
|
Chris@0
|
57 $plugin_id,
|
Chris@0
|
58 $plugin_definition,
|
Chris@5
|
59 {{ di.container(services) }}
|
Chris@0
|
60 );
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@5
|
63 {% endif %}
|
Chris@5
|
64 {% if configurable %}
|
Chris@0
|
65 /**
|
Chris@0
|
66 * {@inheritdoc}
|
Chris@0
|
67 */
|
Chris@0
|
68 protected function defineOptions() {
|
Chris@0
|
69 $options = parent::defineOptions();
|
Chris@5
|
70 $options['example'] = ['default' => ''];
|
Chris@0
|
71 return $options;
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * {@inheritdoc}
|
Chris@0
|
76 */
|
Chris@0
|
77 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
Chris@5
|
78 $form['example'] = [
|
Chris@0
|
79 '#type' => 'textfield',
|
Chris@5
|
80 '#title' => $this->t('Example'),
|
Chris@5
|
81 '#default_value' => $this->options['example'],
|
Chris@0
|
82 ];
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@5
|
85 {% endif %}
|
Chris@0
|
86 /**
|
Chris@0
|
87 * {@inheritdoc}
|
Chris@0
|
88 */
|
Chris@0
|
89 public function getArgument() {
|
Chris@0
|
90
|
Chris@0
|
91 // @DCG
|
Chris@0
|
92 // Here is the place where you should create a default argument for the
|
Chris@0
|
93 // contextual filter. The source of this argument depends on your needs.
|
Chris@0
|
94 // For example, you can extract the value from the URL or fetch it from
|
Chris@0
|
95 // some fields of the current viewed entity.
|
Chris@5
|
96 $argument = 123;
|
Chris@0
|
97
|
Chris@0
|
98 return $argument;
|
Chris@0
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 /**
|
Chris@0
|
102 * {@inheritdoc}
|
Chris@0
|
103 */
|
Chris@0
|
104 public function getCacheMaxAge() {
|
Chris@0
|
105 return Cache::PERMANENT;
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 /**
|
Chris@0
|
109 * {@inheritdoc}
|
Chris@0
|
110 */
|
Chris@0
|
111 public function getCacheContexts() {
|
Chris@5
|
112 // @DCG Use 'url' context if the argument comes from URL.
|
Chris@5
|
113 return [];
|
Chris@0
|
114 }
|
Chris@0
|
115
|
Chris@0
|
116 }
|