Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / templates / module / src / Plugin / Block / block.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 \Drupal\{{module}}\Plugin\Block\{{class_name}}.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{module}}\Plugin\Block;
9 {% endblock %}
10
11 {% block use_class %}
12 use Drupal\Core\Block\BlockBase;
13 {% if inputs %}
14 use Drupal\Core\Form\FormStateInterface;
15 {% endif %}
16 {% if services is not empty %}
17 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
18 use Symfony\Component\DependencyInjection\ContainerInterface;
19 {% endif %}
20 {% endblock %}
21
22 {% block class_declaration %}
23 /**
24  * Provides a '{{class_name}}' block.
25  *
26  * @Block(
27  *  id = "{{plugin_id}}",
28  *  admin_label = @Translation("{{label}}"),
29  * )
30  */
31 class {{class_name}} extends BlockBase {% if services is not empty %}implements ContainerFactoryPluginInterface {% endif %}{% endblock %}
32 {% block class_construct %}
33 {% if services is not empty %}
34   /**
35    * Constructs a new {{class_name}} object.
36    *
37    * @param array $configuration
38    *   A configuration array containing information about the plugin instance.
39    * @param string $plugin_id
40    *   The plugin_id for the plugin instance.
41    * @param string $plugin_definition
42    *   The plugin implementation definition.
43    */
44   public function __construct(
45         array $configuration,
46         $plugin_id,
47         $plugin_definition,
48         {{ servicesAsParameters(services)|join(', \n\t') }}
49   ) {
50     parent::__construct($configuration, $plugin_id, $plugin_definition);
51 {{ serviceClassInitialization(services) }}
52   }
53 {% endif %}
54 {% endblock %}
55 {% block class_create %}
56 {% if services is not empty %}
57   /**
58    * {@inheritdoc}
59    */
60   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
61     return new static(
62       $configuration,
63       $plugin_id,
64       $plugin_definition,
65 {{ serviceClassInjection(services) }}
66     );
67   }
68 {% endif %}
69 {% endblock %}
70 {% block class_methods %}
71 {% if inputs %}
72
73   /**
74    * {@inheritdoc}
75    */
76   public function defaultConfiguration() {
77     return [
78     {% for input in inputs %}
79      '{{ input.name }}' => {{ input.default_code }},
80     {% endfor %}
81     ] + parent::defaultConfiguration();
82
83  }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function blockForm($form, FormStateInterface $form_state) {
89 {% for input in inputs %}
90     $form['{{ input.name }}'] = [
91       '#type' => '{{ input.type }}',
92       '#title' => $this->t('{{ input.label }}'),
93       '#description' => $this->t('{{ input.description }}'),
94 {% if input.options|length %}
95       '#options' => {{ input.options }},
96 {% endif %}
97       '#default_value' => $this->configuration['{{ input.name  }}'],
98 {% if input.maxlength|length %}
99       '#maxlength' => {{ input.maxlength }},
100 {% endif %}
101 {% if input.size|length %}
102       '#size' => {{ input.size }},
103 {% endif %}
104 {% if input.weight|length %}
105       '#weight' => '{{ input.weight }}',
106 {% endif %}
107     ];
108 {% endfor %}
109
110     return $form;
111   }
112
113   /**
114    * {@inheritdoc}
115    */
116   public function blockSubmit($form, FormStateInterface $form_state) {
117 {% for input in inputs %}
118     $this->configuration['{{ input.name }}'] = $form_state->getValue('{{ input.name }}');
119 {% endfor %}
120   }
121
122 {% endif %}
123   /**
124    * {@inheritdoc}
125    */
126   public function build() {
127     $build = [];
128 {% for input in inputs %}
129     $build['{{plugin_id}}_{{ input.name }}']['#markup'] = '<p>' . $this->configuration['{{ input.name }}'] . '</p>';
130 {% else %}
131     $build['{{plugin_id}}']['#markup'] = 'Implement {{class_name}}.';
132 {% endfor %}
133
134     return $build;
135   }
136 {% endblock %}