You are here

public function SendGridSettingsForm::buildForm in SendGrid Integration 8.2

Same name and namespace in other branches
  1. 8 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.'),
    ];
  }
  $form['settings'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Settings'),
  ];
  $form['settings']['sendgrig_intergration_trackopens'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Track Opens'),
    '#description' => $this
      ->t('Track opening of emails. This will include a small image in each email. Set to off by default.'),
    '#default_value' => !empty($config
      ->get('trackopens')) ? $config
      ->get('trackopens') : 0,
  ];
  $form['settings']['sendgrig_intergration_trackclicks'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Track Clicks'),
    '#description' => $this
      ->t('Track the clicking of links in email. Set to off by default.'),
    '#default_value' => !empty($config
      ->get('trackclicks')) ? $config
      ->get('trackclicks') : 0,
  ];
  return parent::buildForm($form, $form_state);
}