You are here

public function SalesforceJWTPlugin::buildConfigurationForm in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 5.0.x modules/salesforce_jwt/src/Plugin/SalesforceAuthProvider/SalesforceJWTPlugin.php \Drupal\salesforce_jwt\Plugin\SalesforceAuthProvider\SalesforceJWTPlugin::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

File

modules/salesforce_jwt/src/Plugin/SalesforceAuthProvider/SalesforceJWTPlugin.php, line 94

Class

SalesforceJWTPlugin
JWT Oauth plugin.

Namespace

Drupal\salesforce_jwt\Plugin\SalesforceAuthProvider

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  if (!$this->keyRepository
    ->getKeyNamesAsOptions([
    'type' => 'authentication',
  ])) {
    $this
      ->messenger()
      ->addError($this
      ->t('Please <a href="@href">add an authentication key</a> before creating a JWT Auth provider.', [
      '@href' => Url::fromRoute('entity.key.add_form')
        ->toString(),
    ]));
    return $form;
  }
  $form['consumer_key'] = [
    '#title' => $this
      ->t('Salesforce consumer key'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('Consumer key of the Salesforce remote application you want to grant access to'),
    '#required' => TRUE,
    '#default_value' => $this
      ->getCredentials()
      ->getConsumerKey(),
  ];
  $form['login_user'] = [
    '#title' => $this
      ->t('Salesforce login user'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('User account to issue token to'),
    '#required' => TRUE,
    '#default_value' => $this
      ->getCredentials()
      ->getLoginUser(),
  ];
  $form['login_url'] = [
    '#title' => $this
      ->t('Login URL'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getCredentials()
      ->getLoginUrl(),
    '#description' => $this
      ->t('Enter a login URL, either https://login.salesforce.com or https://test.salesforce.com.'),
    '#required' => TRUE,
  ];

  // Can't use key-select input type here because its #process method doesn't
  // fire on ajax, so the list is empty. DERP.
  $form['encrypt_key'] = [
    '#title' => 'Private Key',
    '#type' => 'select',
    '#empty_option' => $this
      ->t('- Select -'),
    '#options' => $this->keyRepository
      ->getKeyNamesAsOptions([
      'type' => 'authentication',
    ]),
    '#required' => TRUE,
    '#default_value' => $this
      ->getCredentials()
      ->getKeyId(),
  ];
  return $form;
}