You are here

public function FacebookCommentsBlock::blockValidate in Facebook Comments Block 8

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

Overrides BlockPluginTrait::blockValidate

File

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

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)) {
    drupal_set_message($this
      ->t('Main domain must be a valid absolute URL.'), 'error');
    $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)) {
    drupal_set_message($this
      ->t('Number of posts must be a valid number.'), 'error');
    $form_state
      ->setErrorByName('facebook_comments_block_settings_domain', $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)) {
    drupal_set_message($this
      ->t('Width must be a valid number.'), 'error');
    $form_state
      ->setErrorByName('facebook_comments_block_settings_domain', $this
      ->t('Width must be a valid number.'));
  }
}