Implements hook_menu_alter().
function translation_entity_menu_alter(array &$items) {
// Some menu loaders in the item paths might have been altered: we need to
// replace any menu loader with a plain % to check if base paths are still
// compatible.
$paths = array();
$regex = '|%[^/]+|';
foreach ($items as $path => $item) {
$path = preg_replace($regex, '%', $path);
$paths[$path] = $path;
}
// Check that the declared menu base paths are actually valid.
foreach (entity_get_info() as $entity_type => $info) {
if (translation_entity_enabled($entity_type)) {
$path = $info['menu_base_path'];
// If the base path is not defined or is not compatible with any defined
// one we cannot provide the translation UI for this entity type.
if (!isset($paths[preg_replace($regex, '%', $path)])) {
drupal_set_message(t('The entities of type %entity_type do not define a valid base path: it will not be possible to translate them.', array(
'%entity_type' => $info['label'],
)), 'warning');
unset($items["{$path}/translations"], $items["{$path}/translations/add/%language"], $items["{$path}/translations/delete/%language"]);
}
else {
$entity_position = count(explode('/', $path)) - 1;
$edit_path = $info['menu_edit_path'];
if (isset($items[$edit_path])) {
// If the edit path is a default local task we need to find the parent
// item.
$edit_path_split = explode('/', $edit_path);
do {
$entity_form_item =& $items[implode('/', $edit_path_split)];
array_pop($edit_path_split);
} while (!empty($entity_form_item['type']) && $entity_form_item['type'] == MENU_DEFAULT_LOCAL_TASK);
// Make the "Translate" tab follow the "Edit" one when possibile.
if (isset($entity_form_item['weight'])) {
$items["{$path}/translations"]['weight'] = $entity_form_item['weight'] + 0.01;
}
}
}
}
}
}