You are here

function entity_translation_i18n_menu_item in Entity Translation 7

Checks whether a given menu item is translatable through entity translation.

@todo Find more generic way of determining whether ET is enabled for a link; add support for other entities, e.g. taxonomy_term (?).

Parameters

array $item: A menu item.

3 calls to entity_translation_i18n_menu_item()
entity_translation_i18n_menu_menu_link_alter in entity_translation_i18n_menu/entity_translation_i18n_menu.module
Implements hook_menu_link_alter().
entity_translation_i18n_menu_menu_link_update in entity_translation_i18n_menu/entity_translation_i18n_menu.module
Implements hook_menu_link_update().
entity_translation_i18n_menu_node_prepare in entity_translation_i18n_menu/entity_translation_i18n_menu.module
Implements hook_node_prepare().

File

entity_translation_i18n_menu/entity_translation_i18n_menu.module, line 224
The menu specific translation functions and hook implementations.

Code

function entity_translation_i18n_menu_item($item) {
  $cache =& drupal_static(__FUNCTION__, array());
  if (!isset($cache[$item['link_path']])) {

    // First check that the item belongs to a menu which has translation
    // enabled.
    if (!i18n_menu_mode($item['menu_name'], I18N_MODE_MULTIPLE)) {
      $cache[$item['link_path']] = FALSE;
    }

    // Check if the respective node type has entity translation enabled.
    if (preg_match('!^node/(\\d+)(/.+|)$!', $item['link_path'], $matches)) {
      if (!entity_translation_enabled('node')) {
        $cache[$item['link_path']] = FALSE;
      }
      else {
        $type = db_select('node', 'n')
          ->condition('nid', $matches[1])
          ->fields('n', array(
          'type',
        ))
          ->execute()
          ->fetchField();
        $cache[$item['link_path']] = entity_translation_node_supported_type($type);
      }
    }
    else {
      $cache[$item['link_path']] = FALSE;
    }
  }
  return $cache[$item['link_path']];
}