You are here

public function SubscriptionBlock::blockForm in Mailing List 8

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/SubscriptionBlock.php, line 124

Class

SubscriptionBlock
Mailing list subscription blocks.

Namespace

Drupal\mailing_list\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {

  // Mailing list for this subscription block.
  $options = [];
  foreach ($this->entityTypeManager
    ->getStorage('mailing_list')
    ->loadMultiple() as $list) {
    $options[$list
      ->id()] = $list
      ->label();
  }
  if (count($options) > 1) {
    asort($options, SORT_STRING);
  }
  $form['manage_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show manage subscriptions link'),
    '#default_value' => $this->configuration['manage_link'],
  ];
  $form['list'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Mailing list'),
    '#options' => $options,
    '#required' => TRUE,
    '#default_value' => $this->configuration['list'] ?: key($options),
  ];

  // Block message.
  $form['message'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Block message'),
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => $this
      ->t('Message to the user. Leave empty for display the mailing list configured help. Enter @none for no message at all.', [
      '@none' => '<none>',
    ]),
    '#default_value' => $this->configuration['message'],
  ];

  // Subscription form ID.
  $form['form_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Form ID'),
    '#field_prefix' => 'mailing_list_subscription_&lt;LIST-ID&gt;_',
    '#field_suffix' => '_block_form',
    '#size' => 16,
    '#maxlength' => 32,
    '#description' => $this
      ->t('Customize the subscription form ID.'),
    '#default_value' => $this->configuration['form_id'],
  ];
  return $form;
}