Issue #2223249 by alexpott: Remove hook_language_insert/update/delete/presave in favour of entity hooks.

8.0.x
catch 2014-03-25 20:51:00 +01:00
parent fa84283f78
commit e1dd5a1efd
5 changed files with 32 additions and 82 deletions

View File

@ -7,6 +7,7 @@
use Drupal\block\BlockInterface; use Drupal\block\BlockInterface;
use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\language\Entity\Language;
use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/** /**
@ -444,16 +445,16 @@ function block_menu_delete($menu) {
} }
/** /**
* Implements hook_language_delete(). * Implements hook_ENTITY_TYPE_delete() for 'language_entity'.
* *
* Delete the potential block visibility settings of the deleted language. * Delete the potential block visibility settings of the deleted language.
*/ */
function block_language_delete($language) { function block_language_entity_delete(Language $language) {
// Remove the block visibility settings for the deleted language. // Remove the block visibility settings for the deleted language.
foreach (entity_load_multiple('block') as $block) { foreach (entity_load_multiple('block') as $block) {
$visibility = $block->get('visibility'); $visibility = $block->get('visibility');
if (isset($visibility['language']['langcodes'][$language->id])) { if (isset($visibility['language']['langcodes'][$language->id()])) {
unset($visibility['language']['langcodes'][$language->id]); unset($visibility['language']['langcodes'][$language->id()]);
$block->set('visibility', $visibility); $block->set('visibility', $visibility);
$block->save(); $block->save();
} }

View File

@ -77,53 +77,6 @@ function hook_language_negotiation_info_alter(array &$negotiation_info) {
} }
} }
/**
* React to a language about to be added or updated in the system.
*
* @param $language
* A language object.
*/
function hook_language_presave($language) {
if ($language->default) {
// React to a new default language.
example_new_default_language($language);
}
}
/**
* React to a language that was just added to the system.
*
* @param $language
* A language object.
*/
function hook_language_insert($language) {
example_refresh_permissions();
}
/**
* React to a language that was just updated in the system.
*
* @param $language
* A language object.
*/
function hook_language_update($language) {
example_refresh_permissions();
}
/**
* 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_language_delete($language) {
// On nodes with this language, unset the language
db_update('node')
->fields(array('language' => ''))
->condition('language', $language->id)
->execute();
}
/** /**
* Allow modules to alter the language fallback candidates. * Allow modules to alter the language fallback candidates.
* *

View File

@ -9,6 +9,7 @@ use Drupal\Component\PhpStorage\PhpStorageFactory;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\language\ConfigurableLanguageManager; use Drupal\language\ConfigurableLanguageManager;
use Drupal\language\ConfigurableLanguageManagerInterface; use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\language\Entity\Language as LanguageEntity;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback;
@ -448,9 +449,6 @@ function language_save($language) {
} }
$language->is_new = $language_entity->isNew(); $language->is_new = $language_entity->isNew();
// Let other modules modify $language before saved.
\Drupal::moduleHandler()->invokeAll('language_presave', array($language));
// Assign language properties to language entity. // Assign language properties to language entity.
$language_entity->label = isset($language->name) ? $language->name : ''; $language_entity->label = isset($language->name) ? $language->name : '';
$language_entity->direction = isset($language->direction) ? $language->direction : '0'; $language_entity->direction = isset($language->direction) ? $language->direction : '0';
@ -462,11 +460,9 @@ function language_save($language) {
$language_entity->save(); $language_entity->save();
$t_args = array('%language' => $language->name, '%langcode' => $language->id); $t_args = array('%language' => $language->name, '%langcode' => $language->id);
if ($language->is_new) { if ($language->is_new) {
\Drupal::moduleHandler()->invokeAll('language_insert', array($language));
watchdog('language', 'The %language (%langcode) language has been created.', $t_args); watchdog('language', 'The %language (%langcode) language has been created.', $t_args);
} }
else { else {
\Drupal::moduleHandler()->invokeAll('language_update', array($language));
watchdog('language', 'The %language (%langcode) language has been updated.', $t_args); watchdog('language', 'The %language (%langcode) language has been updated.', $t_args);
} }
@ -510,8 +506,6 @@ function language_delete($langcode) {
if (isset($languages[$langcode]) && !$languages[$langcode]->locked) { if (isset($languages[$langcode]) && !$languages[$langcode]->locked) {
$language = $languages[$langcode]; $language = $languages[$langcode];
\Drupal::moduleHandler()->invokeAll('language_delete', array($language));
// Remove the language. // Remove the language.
entity_delete_multiple('language_entity', array($language->id)); entity_delete_multiple('language_entity', array($language->id));
@ -637,31 +631,31 @@ function language_modules_uninstalled($modules) {
} }
/** /**
* Implements hook_language_insert(). * Implements hook_ENTITY_TYPE_insert() for 'language_entity'.
*/ */
function language_language_insert($language) { function language_language_entity_insert(LanguageEntity $language) {
if (!empty($language->locked)) { if (!empty($language->locked)) {
return; return;
} }
// Add language to the list of language domains. // Add language to the list of language domains.
$domains = language_negotiation_url_domains(); $domains = language_negotiation_url_domains();
$domains[$language->id] = ''; $domains[$language->id()] = '';
language_negotiation_url_domains_save($domains); language_negotiation_url_domains_save($domains);
} }
/** /**
* Implements hook_language_delete(). * Implements hook_ENTITY_TYPE_delete() for 'language_entity'.
*/ */
function language_language_delete($language) { function language_language_entity_delete(LanguageEntity $language) {
// Remove language from language prefix list. // Remove language from language prefix list.
$prefixes = language_negotiation_url_prefixes(); $prefixes = language_negotiation_url_prefixes();
unset($prefixes[$language->id]); unset($prefixes[$language->id()]);
language_negotiation_url_prefixes_save($prefixes); language_negotiation_url_prefixes_save($prefixes);
// Remove language from language domain list. // Remove language from language domain list.
$domains = language_negotiation_url_domains(); $domains = language_negotiation_url_domains();
unset($domains[$language->id]); unset($domains[$language->id()]);
language_negotiation_url_domains_save($domains); language_negotiation_url_domains_save($domains);
} }

View File

@ -13,6 +13,7 @@
use Drupal\Component\Utility\Json; use Drupal\Component\Utility\Json;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\language\Entity\Language as LanguageEntity;
use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Crypt;
/** /**
@ -240,48 +241,48 @@ function locale_stream_wrappers() {
} }
/** /**
* Implements hook_language_insert(). * Implements hook_ENTITY_TYPE_insert() for 'language_entity'.
*/ */
function locale_language_insert($language) { function locale_language_entity_insert(LanguageEntity $language) {
// @todo move these two cache clears out. See http://drupal.org/node/1293252 // @todo move these two cache clears out. See http://drupal.org/node/1293252
// Changing the language settings impacts the interface. // Changing the language settings impacts the interface.
\Drupal::cache('page')->deleteAll(); \Drupal::cache('page')->deleteAll();
// Force JavaScript translation file re-creation for the new language. // Force JavaScript translation file re-creation for the new language.
_locale_invalidate_js($language->id); _locale_invalidate_js($language->id());
} }
/** /**
* Implements hook_language_update(). * Implements hook_ENTITY_TYPE_update() for 'language_entity'.
*/ */
function locale_language_update($language) { function locale_language_entity_update(LanguageEntity $language) {
// @todo move these two cache clears out. See http://drupal.org/node/1293252 // @todo move these two cache clears out. See http://drupal.org/node/1293252
// Changing the language settings impacts the interface. // Changing the language settings impacts the interface.
\Drupal::cache('page')->deleteAll(); \Drupal::cache('page')->deleteAll();
// Force JavaScript translation file re-creation for the modified language. // Force JavaScript translation file re-creation for the modified language.
_locale_invalidate_js($language->id); _locale_invalidate_js($language->id());
} }
/** /**
* Implements hook_language_delete(). * Implements hook_ENTITY_TYPE_delete() for 'language_entity'.
*/ */
function locale_language_delete($language) { function locale_language_entity_delete(LanguageEntity $language) {
// Remove translations. // Remove translations.
\Drupal::service('locale.storage')->deleteTranslations(array('language' => $language->id)); \Drupal::service('locale.storage')->deleteTranslations(array('language' => $language->id()));
// Remove interface translation files. // Remove interface translation files.
module_load_include('inc', 'locale', 'locale.bulk'); module_load_include('inc', 'locale', 'locale.bulk');
locale_translate_delete_translation_files(array(), array($language->id)); locale_translate_delete_translation_files(array(), array($language->id()));
// Remove translated configuration objects. // Remove translated configuration objects.
\Drupal\locale\Locale::config()->deleteLanguageTranslations($language->id); \Drupal\locale\Locale::config()->deleteLanguageTranslations($language->id());
// Changing the language settings impacts the interface: // Changing the language settings impacts the interface:
_locale_invalidate_js($language->id); _locale_invalidate_js($language->id());
\Drupal::cache('page')->deleteAll(); \Drupal::cache('page')->deleteAll();
// Clear locale translation caches. // Clear locale translation caches.
locale_translation_status_delete_languages(array($language->id)); locale_translation_status_delete_languages(array($language->id()));
\Drupal::cache()->delete('locale:' . $language->id); \Drupal::cache()->delete('locale:' . $language->id());
} }
/** /**

View File

@ -21,6 +21,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Template\Attribute; use Drupal\Core\Template\Attribute;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
use Drupal\language\Entity\Language as LanguageEntity;
use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/** /**
@ -1810,13 +1811,13 @@ function node_file_download_access($field, EntityInterface $entity, File $file)
} }
/** /**
* Implements hook_language_delete(). * Implements hook_ENTITY_TYPE_delete() for 'language_entity'.
*/ */
function node_language_delete($language) { function node_language_entity_delete(LanguageEntity $language) {
// On nodes with this language, unset the language. // On nodes with this language, unset the language.
db_update('node_revision') db_update('node_revision')
->fields(array('langcode' => '')) ->fields(array('langcode' => ''))
->condition('langcode', $language->id) ->condition('langcode', $language->id())
->execute(); ->execute();
} }