You are here

public function SalesforceAuthSettings::buildForm in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Form/SalesforceAuthSettings.php \Drupal\salesforce\Form\SalesforceAuthSettings::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/SalesforceAuthSettings.php, line 77

Class

SalesforceAuthSettings
Class SalesforceAuthSettings.

Namespace

Drupal\salesforce\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  if (!$this->salesforceAuth
    ->hasProviders()) {
    return [
      '#markup' => 'No auth providers have been enabled. Please enable an auth provider and create an auth config before continuing.',
    ];
  }
  $config = $this
    ->config('salesforce.settings');
  $form = parent::buildForm($form, $form_state);
  $options = [];
  foreach ($this->salesforceAuth
    ->getProviders() as $provider) {
    $options[$provider
      ->id()] = $provider
      ->label() . ' (' . $provider
      ->getPlugin()
      ->label() . ')';
  }
  if (empty($options)) {
    return [
      '#markup' => 'No auth providers found. Please add an auth provider before continuing.',
    ];
  }
  $options = [
    '' => '- None -',
  ] + $options;
  $form['provider'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Choose a default auth provider'),
    '#options' => $options,
    '#default_value' => $config
      ->get('salesforce_auth_provider') ? $config
      ->get('salesforce_auth_provider') : '',
  ];
  $form['#theme'] = 'system_config_form';
  return $form;
}