You are here

public function ContactInfoBlock::blockForm in Brainstorm profile 8

Overrides BlockPluginTrait::blockForm

File

module/custom/adci_contact_info/src/Plugin/Block/ContactInfoBlock.php, line 74

Class

ContactInfoBlock
Provides an contact info block.

Namespace

Drupal\adci_contact_info\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);
  $config = $this
    ->getConfiguration();
  $defaults = $this
    ->defaultConfiguration();
  $form['info'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Information'),
    '#open' => $defaults['info'] !== $config['info'],
  ];
  $form['info']['info'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Information'),
    '#default_value' => $config['info'],
    '#description' => $this
      ->t('You can use @version placeholder to print the version of Drupal core.'),
  ];
  $form['site'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Site link'),
    '#open' => $defaults['site'] !== $config['site'],
  ];
  $form['site']['link'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link'),
    '#default_value' => $config['site']['link'],
    '#attributes' => [
      'id' => 'adci-info-block-site-link',
    ],
  ];
  $form['site']['text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link text'),
    '#default_value' => $config['site']['text'],
    '#states' => [
      'disabled' => [
        ':input[id="adci-info-block-site-link"]' => [
          'empty' => TRUE,
        ],
      ],
    ],
  ];
  $form['site']['title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title'),
    '#default_value' => $config['site']['title'],
    '#states' => [
      'disabled' => [
        ':input[id="adci-info-block-site-link"]' => [
          'empty' => TRUE,
        ],
      ],
    ],
  ];
  $form['email'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Email'),
    '#open' => $defaults['email'] !== $config['email'],
  ];
  $form['email']['email'] = [
    '#type' => 'email',
    '#title' => $this
      ->t('Email'),
    '#default_value' => $config['email']['email'],
    '#attributes' => [
      'id' => 'adci-info-block-email-email',
    ],
  ];
  $form['email']['title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title'),
    '#default_value' => $config['email']['title'],
    '#states' => [
      'disabled' => [
        ':input[id="adci-info-block-email-email"]' => [
          'empty' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}