NegotiationBrowserDeleteForm.php 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\language\Form\NegotiationConfigureBrowserDeleteForm.
 */

namespace Drupal\language\Form;

use Drupal\Core\Form\ConfirmFormBase;
11
use Drupal\Core\Form\FormStateInterface;
12
use Drupal\Core\Url;
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
use Symfony\Component\HttpFoundation\Request;

/**
 * Defines a confirmation form for deleting a browser language negotiation mapping.
 */
class NegotiationBrowserDeleteForm extends ConfirmFormBase {

  /**
   * The browser language code to be deleted.
   *
   * @var string
   */
  protected $browserLangcode;

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this->t('Are you sure you want to delete %browser_langcode?', array('%browser_langcode' => $this->browserLangcode));
  }

  /**
   * {@inheritdoc}
   */
37 38
  public function getCancelUrl() {
    return new Url('language.negotiation_browser');
39 40 41 42 43
  }

  /**
   * {@inheritdoc}
   */
44
  public function getFormId() {
45 46 47 48 49 50
    return 'language_negotiation_configure_browser_delete_form';
  }

  /**
   * {@inheritdoc}
   */
51
  public function buildForm(array $form, FormStateInterface $form_state, $browser_langcode = NULL) {
52 53
    $this->browserLangcode = $browser_langcode;

54 55 56
    $form = parent::buildForm($form, $form_state);

    return $form;
57 58 59 60 61
  }

  /**
   * {@inheritdoc}
   */
62
  public function submitForm(array &$form, FormStateInterface $form_state) {
alexpott's avatar
alexpott committed
63 64 65
    $this->config('language.mappings')
      ->clear($this->browserLangcode)
      ->save();
66

alexpott's avatar
alexpott committed
67 68 69
    $args = array(
      '%browser' => $this->browserLangcode,
    );
70

alexpott's avatar
alexpott committed
71
    $this->logger('language')->notice('The browser language detection mapping for the %browser browser language code has been deleted.', $args);
72

alexpott's avatar
alexpott committed
73
    drupal_set_message($this->t('The mapping for the %browser browser language code has been deleted.', $args));
74

75
    $form_state->setRedirect('language.negotiation_browser');
76 77 78
  }

}