View source
<?php
namespace Drupal\apigee_edge\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class ConnectionConfigForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'apigee_edge.client',
];
}
public function getFormId() {
return 'apigee_edge_connection_config_form.';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['connect_timeout'] = [
'#type' => 'number',
'#title' => $this
->t('Connection timeout'),
'#description' => $this
->t('Number of seconds before an HTTP connection to Apigee Edge is assumed to have timed out.'),
'#default_value' => $this
->config('apigee_edge.client')
->get('http_client_connect_timeout'),
'#min' => 0,
'#step' => 0.1,
'#required' => TRUE,
];
$form['request_timeout'] = [
'#type' => 'number',
'#title' => $this
->t('Request timeout'),
'#description' => $this
->t('Number of seconds before an HTTP response from Apigee Edge is assumed to have timed out.'),
'#default_value' => $this
->config('apigee_edge.client')
->get('http_client_timeout'),
'#min' => 0,
'#step' => 0.1,
'#required' => TRUE,
];
$form['http_proxy'] = [
'#type' => 'textfield',
'#title' => $this
->t('HTTP client proxy'),
'#description' => $this
->t('Leave empty unless an HTTP proxy is needed to connect to Apigee Edge.'),
'#default_value' => $this
->config('apigee_edge.client')
->get('http_client_proxy'),
'#required' => FALSE,
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('apigee_edge.client')
->set('http_client_connect_timeout', $form_state
->getValue('connect_timeout'))
->set('http_client_timeout', $form_state
->getValue('request_timeout'))
->set('http_client_proxy', trim($form_state
->getValue('http_proxy')))
->save();
parent::submitForm($form, $form_state);
}
}