You are here

public function SettingsForm::buildForm in Salesforce Suite 8.3

Same name in this branch
  1. 8.3 src/Form/SettingsForm.php \Drupal\salesforce\Form\SettingsForm::buildForm()
  2. 8.3 modules/salesforce_logger/src/Form/SettingsForm.php \Drupal\salesforce_logger\Form\SettingsForm::buildForm()
  3. 8.3 modules/salesforce_encrypt/src/Form/SettingsForm.php \Drupal\salesforce_encrypt\Form\SettingsForm::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 FormInterface::buildForm

File

modules/salesforce_encrypt/src/Form/SettingsForm.php, line 63

Class

SettingsForm
Base form for key add and edit forms.

Namespace

Drupal\salesforce_encrypt\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $options = $this->encryptionProfileManager
    ->getEncryptionProfileNamesAsOptions();
  $default = NULL;
  try {
    $profile = $this->client
      ->getEncryptionProfile();
    if (!empty($profile)) {
      $default = $profile
        ->id();
    }
  } catch (EntityNotFoundException $e) {
    drupal_set_message($e
      ->getFormattableMessage(), 'error');
    drupal_set_message($this
      ->t('Error while loading encryption profile. You will need to <a href=":encrypt">assign a new encryption profile</a>, then <a href=":oauth">re-authenticate to Salesforce</a>.', [
      ':encrypt' => Url::fromRoute('salesforce_encrypt.settings')
        ->toString(),
      ':oauth' => Url::fromRoute('salesforce.authorize')
        ->toString(),
    ]), 'error');
  }
  $form['profile'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Encryption Profile'),
    '#description' => $this
      ->t('Choose an encryption profile with which to encrypt Salesforce information.'),
    '#options' => $options,
    '#default_value' => $default,
    '#empty_option' => $this
      ->t('Do not use encryption'),
  ];
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save configuration'),
    '#button_type' => 'primary',
  ];

  // By default, render the form using system-config-form.html.twig.
  $form['#theme'] = 'system_config_form';
  return $form;
}