1 {% extends "base/class.php.twig" %}
4 \Drupal\{{module}}\Plugin\Block\{{class_name}}.
7 {% block namespace_class %}
8 namespace Drupal\{{module}}\Plugin\Block;
12 use Drupal\Core\Block\BlockBase;
14 use Drupal\Core\Form\FormStateInterface;
16 {% if services is not empty %}
17 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
18 use Symfony\Component\DependencyInjection\ContainerInterface;
22 {% block class_declaration %}
24 * Provides a '{{class_name}}' block.
27 * id = "{{plugin_id}}",
28 * admin_label = @Translation("{{label}}"),
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 %}
35 * Constructs a new {{class_name}} object.
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.
44 public function __construct(
48 {{ servicesAsParameters(services)|join(', \n\t') }}
50 parent::__construct($configuration, $plugin_id, $plugin_definition);
51 {{ serviceClassInitialization(services) }}
55 {% block class_create %}
56 {% if services is not empty %}
60 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
65 {{ serviceClassInjection(services) }}
70 {% block class_methods %}
76 public function defaultConfiguration() {
78 {% for input in inputs %}
79 '{{ input.name }}' => {{ input.default_code }},
81 ] + parent::defaultConfiguration();
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 }},
97 '#default_value' => $this->configuration['{{ input.name }}'],
98 {% if input.maxlength|length %}
99 '#maxlength' => {{ input.maxlength }},
101 {% if input.size|length %}
102 '#size' => {{ input.size }},
104 {% if input.weight|length %}
105 '#weight' => '{{ input.weight }}',
116 public function blockSubmit($form, FormStateInterface $form_state) {
117 {% for input in inputs %}
118 $this->configuration['{{ input.name }}'] = $form_state->getValue('{{ input.name }}');
126 public function build() {
128 {% for input in inputs %}
129 $build['{{plugin_id}}_{{ input.name }}']['#markup'] = '<p>' . $this->configuration['{{ input.name }}'] . '</p>';
131 $build['{{plugin_id}}']['#markup'] = 'Implement {{class_name}}.';