You are here

public function SendGridSettingsForm::buildForm in SendGrid Integration 8

Same name and namespace in other branches
  1. 8.2 src/Form/SendGridSettingsForm.php \Drupal\sendgrid_integration\Form\SendGridSettingsForm::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/SendGridSettingsForm.php, line 65

Class

SendGridSettingsForm
Class SendGridSettingsForm.

Namespace

Drupal\sendgrid_integration\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('sendgrid_integration.settings');
  $form['authentication'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Authentication'),
  ];
  $key_exists = $this->moduleHandler
    ->moduleExists('key');
  $requirenewkey = TRUE;
  if (!$key_exists && !empty($config
    ->get('apikey'))) {
    $form['authentication']['secretkeynotice'] = [
      '#markup' => $this
        ->t('You have saved a secret key. You may change the key by inputing a new one in the field directly below.'),
    ];
    $requirenewkey = FALSE;
  }
  if ($key_exists) {
    $form['authentication']['sendgrid_integration_apikey'] = [
      '#type' => 'key_select',
      '#required' => TRUE,
      '#default_value' => $config
        ->get('apikey'),
      '#title' => $this
        ->t('API Secret Key'),
      '#description' => $this
        ->t('The secret key of your key pair. These are only generated once by Sendgrid.'),
    ];
  }
  else {
    $form['authentication']['sendgrid_integration_apikey'] = [
      '#type' => 'password',
      '#required' => $requirenewkey,
      '#title' => $this
        ->t('API Secret Key'),
      '#description' => $this
        ->t('The secret key of your key pair. These are only generated once by Sendgrid. Your existing key is hidden. If you need to change this, provide a new key here.'),
    ];
  }
  return parent::buildForm($form, $form_state);
}