class AuthmapDeleteForm in External Authentication 2.0.x
Confirm the user wants to delete an authmap entry.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\externalauth\Form\AuthmapDeleteForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of AuthmapDeleteForm
1 string reference to 'AuthmapDeleteForm'
File
- src/
Form/ AuthmapDeleteForm.php, line 15
Namespace
Drupal\externalauth\FormView source
class AuthmapDeleteForm 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 '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']);
}
// We don't display the provider name; in most use cases it's implicit.
return $this
->t('Are you sure you want to delete the link between authentication name %id and Drupal user %user?', [
'%id' => $this->authmapEntry['authname'],
'%user' => isset($user) ? $user
->getAccountName() : "<unknown> ({$this->authmapEntry['uid']})",
]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
// We want to return a URL object pointing to admin/people/authmap/PROVIDER.
// Url('view.authmap.page', ['provider' => PROVIDER]) instead returns
// admin/people/authmap?provider=PROVIDER, which is not recognized as
// contextual filter value.
return Url::fromUri('internal:/admin/people/authmap/' . $this->authmapEntry['provider']);
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$provider = $this
->getRouteMatch()
->getParameter('provider');
$uid = $this
->getRouteMatch()
->getParameter('uid');
if (!$provider || !$uid || filter_var($uid, FILTER_VALIDATE_INT) === FALSE) {
throw new \LogicException('It should be impossible to submit this form without valid provider/uid parameters.');
}
$this->connection
->delete('authmap')
->condition('uid', (int) $uid)
->condition('provider', $provider)
->execute();
$this
->messenger()
->addStatus($this
->t('The link has been deleted.'));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthmapDeleteForm:: |
protected | property | Temporary storage for the current authmap entry. | |
AuthmapDeleteForm:: |
protected | property | The database connection. | |
AuthmapDeleteForm:: |
protected | property | The EntityTypeManager service. | |
AuthmapDeleteForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
AuthmapDeleteForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
AuthmapDeleteForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
AuthmapDeleteForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AuthmapDeleteForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
AuthmapDeleteForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
AuthmapDeleteForm:: |
public | function | Constructs a router for Drupal with access check and upcasting. | |
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. | |
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. |