You are here

public function FacebookCommentsBlock::blockValidate in Facebook Comments Block 8.2

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

Overrides BlockPluginTrait::blockValidate

File

src/Plugin/Block/FacebookCommentsBlock.php, line 282

Class

FacebookCommentsBlock
Provides a 'Facebook Comments Block' block.

Namespace

Drupal\facebook_comments_block\Plugin\Block

Code

public function blockValidate($form, FormStateInterface $form_state) {
  $main_domain = $form_state
    ->getValue(array(
    'facebook_comments_settings',
    'facebook_comments_block_settings_domain',
  ));
  if ($main_domain !== '' && !UrlHelper::isValid($main_domain, TRUE)) {
    $this
      ->messenger()
      ->addError($this
      ->t('Main domain must be a valid absolute URL.'));
    $form_state
      ->setErrorByName('facebook_comments_block_settings_domain', $this
      ->t('Main domain must be a valid absolute URL.'));
  }
  $number_of_posts = $form_state
    ->getValue(array(
    'facebook_comments_settings',
    'facebook_comments_block_settings_number_of_posts',
  ));
  if (!is_numeric($number_of_posts)) {
    $this
      ->messenger()
      ->addError($this
      ->t('Number of posts must be a valid number.'));
    $form_state
      ->setErrorByName('facebook_comments_block_settings_number_of_posts', $this
      ->t('Number of posts must be a valid number.'));
  }
  $width = $form_state
    ->getValue(array(
    'facebook_comments_settings',
    'facebook_comments_block_settings_width',
  ));
  if (!is_numeric($width)) {
    $this
      ->messenger()
      ->addError($this
      ->t('Width must be a valid number.'));
    $form_state
      ->setErrorByName('facebook_comments_block_settings_width', $this
      ->t('Width must be a valid number.'));
  }
}