You are here

function i18n_page_menu_items in Internationalization 7

Create menu items for translatable objecs

1 call to i18n_page_menu_items()
i18n_menu in ./i18n.module
Implements hook_menu().

File

./i18n.pages.inc, line 13
Generic translation pages

Code

function i18n_page_menu_items() {
  $items = array();

  // Menus are rebuilt right after other modules are disabled, if no reset we get tabs for disabled modules.
  drupal_static_reset('i18n_object_info');
  foreach (i18n_object_info() as $type => $info) {

    // These objects should have a 'translate tab' property
    if (!empty($info['translate tab'])) {
      $path = $info['translate tab'];
      $localize = module_exists('i18n_string') && !empty($info['string translation']);
      $translate = module_exists('i18n_translation') && i18n_translation_set_info($type);
      if ($translate && $localize) {
        $page_callback = 'i18n_page_translate_tab';
      }
      elseif ($translate) {
        $page_callback = 'i18n_page_translate_translation';
      }
      elseif ($localize) {
        $page_callback = 'i18n_page_translate_localize';
      }

      // Find the position for the object placeholder. We assume the first one.
      $placeholder = key($info['placeholders']);
      $parts = explode('/', $path);
      $position = array_search($placeholder, $parts);

      // Now create items with the right callbacks
      if ($translate || $localize) {
        $items[$path] = array(
          'title' => 'Translate',
          'page callback' => $page_callback,
          'page arguments' => array(
            $type,
            $position,
          ),
          'access callback' => 'i18n_object_translate_access',
          'access arguments' => array(
            $type,
            $position,
          ),
          'type' => MENU_LOCAL_TASK,
          'file' => 'i18n.pages.inc',
          'weight' => 10,
        );
      }
      if ($localize) {
        $items[$path . '/%i18n_language'] = array(
          'title' => 'Translate',
          'page callback' => $page_callback,
          'page arguments' => array(
            $type,
            $position,
            count($parts),
          ),
          'access callback' => 'i18n_object_translate_access',
          'access arguments' => array(
            $type,
            $position,
          ),
          'type' => MENU_CALLBACK,
          'file' => 'i18n.pages.inc',
        );
      }
    }
  }
  return $items;
}