You are here

public function SamlauthAuthmapDeleteForm::buildForm in SAML Authentication 8.3

Same name and namespace in other branches
  1. 4.x src/Form/SamlauthAuthmapDeleteForm.php \Drupal\samlauth\Form\SamlauthAuthmapDeleteForm::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 ConfirmFormBase::buildForm

File

src/Form/SamlauthAuthmapDeleteForm.php, line 94

Class

SamlauthAuthmapDeleteForm
Confirm the user wants to delete an authmap entry.

Namespace

Drupal\samlauth\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $authname = FALSE;
  $uid = $this
    ->getRouteMatch()
    ->getParameter('uid');
  if ($uid && filter_var($uid, FILTER_VALIDATE_INT)) {
    $authname = $this->connection
      ->select('authmap', 'm')
      ->fields('m', [
      'authname',
    ])
      ->condition('m.uid', (int) $uid)
      ->condition('m.provider', 'samlauth')
      ->execute()
      ->fetchField();
  }
  if ($authname === FALSE) {

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