You are here

public function BrightcoveProxyForm::validateForm in Brightcove Video Connect 8.2

Same name and namespace in other branches
  1. 8 modules/brightcove_proxy/src/Form/BrightcoveProxyForm.php \Drupal\brightcove_proxy\Form\BrightcoveProxyForm::validateForm()
  2. 3.x modules/brightcove_proxy/src/Form/BrightcoveProxyForm.php \Drupal\brightcove_proxy\Form\BrightcoveProxyForm::validateForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormBase::validateForm

File

modules/brightcove_proxy/src/Form/BrightcoveProxyForm.php, line 117

Class

BrightcoveProxyForm
Builds form for the Brightcove Proxy settings.

Namespace

Drupal\brightcove_proxy\Form

Code

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

  // Validate proxy config.
  if ($form_state
    ->getValue('use_proxy')) {
    $ch = curl_init("{$_SERVER['HTTP_HOST']}:{$_SERVER['SERVER_PORT']}/brightcove-proxy/test");
    curl_setopt_array($ch, [
      CURLOPT_PROXYUSERPWD => "{$form_state->getValue('proxy_username')}:{$form_state->getValue('proxy_password')}",
      CURLOPT_PROXYAUTH => $form_state
        ->getValue('proxy_auth'),
      CURLOPT_PROXYTYPE => $form_state
        ->getValue('proxy_type'),
      CURLOPT_PROXY => $form_state
        ->getValue('proxy'),
      CURLOPT_PROXYPORT => $form_state
        ->getValue('proxy_port'),
      CURLOPT_HTTPPROXYTUNNEL => $form_state
        ->getValue('http_proxy_tunnel'),
      CURLOPT_RETURNTRANSFER => FALSE,
      CURLOPT_AUTOREFERER => TRUE,
      CURLOPT_FOLLOWLOCATION => TRUE,
      CURLOPT_MAXREDIRS => 5,
    ]);
    curl_exec($ch);
    $info = curl_getinfo($ch);
    if ($info['http_code'] != 200) {
      $form_state
        ->setErrorByName('', curl_error($ch));
    }
    curl_close($ch);
  }
  parent::validateForm($form, $form_state);
}