You are here

public function BaseSettingsForm::validateAdSourceUrl in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/BaseSettingsForm.php \Drupal\fb_instant_articles\Form\BaseSettingsForm::validateAdSourceUrl()

Validate the Ad Source Url field.

Parameters

array $form: FAPI array.

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

File

src/Form/BaseSettingsForm.php, line 193

Class

BaseSettingsForm
Facebook Instant Articles base settings form.

Namespace

Drupal\fb_instant_articles\Form

Code

public function validateAdSourceUrl(array &$form, FormStateInterface $form_state) {

  // Only validate if Source URL is selected as ad type.
  if ($form_state
    ->getValue('ads_type') != AdTypes::AD_TYPE_SOURCE_URL) {
    return;
  }
  $ads_iframe_url = $form_state
    ->getValue('ads_iframe_url');
  if (empty($ads_iframe_url)) {
    $form_state
      ->setErrorByName('ads_iframe_url', $this
      ->t('You must specify a valid source URL for your Ads when using the Source URL ad type.'));
  }
  if (!UrlHelper::isValid($ads_iframe_url, TRUE)) {
    $form_state
      ->setErrorByName('ads_iframe_url', $this
      ->t('You must specify a valid source URL for your Ads when using the Source URL ad type.'));
  }
}