You are here

public function CampaignMonitorSubscribeBlock::blockValidate in Campaign Monitor 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Block/CampaignMonitorSubscribeBlock.php \Drupal\campaignmonitor\Plugin\Block\CampaignMonitorSubscribeBlock::blockValidate()

Adds block type-specific validation for the block form.

Note that this method takes the form structure and form state for the full block configuration form as arguments, not just the elements defined in BlockPluginInterface::blockForm().

Parameters

array $form: The form definition array for the full block configuration form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides BlockPluginTrait::blockValidate

See also

\Drupal\Core\Block\BlockPluginInterface::blockForm()

\Drupal\Core\Block\BlockPluginInterface::blockSubmit()

File

src/Plugin/Block/CampaignMonitorSubscribeBlock.php, line 109

Class

CampaignMonitorSubscribeBlock
Provides a 'Subscribe' block.

Namespace

Drupal\campaignmonitor\Plugin\Block

Code

public function blockValidate($form, FormStateInterface $form_state) {
  $subscribe_option = $form_state
    ->getValue([
    'campaignmonitor',
    'list',
  ]);
  if ($subscribe_option == 'single') {
    $list_id = $form_state
      ->getValue([
      'campaignmonitor',
      'list_id',
    ]);
    if (empty($list_id)) {
      $form_state
        ->setErrorByName('settings[campaignmonitor][list_id]', 'List Selection required');
    }
  }
  if ($subscribe_option == 'segments') {
    $segment_list_id = $form_state
      ->getValue([
      'campaignmonitor',
      'segment_list_id',
    ]);
    if (empty($segment_list_id)) {
      $form_state
        ->setErrorByName('settings[campaignmonitor][segment_list_id]', 'List Selection required');
    }
  }
}