You are here

class SamlauthMappingDeleteForm in SAML Authentication 4.x

Same name and namespace in other branches
  1. 8.3 modules/samlauth_user_fields/src/Form/SamlauthMappingDeleteForm.php \Drupal\samlauth_user_fields\Form\SamlauthMappingDeleteForm

Form for deleting a mapping.

Hierarchy

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\Form
View 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

Namesort descending Modifiers Type Description Overrides
ConfirmFormBase::getCancelText public function Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface::getCancelText 2
ConfirmFormBase::getConfirmText public function Returns a caption for the button that confirms the action. Overrides ConfirmFormInterface::getConfirmText 22
ConfirmFormBase::getDescription public function Returns additional text to display as a description. Overrides ConfirmFormInterface::getDescription 14
ConfirmFormBase::getFormName public function Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface::getFormName
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
SamlauthMappingDeleteForm::$attributeName protected property The name of the attribute we're deleting (needed for the confirm message).
SamlauthMappingDeleteForm::$entityFieldManager protected property The entity field manager service.
SamlauthMappingDeleteForm::$fieldName protected property The name of the field we're deleting (needed for the confirm message).
SamlauthMappingDeleteForm::buildForm public function Form for deleting a mapping. Overrides ConfirmFormBase::buildForm
SamlauthMappingDeleteForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
SamlauthMappingDeleteForm::getCancelUrl public function Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface::getCancelUrl
SamlauthMappingDeleteForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
SamlauthMappingDeleteForm::getQuestion public function Returns the question to ask the user. Overrides ConfirmFormInterface::getQuestion
SamlauthMappingDeleteForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
SamlauthMappingDeleteForm::__construct public function SamlauthMappingDeleteForm constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.