1 {% import 'lib/di.twig' as di %}
4 namespace Drupal\{{ machine_name }}\Plugin\Block;
8 use Drupal\Core\Access\AccessResult;
9 use Drupal\Core\Session\AccountInterface;
11 use Drupal\Core\Block\BlockBase;
13 use Drupal\Core\Form\FormStateInterface;
16 {{ di.use(services) }}
17 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
18 use Symfony\Component\DependencyInjection\ContainerInterface;
23 * Provides {{ plugin_label|article|lower }} block.
26 * id = "{{ plugin_id }}",
27 * admin_label = @Translation("{{ plugin_label }}"),
28 * category = @Translation("{{ category }}")
31 class {{ class }} extends BlockBase {% if services %}implements ContainerFactoryPluginInterface {% endif %}{
34 {{ di.properties(services) }}
37 * Constructs a new {{ class }} instance.
39 * @param array $configuration
40 * The plugin configuration, i.e. an array with configuration values keyed
41 * by configuration option name. The special key 'context' may be used to
42 * initialize the defined contexts by setting it to an array of context
43 * values keyed by context names.
44 * @param string $plugin_id
45 * The plugin_id for the plugin instance.
46 * @param mixed $plugin_definition
47 * The plugin implementation definition.
48 {{ di.annotation(services) }}
50 public function __construct(array $configuration, $plugin_id, $plugin_definition, {{ di.signature(services) }}) {
51 parent::__construct($configuration, $plugin_id, $plugin_definition);
52 {{ di.assignment(services) }}
58 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
63 {{ di.container(services) }}
72 public function defaultConfiguration() {
74 'foo' => $this->t('Hello world!'),
81 public function blockForm($form, FormStateInterface $form_state) {
83 '#type' => 'textarea',
84 '#title' => $this->t('Foo'),
85 '#default_value' => $this->configuration['foo'],
93 public function blockSubmit($form, FormStateInterface $form_state) {
94 $this->configuration['foo'] = $form_state->getValue('foo');
102 protected function blockAccess(AccountInterface $account) {
103 // @DCG Evaluate the access condition here.
105 return AccessResult::allowedIf($condition);
112 public function build() {
113 $build['content'] = [
114 '#markup' => $this->t('It works!'),