You are here

function i18n_field_menu in Internationalization 7

Implements hook_menu().

File

i18n_field/i18n_field.module, line 15
Internationalization (i18n) module - Field handling

Code

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

  // Ensure the following is not executed until field_bundles is working and
  // tables are updated. Needed to avoid errors on initial installation.
  if (!module_exists('field_ui') || defined('MAINTENANCE_MODE')) {
    return $items;
  }

  // Create tabs for all possible bundles. From field_ui_menu().
  foreach (entity_get_info() as $entity_type => $entity_info) {
    if ($entity_info['fieldable']) {
      foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
        if (isset($bundle_info['admin'])) {

          // Extract path information from the bundle.
          $path = $bundle_info['admin']['path'];

          // Different bundles can appear on the same path (e.g. %node_type and
          // %comment_node_type). To allow field_ui_menu_load() to extract the
          // actual bundle object from the translated menu router path
          // arguments, we need to identify the argument position of the bundle
          // name string ('bundle argument') and pass that position to the menu
          // loader. The position needs to be casted into a string; otherwise it
          // would be replaced with the bundle name string.
          if (isset($bundle_info['admin']['bundle argument'])) {
            $bundle_arg = $bundle_info['admin']['bundle argument'];
            $bundle_pos = (string) $bundle_arg;
          }
          else {
            $bundle_arg = $bundle_name;
            $bundle_pos = '0';
          }

          // This is the position of the %field_ui_menu placeholder in the
          // items below.
          $field_position = count(explode('/', $path)) + 1;

          // Extract access information, providing defaults.
          $access = array_intersect_key($bundle_info['admin'], drupal_map_assoc(array(
            'access callback',
            'access arguments',
          )));
          $access += array(
            'access callback' => 'user_access',
            'access arguments' => array(
              'administer site configuration',
            ),
          );
          $items["{$path}/fields/%field_ui_menu/translate"] = array(
            'load arguments' => array(
              $entity_type,
              $bundle_arg,
              $bundle_pos,
              '%map',
            ),
            'title' => 'Translate',
            'page callback' => 'i18n_field_page_translate',
            'page arguments' => array(
              $field_position,
            ),
            'file' => 'i18n_field.pages.inc',
            'type' => MENU_LOCAL_TASK,
          ) + $access;
          $items["{$path}/fields/%field_ui_menu/translate/%i18n_language"] = array(
            'load arguments' => array(
              $entity_type,
              $bundle_arg,
              $bundle_pos,
              '%map',
            ),
            'title' => 'Instance',
            'page callback' => 'i18n_field_page_translate',
            'page arguments' => array(
              $field_position,
              $field_position + 2,
            ),
            'file' => 'i18n_field.pages.inc',
            'type' => MENU_CALLBACK,
          ) + $access;
        }
      }
    }
  }
  return $items;
}