You are here

public function OpenIDConnectClientFormBase::buildForm in OpenID Connect / OAuth client 2.x

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 EntityForm::buildForm

File

src/Form/OpenIDConnectClientFormBase.php, line 64

Class

OpenIDConnectClientFormBase
Form handler for the OpenID Connect client add and edit forms.

Namespace

Drupal\openid_connect\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) : array {
  $form = parent::buildForm($form, $form_state);

  /** @var \Drupal\openid_connect\Entity\OpenIDConnectClientEntity $entity */
  $entity = $this->entity;
  $form['#tree'] = TRUE;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Name'),
    '#maxlength' => 255,
    '#default_value' => $entity
      ->label(),
    '#required' => TRUE,
  ];

  // If the entity is new, provide an AJAX-generated Redirect URL.
  if ($entity
    ->isNew()) {
    $form['label']['#ajax'] = [
      'callback' => '::changeRedirectUrl',
      'event' => 'focusout',
      'disable-refocus' => TRUE,
      'wrapper' => 'redirect-url-value',
    ];
  }
  $form['id'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#default_value' => $entity
      ->id(),
    '#machine_name' => [
      'exists' => [
        $this,
        'exists',
      ],
      'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
      'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".',
    ],
    '#disabled' => !$entity
      ->isNew(),
  ];
  $form['settings'] = [];
  $subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
  $form['settings'] = $this
    ->getPluginForm($entity
    ->getPlugin())
    ->buildConfigurationForm($form['settings'], $subform_state);
  $form['redirect_url'] = [
    '#title' => $this
      ->t('Redirect URL'),
    '#type' => 'item',
    '#markup' => '<div id="redirect-url-value">' . $this
      ->getRedirectUrl($entity
      ->id()) . '</div>',
  ];
  return $form;
}