You are here

public function OAuthKeyForm::buildForm in Lightning API 8

Same name and namespace in other branches
  1. 8.4 src/Form/OAuthKeyForm.php \Drupal\lightning_api\Form\OAuthKeyForm::buildForm()
  2. 8.2 src/Form/OAuthKeyForm.php \Drupal\lightning_api\Form\OAuthKeyForm::buildForm()
  3. 8.3 src/Form/OAuthKeyForm.php \Drupal\lightning_api\Form\OAuthKeyForm::buildForm()

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/OAuthKeyForm.php, line 79

Class

OAuthKeyForm

Namespace

Drupal\lightning_api\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  if (extension_loaded('openssl') == FALSE) {
    drupal_set_message($this
      ->t('The OpenSSL extension is unavailable. Please enable it to generate OAuth keys.'), 'error');
    return $form;
  }
  if ($this->key
    ->exists() && $form_state
    ->isSubmitted() == FALSE && $form_state
    ->isRebuilding() == FALSE) {
    drupal_set_message($this
      ->t('A key pair already exists and will be overwritten if you generate new keys.'), 'warning');
  }
  $form['dir'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Destination'),
    '#description' => $this
      ->t('Path to the directory in which to store the generated keys.'),
    '#required' => TRUE,
    '#element_validate' => [
      '::validateDestinationExists',
    ],
  ];
  $form['advanced'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced'),
  ];
  $form['advanced']['private_key'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Private key name'),
    '#description' => $this
      ->t('File name of the generated private key. Will be automatically generated if left empty.'),
    '#element_validate' => [
      '::validateKeyFileName',
    ],
  ];
  $form['advanced']['public_key'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Public key name'),
    '#description' => $this
      ->t('File name of the generated public key. Will be automatically generated if left empty.'),
    '#element_validate' => [
      '::validateKeyFileName',
    ],
  ];
  $form['advanced']['conf'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('OpenSSL configuration file'),
    '#description' => $this
      ->t('Path to the openssl.cnf configuration file. PHP will attempt to auto-detect this if not specified.'),
  ];
  $form['generate'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Generate keys'),
  ];
  return $form;
}