class SamlauthMappingDeleteForm in SAML Authentication 4.x
Same name and namespace in other branches
- 8.3 modules/samlauth_user_fields/src/Form/SamlauthMappingDeleteForm.php \Drupal\samlauth_user_fields\Form\SamlauthMappingDeleteForm
Form for deleting a mapping.
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_user_fields\Form\SamlauthMappingDeleteForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of SamlauthMappingDeleteForm
1 string reference to 'SamlauthMappingDeleteForm'
- samlauth_user_fields.routing.yml in modules/
samlauth_user_fields/ samlauth_user_fields.routing.yml - modules/samlauth_user_fields/samlauth_user_fields.routing.yml
File
- modules/
samlauth_user_fields/ src/ Form/ SamlauthMappingDeleteForm.php, line 15
Namespace
Drupal\samlauth_user_fields\FormView source
class SamlauthMappingDeleteForm extends ConfirmFormBase {
/**
* The entity field manager service.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* The name of the attribute we're deleting (needed for the confirm message).
*
* @var string
*/
protected $attributeName;
/**
* The name of the field we're deleting (needed for the confirm message).
*
* @var string
*/
protected $fieldName;
/**
* SamlauthMappingDeleteForm constructor.
*
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager service.
*/
public function __construct(EntityFieldManagerInterface $entity_field_manager) {
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_field.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'samlauth_user_fields_delete_form';
}
/**
* Form for deleting a mapping.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param int $mapping_id
* (optional) The numeric ID of the mapping.
*
* @return array
* The form structure.
*/
public function buildForm(array $form, FormStateInterface $form_state, $mapping_id = NULL) {
if ($mapping_id !== NULL) {
$mappings = $this
->configFactory()
->get(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)
->get('field_mappings');
// Set these values for the confirm message to pick up on them.
$this->attributeName = $mappings[$mapping_id]['attribute_name'];
$this->fieldName = $mappings[$mapping_id]['field_name'];
// Set the mapping id so the submit handler can delete it.
$form_state
->set('mapping_id', $mapping_id);
return parent::buildForm($form, $form_state);
}
return [];
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
$fields = $this->entityFieldManager
->getFieldDefinitions('user', 'user');
$field_name = $fields[$this->fieldName]
->getLabel();
return $this
->t('Are you sure you want to delete the mapping for %attribute > %field?', [
'%attribute' => $this->attributeName,
'%field' => $field_name,
]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('samlauth_user_fields.list');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->configFactory()
->getEditable(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME);
$mappings = $config
->get('field_mappings');
unset($mappings[$form_state
->get('mapping_id')]);
$config
->set('field_mappings', $mappings)
->save();
$form_state
->setRedirect('samlauth_user_fields.list');
}
}
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. | |
SamlauthMappingDeleteForm:: |
protected | property | The name of the attribute we're deleting (needed for the confirm message). | |
SamlauthMappingDeleteForm:: |
protected | property | The entity field manager service. | |
SamlauthMappingDeleteForm:: |
protected | property | The name of the field we're deleting (needed for the confirm message). | |
SamlauthMappingDeleteForm:: |
public | function |
Form for deleting a mapping. Overrides ConfirmFormBase:: |
|
SamlauthMappingDeleteForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
SamlauthMappingDeleteForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
SamlauthMappingDeleteForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SamlauthMappingDeleteForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
SamlauthMappingDeleteForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
SamlauthMappingDeleteForm:: |
public | function | SamlauthMappingDeleteForm constructor. | |
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. |