Skip to content
Snippets Groups Projects
Commit 1a1da09d authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #1260528 by tarmstrong, svendecabooter, podarok: introduce API to delete languages.

parent a120045c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -60,9 +60,9 @@
*/
/**
* Implements hook_multilingual_settings_changed().
* Implements hook_locale_language_delete().
*/
function field_multilingual_settings_changed() {
function field_locale_language_delete() {
field_info_cache_clear();
}
......
......@@ -461,37 +461,18 @@ function locale_languages_delete_form($form, &$form_state, $langcode) {
* Process language deletion submissions.
*/
function locale_languages_delete_form_submit($form, &$form_state) {
$langcode = $form_state['values']['langcode'];
$languages = language_list();
if (isset($languages[$form_state['values']['langcode']])) {
// Remove translations first.
db_delete('locales_target')
->condition('language', $form_state['values']['langcode'])
->execute();
cache_clear_all('locale:' . $form_state['values']['langcode'], 'cache');
// With no translations, this removes existing JavaScript translations file.
_locale_rebuild_js($form_state['values']['langcode']);
// Remove the language.
db_delete('languages')
->condition('language', $form_state['values']['langcode'])
->execute();
db_update('node')
->fields(array('language' => ''))
->condition('language', $form_state['values']['langcode'])
->execute();
if ($languages[$form_state['values']['langcode']]->enabled) {
variable_set('language_count', variable_get('language_count', 1) - 1);
}
module_invoke_all('multilingual_settings_changed');
$variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);
$language = $languages[$langcode];
$success = locale_language_delete($langcode);
if ($success) {
$variables = array('%locale' => $language->name);
drupal_set_message(t('The language %locale has been removed.', $variables));
watchdog('locale', 'The language %locale has been removed.', $variables);
}
// Changing the language settings impacts the interface:
cache_clear_all('*', 'cache_page', TRUE);
$form_state['redirect'] = 'admin/config/regional/language';
return;
}
/**
......
......@@ -154,19 +154,6 @@ function hook_language_negotiation_info_alter(array &$language_providers) {
}
}
/**
* Allow modules to react to language settings changes.
*
* Every module needing to act when the number of enabled languages changes
* should implement this. This is an "internal" hook and should not be invoked
* elsewhere. The typical implementation would trigger some kind of rebuilding,
* this way system components could properly react to the change of the enabled
* languages number.
*/
function hook_multilingual_settings_changed() {
field_info_cache_clear();
}
/**
* Perform alterations on the language fallback candidates.
*
......@@ -178,6 +165,20 @@ function hook_language_fallback_candidates_alter(array &$fallback_candidates) {
$fallback_candidates = array_reverse($fallback_candidates);
}
/**
* Allow modules to react before the deletion of a language.
*
* @param $language
* The language object of the language that is about to be deleted.
*/
function hook_locale_language_delete($language) {
// On nodes with this language, unset the language
db_update('node')
->fields(array('language' => ''))
->condition('language', $language->language)
->execute();
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -778,6 +778,51 @@ function locale_language_list($field = 'name', $all = FALSE) {
return $list;
}
/**
* Delete a language.
*
* @param $langcode
* Language code of the language to be deleted.
* @return
* TRUE if language is successfully deleted. Otherwise FALSE.
*/
function locale_language_delete($langcode) {
$languages = language_list();
if (isset($languages[$langcode])) {
$language = $languages[$langcode];
module_invoke_all('locale_language_delete', $language);
// Remove translations first.
db_delete('locales_target')
->condition('language', $language->language)
->execute();
// Remove the language.
db_delete('languages')
->condition('language', $language->language)
->execute();
if ($language->enabled) {
variable_set('language_count', variable_get('language_count', 1) - 1);
}
drupal_static_reset('language_list');
_locale_invalidate_js($language->language);
// Changing the language settings impacts the interface:
cache_clear_all('*', 'cache_page', TRUE);
// Clearing all locale cache from database
cache_clear_all('locale:' . $language->language, 'cache');
$variables = array('%locale' => $language->name);
watchdog('locale', 'The language %locale has been removed.', $variables);
return TRUE;
}
return FALSE;
}
/**
* Implements hook_modules_installed().
*/
......
......@@ -3948,3 +3948,14 @@ function node_file_download_access($field, $entity_type, $entity) {
return node_access('view', $entity);
}
}
/**
* Implements hook_locale_language_delete().
*/
function node_locale_language_delete($language) {
// On nodes with this language, unset the language
db_update('node')
->fields(array('language' => ''))
->condition('language', $language->language)
->execute();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment