Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / block / tests / modules / block_test / src / Plugin / Block / TestBlockInstantiation.php
1 <?php
2
3 namespace Drupal\block_test\Plugin\Block;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Block\BlockBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Session\AccountInterface;
9
10 /**
11  * Provides a basic block for testing block instantiation and configuration.
12  *
13  * @Block(
14  *   id = "test_block_instantiation",
15  *   admin_label = @Translation("Display message")
16  * )
17  */
18 class TestBlockInstantiation extends BlockBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function defaultConfiguration() {
24     return [
25       'display_message' => 'no message set',
26     ];
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function blockAccess(AccountInterface $account) {
33     return AccessResult::allowedIfHasPermission($account, 'access content');
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function blockForm($form, FormStateInterface $form_state) {
40     $form['display_message'] = [
41       '#type' => 'textfield',
42       '#title' => $this->t('Display message'),
43       '#default_value' => $this->configuration['display_message'],
44     ];
45     return $form;
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function blockSubmit($form, FormStateInterface $form_state) {
52     $this->configuration['display_message'] = $form_state->getValue('display_message');
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function build() {
59     return [
60       '#children' => $this->configuration['display_message'],
61     ];
62   }
63
64 }