Commit eddf21e5 authored by alexpott's avatar alexpott

Issue #1946426 by ramlev, pfrenssen, foopang, webflo, David Hernández,...

Issue #1946426 by ramlev, pfrenssen, foopang, webflo, David Hernández, vijaycs85, disasm, tim.plunkett: Convert all of confirm_form() in language.admin.inc to the new form interface.
parent 02a7ac8f
......@@ -213,47 +213,6 @@ function language_admin_edit_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/regional/language';
}
/**
* User interface for the language deletion confirmation screen.
*/
function language_admin_delete_form($form, &$form_state, $language) {
$langcode = $language->id;
if (language_default()->id == $langcode) {
drupal_set_message(t('The default language cannot be deleted.'));
return new RedirectResponse(url('admin/config/regional/language', array('absolute' => TRUE)));
}
// For other languages, warn the user that data loss is ahead.
$languages = language_list();
if (!isset($languages[$langcode])) {
throw new NotFoundHttpException();
}
else {
$form['langcode'] = array('#type' => 'value', '#value' => $langcode);
return confirm_form($form, t('Are you sure you want to delete the language %language?', array('%language' => $languages[$langcode]->name)), 'admin/config/regional/language', t('Deleting a language will remove all interface translations associated with it, and posts in this language will be set to be language neutral. This action cannot be undone.'), t('Delete'), t('Cancel'));
}
}
/**
* Process language deletion submissions.
*/
function language_admin_delete_form_submit($form, &$form_state) {
$langcode = $form_state['values']['langcode'];
$languages = language_list();
$language = $languages[$langcode];
$success = language_delete($langcode);
if ($success) {
$t_args = array('%language' => $language->name, '%langcode' => $language->id);
drupal_set_message(t('The %language (%langcode) language has been removed.', $t_args));
}
$form_state['redirect'] = 'admin/config/regional/language';
}
/**
* Prepare a language code list for unused predefined languages.
*/
......@@ -711,31 +670,6 @@ function language_negotiation_configure_browser_form_submit($form, &$form_state)
$form_state['redirect'] = 'admin/config/regional/language/detection';
}
/**
* Form for deleting a browser language negotiation mapping.
*/
function language_negotiation_configure_browser_delete_form($form, &$form_state, $browser_langcode) {
$form_state['browser_langcode'] = $browser_langcode;
$question = t('Are you sure you want to delete %browser_langcode?', array(
'%browser_langcode' => $browser_langcode,
));
$path = 'admin/config/regional/language/detection/browser';
return confirm_form($form, $question, $path, '');
}
/**
* Form submit handler to delete a browser language negotiation mapping.
*/
function language_negotiation_configure_browser_delete_form_submit($form, &$form_state) {
$browser_langcode = $form_state['browser_langcode'];
$mappings = language_get_browser_drupal_langcode_mappings();
if (array_key_exists($browser_langcode, $mappings)) {
unset($mappings[$browser_langcode]);
language_set_browser_drupal_langcode_mappings($mappings);
}
$form_state['redirect'] = 'admin/config/regional/language/detection/browser';
}
/**
* Returns the content language settings form.
*/
......
......@@ -94,12 +94,7 @@ function language_menu() {
'file' => 'language.admin.inc',
);
$items['admin/config/regional/language/delete/%language'] = array(
'title' => 'Confirm delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('language_admin_delete_form', 5),
'access callback' => 'language_access_language_edit_or_delete',
'access arguments' => array(5),
'file' => 'language.admin.inc',
'route_name' => 'language_delete',
);
// Language negotiation.
......@@ -130,13 +125,6 @@ function language_menu() {
'file' => 'language.admin.inc',
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
$items['admin/config/regional/language/detection/browser/delete/%'] = array(
'title' => 'Delete language mapping',
'page arguments' => array('language_negotiation_configure_browser_delete_form', 7),
'type' => MENU_CALLBACK,
'access arguments' => array('administer languages'),
'file' => 'language.admin.inc',
);
$items['admin/config/regional/language/detection/selected'] = array(
'title' => 'Selected language detection configuration',
'route_name' => 'language_negotiation_selected',
......
......@@ -25,3 +25,17 @@ language_admin_overview:
_entity_list: 'language_entity'
requirements:
_permission: 'administer languages'
language_delete:
pattern: '/admin/config/regional/language/delete/{language_entity}'
defaults:
_entity_form: 'language_entity.delete'
requirements:
_entity_access: 'language_entity.delete'
language_negotiation_browser_delete:
pattern: 'admin/config/regional/language/detection/browser/delete/{browser_langcode}'
defaults:
_form: '\Drupal\language\Form\NegotiationBrowserDeleteForm'
requirements:
_permission: 'administer languages'
......@@ -24,7 +24,10 @@
* controllers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController",
* "list" = "Drupal\language\LanguageListController",
* "access" = "Drupal\language\LanguageAccessController"
* "access" = "Drupal\language\LanguageAccessController",
* "form" = {
* "delete" = "Drupal\language\Form\LanguageDeleteForm"
* }
* },
* config_prefix = "language.entity",
* entity_keys = {
......
<?php
/**
* @file
* Contains \Drupal\language\Form\LanguageDeleteForm.
*/
namespace Drupal\language\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Routing\PathBasedGeneratorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Defines a confirmation form for deleting a language entity.
*/
class LanguageDeleteForm extends EntityConfirmFormBase {
/**
* The urlGenerator service.
*
* @var \Drupal\Core\Routing\PathBasedGeneratorInterface
*/
protected $urlGenerator;
/**
* Constructs a new LanguageDeleteForm object.
*
* @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator
* The url generator service.
*/
public function __construct(PathBasedGeneratorInterface $url_generator) {
$this->urlGenerator = $url_generator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('url_generator')
);
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the language %language?', array('%language' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/config/regional/language';
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Deleting a language will remove all interface translations associated with it, and content in this language will be set to be language neutral. This action cannot be undone.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'language_delete_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$langcode = $this->entity->id();
// Warn and redirect user when attempting to delete the default language.
if (language_default()->id == $langcode) {
drupal_set_message($this->t('The default language cannot be deleted.'));
$url = $this->urlGenerator->generateFromPath('admin/config/regional/language', array('absolute' => TRUE));
return new RedirectResponse($url);
}
// Throw a 404 when attempting to delete a non-existing language.
$languages = language_list();
if (!isset($languages[$langcode])) {
throw new NotFoundHttpException();
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
// @todo This should be replaced with $this->entity->delete() when the
// additional logic in language_delete() is ported.
$success = language_delete($this->entity->id());
if ($success) {
drupal_set_message($this->t('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id())));
}
$form_state['redirect'] = 'admin/config/regional/language';
}
}
<?php
/**
* @file
* Contains \Drupal\language\Form\NegotiationConfigureBrowserDeleteForm.
*/
namespace Drupal\language\Form;
use Drupal\Core\Form\ConfirmFormBase;
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}
*/
public function getCancelPath() {
return 'admin/config/regional/language/detection/browser';
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'language_negotiation_configure_browser_delete_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, $browser_langcode = NULL) {
$this->browserLangcode = $browser_langcode;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$mappings = language_get_browser_drupal_langcode_mappings();
if (array_key_exists($this->browserLangcode, $mappings)) {
unset($mappings[$this->browserLangcode]);
language_set_browser_drupal_langcode_mappings($mappings);
}
$form_state['redirect'] = 'admin/config/regional/language/detection/browser';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment