You are here

public function AuthmapDeleteForm::buildForm in External Authentication 2.0.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 ConfirmFormBase::buildForm

File

src/Form/AuthmapDeleteForm.php, line 97

Class

AuthmapDeleteForm
Confirm the user wants to delete an authmap entry.

Namespace

Drupal\externalauth\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // This form has uid + provider in its URL, not authname + provider, to not
  // expose authnames externally in e.g. HTTP referrer logs.
  $authname = FALSE;
  $provider = $this
    ->getRouteMatch()
    ->getParameter('provider');
  $uid = $this
    ->getRouteMatch()
    ->getParameter('uid');
  if ($provider && $uid && filter_var($uid, FILTER_VALIDATE_INT)) {
    $authname = $this->connection
      ->select('authmap', 'm')
      ->fields('m', [
      'authname',
    ])
      ->condition('m.uid', (int) $uid)
      ->condition('m.provider', $provider)
      ->execute()
      ->fetchField();
  }
  if ($authname === FALSE) {

    // Display same error for either illegal UID or no record.
    $this
      ->messenger()
      ->addError($this
      ->t('No authmap record found for provider @provider / uid @uid.', [
      '@provider' => $provider,
      '@uid' => $uid,
    ]));
    return [];
  }
  $this->authmapEntry = [
    'provider' => $provider,
    'authname' => $authname,
    'uid' => $uid,
  ];
  return parent::buildForm($form, $form_state);
}