public function UsersKeyDeleteForm::buildForm in JSON Web Token Authentication (JWT) 8
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
- modules/
users_jwt/ src/ Form/ UsersKeyDeleteForm.php, line 54
Class
- UsersKeyDeleteForm
- Class UsersKeyForm.
Namespace
Drupal\users_jwt\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $key_id = NULL, UserInterface $user = NULL) {
if (!$user) {
return $form;
}
$key = $this->keyRepository
->getKey($key_id);
if (!$key || $key->uid != $user
->id()) {
return $form;
}
// Make key available to ::getCancelUrl().
$this->key = $key;
$form['key'] = [
'#type' => 'value',
'#value' => $key,
];
$header = [
$this
->t('Key ID'),
$this
->t('Key Type'),
$this
->t('Key'),
];
$options = $this->keyRepository
->algorithmOptions();
$row = [
'id' => $key->id,
'alg' => $options[$key->alg] ?? $key->alg,
'pubkey' => Unicode::truncate($key->pubkey, 40, FALSE, TRUE),
];
$rows[] = $row;
$form['key_display'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
return parent::buildForm($form, $form_state);
}