3 namespace Drupal\block_test\Plugin\Block;
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Block\BlockBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Session\AccountInterface;
11 * Provides a basic block for testing block instantiation and configuration.
14 * id = "test_block_instantiation",
15 * admin_label = @Translation("Display message")
18 class TestBlockInstantiation extends BlockBase {
23 public function defaultConfiguration() {
25 'display_message' => 'no message set',
32 protected function blockAccess(AccountInterface $account) {
33 return AccessResult::allowedIfHasPermission($account, 'access content');
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'],
51 public function blockSubmit($form, FormStateInterface $form_state) {
52 $this->configuration['display_message'] = $form_state->getValue('display_message');
58 public function build() {
60 '#children' => $this->configuration['display_message'],