function entity_translation_i18n_menu_entity_translation_delete in Entity Translation 7
Implements hook_entity_translation_delete().
File
- entity_translation_i18n_menu/
entity_translation_i18n_menu.module, line 371 - The menu specific translation functions and hook implementations.
Code
function entity_translation_i18n_menu_entity_translation_delete($entity_type, $entity, $langcode) {
// Make sure that we are working with an entity of type node.
if ($entity_type != 'node') {
return;
}
list($entity_id, , ) = entity_extract_ids($entity_type, $entity);
// Clean-up all menu module links that point to this node.
$result = db_select('menu_links', 'ml')
->fields('ml', array(
'mlid',
'language',
))
->condition('link_path', 'node/' . $entity_id)
->condition('module', 'menu')
->execute()
->fetchAllAssoc('mlid');
foreach ($result as $link) {
// Delete all menu links matching the deleted language.
if ($link->language == $langcode) {
menu_link_delete($link->mlid);
}
// Delete string translations for all language-neutral menu items.
if ($link->language == LANGUAGE_NONE) {
$name = array(
'menu',
'item',
$link->mlid,
);
foreach (array(
'title',
'description',
) as $key) {
$name[] = $key;
$source = i18n_string_get_source($name);
if (!empty($source->lid)) {
db_delete('locales_target')
->condition('lid', $source->lid)
->condition('language', $langcode)
->execute();
}
}
}
}
}