You are here

public function TransactionnalEmailForm::buildForm in SendinBlue 8

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

Class

TransactionnalEmailForm
Class Form Transactionnal emails SMTP.

Namespace

Drupal\sendinblue\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $smtpDetails = $this
    ->configFactory()
    ->get(SendinblueManager::CONFIG_SETTINGS_SEND_EMAIL)
    ->get(SendinblueManager::SMTP_DETAILS);
  $smtpAvailable = $smtpDetails !== NULL;
  if ($smtpAvailable === FALSE) {
    $form['sendinblue_alert'] = [
      '#type' => 'markup',
      '#prefix' => '<div id="sendinblue_alert_area" style="padding: 10px;background-color: #fef5f1;color: #8c2e0b;border-color: #ed541d;border-width: 1px;border-style: solid;">',
      '#markup' => $this
        ->t('Current you can not use SendinBlue SMTP. Please confirm at <a href="@smtp-sendinblue" target="_blank">Here</a>', [
        '@smtp-sendinblue' => 'https://mysmtp.sendinblue.com/?utm_source=drupal_plugin&utm_medium=plugin&utm_campaign=module_link',
      ]),
      '#suffix' => '</div>',
      '#tree' => TRUE,
    ];
  }
  $form['sendinblue_on'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Send emails through SendinBlue SMTP'),
    '#default_value' => $this
      ->configFactory()
      ->get(SendinblueManager::CONFIG_SETTINGS_SEND_EMAIL)
      ->get('sendinblue_on'),
    '#description' => $this
      ->t('Choose "Yes" if you want to use SendinBlue SMTP to send transactional emails.'),
    '#options' => [
      1 => $this
        ->t('Yes'),
      0 => $this
        ->t('No'),
    ],
    '#disabled' => $smtpAvailable === TRUE ? FALSE : TRUE,
  ];
  $form['sendinblue_to_email'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Enter email to send a test'),
    '#description' => $this
      ->t('Select here the email address you want to send a test email to.'),
    '#disabled' => $smtpAvailable === TRUE ? FALSE : TRUE,
    '#states' => [
      // Hide unless needed.
      'visible' => [
        ':input[name="sendinblue_on"]' => [
          'value' => 1,
        ],
      ],
      'required' => [
        ':input[name="sendinblue_on"]' => [
          'value' => 1,
        ],
      ],
    ],
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save Settings'),
    '#disabled' => $smtpAvailable === TRUE ? FALSE : TRUE,
  ];
  return $form;
}