class SamlauthAuthmapDeleteForm in SAML Authentication 4.x
Same name and namespace in other branches
- 8.3 src/Form/SamlauthAuthmapDeleteForm.php \Drupal\samlauth\Form\SamlauthAuthmapDeleteForm
Confirm the user wants to delete an authmap entry.
@package Drupal\certificatelogin\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\samlauth\Form\SamlauthAuthmapDeleteForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of SamlauthAuthmapDeleteForm
1 string reference to 'SamlauthAuthmapDeleteForm'
File
- src/
Form/ SamlauthAuthmapDeleteForm.php, line 17
Namespace
Drupal\samlauth\FormView source
class SamlauthAuthmapDeleteForm extends ConfirmFormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* The EntityTypeManager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Temporary storage for the current authmap entry.
*
* @var array
*/
protected $authmapEntry;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('entity_type.manager'));
}
/**
* Constructs a router for Drupal with access check and upcasting.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection to get authmap entries.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The EntityTypeManager service.
*/
public function __construct(Connection $connection, EntityTypeManagerInterface $entity_type_manager) {
$this->connection = $connection;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'samlauth_authmap_delete';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
if (!empty($this->authmapEntry['uid'])) {
/** @var \Drupal\user\Entity\User $user */
$user = $this->entityTypeManager
->getStorage('user')
->load($this->authmapEntry['uid']);
}
return $this
->t('Are you sure you want to delete the link between login ID %id and Drupal user %user?', [
'%id' => $this->authmapEntry['authname'],
'%user' => isset($user) ? $user
->getAccountName() : "<unknown> ({$this->authmapEntry['uid']})",
]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('view.samlauth_map.page');
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$uid = $this
->getRouteMatch()
->getParameter('uid');
if (!$uid || filter_var($uid, FILTER_VALIDATE_INT) === FALSE) {
throw new \LogicException('It should be impossible to submit this form without valid uid parameter.');
}
$this->connection
->delete('authmap')
->condition('uid', (int) $uid)
->condition('provider', 'samlauth')
->execute();
$this
->messenger()
->addStatus($this
->t('The link has been deleted.'));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
2 |
ConfirmFormBase:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormInterface:: |
22 |
ConfirmFormBase:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormInterface:: |
14 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SamlauthAuthmapDeleteForm:: |
protected | property | Temporary storage for the current authmap entry. | |
SamlauthAuthmapDeleteForm:: |
protected | property | The database connection. | |
SamlauthAuthmapDeleteForm:: |
protected | property | The EntityTypeManager service. | |
SamlauthAuthmapDeleteForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
SamlauthAuthmapDeleteForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
SamlauthAuthmapDeleteForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
SamlauthAuthmapDeleteForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SamlauthAuthmapDeleteForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
SamlauthAuthmapDeleteForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
SamlauthAuthmapDeleteForm:: |
public | function | Constructs a router for Drupal with access check and upcasting. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |