forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.php.twig
More file actions
121 lines (107 loc) · 3.01 KB
/
Copy pathblock.php.twig
File metadata and controls
121 lines (107 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{% extends "base/class.php.twig" %}
{% block file_path %}
Drupal\{{module}}\Plugin\Block\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\Block;
{% endblock %}
{% block use_class %}
use Drupal\Core\Block\BlockBase;
{% if inputs %}
use Drupal\Core\Form\FormStateInterface;
{% endif %}
{% if services is not empty %}
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block class_declaration %}
/**
* Provides a '{{class_name}}' block.
*
* @Block(
* id = "{{plugin_id}}",
* admin_label = @Translation("{{label}}"),
* )
*/
class {{class_name}} extends BlockBase {% if services is not empty %}implements ContainerFactoryPluginInterface {% endif %}
{% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
* Construct.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param string $plugin_definition
* The plugin implementation definition.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
{{ servicesAsParameters(services)|join(', \n\t') }}
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
{{ serviceClassInitialization(services) }}
}
{% endif %}
{% endblock %}
{% block class_create %}
{% if services is not empty %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}
{% if inputs %}
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
{% for input in inputs %}
$form['{{ input.name }}'] = array(
'#type' => '{{ input.type }}',
'#title' => $this->t('{{ input.label }}'),
'#description' => $this->t('{{ input.description }}'),
{% if input.options|length %}
'#options' => {{ input.options }},
{% endif %}
'#default_value' => isset($this->configuration['{{ input.name }}']) ? $this->configuration['{{ input.name }}'] : '',
);
{% endfor %}
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
{% for input in inputs %}
$this->configuration['{{ input.name }}'] = $form_state->getValue('{{ input.name }}');
{% endfor %}
}
{% endif %}
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
{% for input in inputs %}
$build['{{plugin_id}}_{{ input.name }}']['#markup'] = '<p>' . $this->configuration['{{ input.name }}'] . '</p>';
{% else %}
$build['{{plugin_id}}']['#markup'] = 'Implement {{class_name}}.';
{% endfor %}
return $build;
}
{% endblock %}