You are here

public function Oauth2GenerateKeyForm::buildForm in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same name and namespace in other branches
  1. 8.3 src/Entity/Form/Oauth2GenerateKeyForm.php \Drupal\simple_oauth\Entity\Form\Oauth2GenerateKeyForm::buildForm()
  2. 5.x src/Entity/Form/Oauth2GenerateKeyForm.php \Drupal\simple_oauth\Entity\Form\Oauth2GenerateKeyForm::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

src/Entity/Form/Oauth2GenerateKeyForm.php, line 52

Class

Oauth2GenerateKeyForm
@internal

Namespace

Drupal\simple_oauth\Entity\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $pubk_id = NULL, $pk_id = NULL) {

  // Hidden public key id.
  $form['key_settings']['pubk_id'] = [
    '#type' => 'hidden',
    '#required' => TRUE,
    '#value' => $pubk_id,
  ];

  // Hidden private key id.
  $form['key_settings']['pk_id'] = [
    '#type' => 'hidden',
    '#required' => TRUE,
    '#value' => $pk_id,
  ];

  // Error Messages container.
  $form['key_settings']['message'] = [
    '#markup' => '<div id="key-error-message" class="messages messages--error"></div>',
    '#hidden' => TRUE,
  ];
  $disclaimer = '<p>' . $this
    ->t('This is the directory where the public and private keys will be stored after generation. This <strong>SHOULD</strong> be located outside of your webroot to avoid making them public unintentionally.') . '</p><p>' . $this
    ->t('Any keys already present in this directory will be deleted.') . '</p>';

  // Private Key Path.
  $form['key_settings']['directory'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Directory for the keys'),
    '#description' => $disclaimer,
    '#required' => TRUE,
    '#attributes' => [
      'id' => "dir_path",
    ],
  ];

  // Submit.
  $form['key_settings']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Generate'),
    '#ajax' => [
      'callback' => '::generateKeys',
      'event' => 'click',
    ],
  ];
  return $form;
}