function field_tools_menu in Field tools 7
Implements hook_menu().
File
- ./
field_tools.module, line 54 - field_tools.module Contains useful tools for working with fields.
Code
function field_tools_menu() {
// Create tabs for all possible bundles.
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'];
// Determine whether this path caters for several bundles (usually all)
// of one entity type, or just one.
if (isset($bundle_info['admin']['bundle argument'])) {
// 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.
$bundle_arg = $bundle_info['admin']['bundle argument'];
$bundle_pos = (string) $bundle_arg;
}
else {
// Otherwise, this path is for a single bundle. Things are much simpler!
$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',
),
);
// Menu item for cloning a bundle's fields en masse.
// In some cases, $path is the same for every bundle, eg nodes, and
// hence doing this here is redundant.
$items["{$path}/tools"] = array(
'title' => 'Tools',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_bundle_fields_clone_from_form',
$entity_type,
$bundle_arg,
),
'type' => MENU_LOCAL_TASK,
'file' => 'field_tools.admin.inc',
'weight' => 10,
) + $access;
// Tweak comment tools to differentiate them from node tools as they
// sit in the same sets of tabs.
if ($entity_type == 'comment') {
$items["{$path}/tools"]['title'] = 'Comment tools';
$items["{$path}/tools"]['weight'] = 11;
}
$items["{$path}/tools/clone-from"] = array(
'title' => 'Clone fields from this bundle',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_bundle_fields_clone_from_form',
$entity_type,
$bundle_arg,
),
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'field_tools.admin.inc',
'weight' => 10,
) + $access;
$items["{$path}/tools/clone-to"] = array(
'title' => 'Clone fields to this bundle',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_bundle_fields_clone_to_form',
$entity_type,
$bundle_arg,
),
'type' => MENU_LOCAL_TASK,
'file' => 'field_tools.admin.inc',
'weight' => 20,
) + $access;
// Menu item for cloning a single field.
$items["{$path}/fields/%field_ui_menu/clone"] = array(
'load arguments' => array(
$entity_type,
$bundle_arg,
$bundle_pos,
'%map',
),
'title' => 'Clone',
'page callback' => 'drupal_get_form',
// The numeric $field_position gets us the field instance from the
// %field_ui_menu menu loader.
'page arguments' => array(
'field_tools_field_clone_form',
$field_position,
),
'type' => MENU_LOCAL_TASK,
'file' => 'field_tools.admin.inc',
'weight' => 10,
) + $access;
// Menu items for import and export of fields.
$items["{$path}/tools/export"] = array(
'title' => 'Export fields',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_bundle_export_form',
$entity_type,
$bundle_arg,
),
'type' => MENU_LOCAL_TASK,
'file' => 'field_tools.admin.inc',
'weight' => 30,
) + $access;
$items["{$path}/tools/import"] = array(
'title' => 'Import fields',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_bundle_import_form',
$entity_type,
$bundle_arg,
),
'type' => MENU_LOCAL_TASK,
'file' => 'field_tools.admin.inc',
'weight' => 40,
) + $access;
// Menu item for exporting a single field.
$items["{$path}/fields/%field_ui_menu/export"] = array(
'load arguments' => array(
$entity_type,
$bundle_arg,
$bundle_pos,
'%map',
),
'title' => 'Export',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_field_export_form',
$field_position,
),
'type' => MENU_LOCAL_TASK,
'file' => 'field_tools.admin.inc',
'weight' => 1,
) + $access;
if (module_exists('field_group')) {
$items["{$path}/groups/%field_group_menu/export"] = array(
'load arguments' => array(
$entity_type,
$bundle_arg,
$bundle_pos,
'%map',
),
'title' => 'Export',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_group_export_form',
$field_position,
),
'type' => MENU_CALLBACK,
'file' => 'field_tools.admin.inc',
'weight' => 1,
) + $access;
}
}
}
}
}
// Field tools overview.
$items["admin/reports/fields/tools"] = array(
'title' => 'Tools',
'page callback' => 'field_tools_field_overview',
'type' => MENU_LOCAL_TASK,
'weight' => -1,
'file' => 'field_tools.admin.inc',
) + $access;
$items["admin/reports/fields/references"] = array(
'title' => 'References',
'page callback' => 'field_tools_field_references_overview',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
'file' => 'field_tools.admin.inc',
) + $access;
if (module_exists('graphapi')) {
$items["admin/reports/fields/graph"] = array(
'title' => 'Graph',
'page callback' => 'field_tools_field_references_graph',
'type' => MENU_LOCAL_TASK,
'weight' => 6,
'file' => 'field_tools.admin.inc',
) + $access;
}
$items["admin/reports/fields/field/%"] = array(
'title' => 'Field instances',
'page callback' => 'field_tools_field_page',
'page arguments' => array(
4,
),
'file' => 'field_tools.admin.inc',
) + $access;
$items["admin/reports/fields/field/%field_tools_field_menu/edit"] = array(
'title' => 'Edit instance',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_field_edit_form',
4,
),
'file' => 'field_tools.admin.inc',
) + $access;
$items["admin/reports/fields/field/%field_tools_field_menu/delete"] = array(
'title' => 'Delete instances',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'field_tools_field_delete_form',
4,
),
'file' => 'field_tools.admin.inc',
) + $access;
return $items;
}