By dave reid on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
7.x-3.x
Introduced in version:
7.x-3.0-rc5
Issue links:
Description:
If your module has a fieldable entity type, it was typically up to you to implement hook_admin_menu_map(). The Fieldable Panels Panes module was a typical example:
/**
* Implements hook_admin_menu_map().
*/
function fieldable_panels_panes_admin_menu_map() {
$map = array();
$bundle_keys = array();
$info = entity_get_info('fieldable_panels_pane');
foreach ($info['bundles'] as $bundle_name => $bundle_info) {
$bundle_keys[] = strtr($bundle_name, '_', '-');
// Add mapping for the individual fields if the Field UI module is enabled.
if (module_exists('field_ui')) {
if (isset($bundle_info['admin'])) {
$admin_path = $bundle_info['admin']['path'];
$fields = array();
foreach (field_info_instances('fieldable_panels_pane', $bundle_name) as $field) {
$fields[] = $field['field_name'];
}
$map["$admin_path/fields/%field_ui_menu"]['parent'] = "$admin_path/fields";
$map["$admin_path/fields/%field_ui_menu"]['arguments'][] = array(
'%fieldable_panels_panes_type' => array($bundle_name),
'%field_ui_menu' => $fields,
);
}
}
}
// Provide mapping for the individual bundles.
$map['admin/structure/fieldable-panels-panes/manage/%fieldable_panels_panes_type'] = array(
'parent' => 'admin/structure/fieldable-panels-panes',
'arguments' => array(
array('%ctools_export_ui' => $bundle_keys),
),
);
return $map;
}
But now Administration Menu provides the mappings for you. To provide support for both old versions of Administration Menu, use both hook_admin_menu_map() and hook_admin_menu_map_alter(). Optionally, you could simplify and just leave out the hook_admin_menu_map_alter() part and rely on your users to use the latest version of Administration Menu.
/**
* Implements hook_admin_menu_map().
*/
function fieldable_panels_panes_admin_menu_map() {
$map = array();
$bundle_keys = array();
$info = entity_get_info('fieldable_panels_pane');
foreach ($info['bundles'] as $bundle_name => $bundle_info) {
$bundle_keys[] = $bundle_name;
}
// Provide mapping for all bundles.
$map['admin/structure/fieldable-panels-panes/%fieldable_panels_pane_type'] = array(
'parent' => 'admin/structure/fieldable-panels-panes',
'arguments' => array(
array('%ctools_export_ui' => $bundle_keys),
),
);
return $map;
}
/**
* Implements hook_admin_menu_map_alter().
*
* Add mapping for the individual fields if the Field UI module is enabled,
* and the mappings are not already added by field_ui_admin_menu_map().
*/
function fieldable_panels_panes_admin_menu_map_alter(array &$map) {
if (!module_exists('field_ui')) {
return;
}
$bundles = array();
$info = entity_get_info('fieldable_panels_pane');
foreach ($info['bundles'] as $bundle_name => $bundle_info) {
if (isset($bundle_info['admin'])) {
$admin_path = $bundle_info['admin']['path'];
// Fields mapping may already be supported by field_ui_admin_menu_map()
// so only add it if it doesn't exist.
if (isset($map["$admin_path/fields/%field_ui_menu"])) {
continue;
}
$fields = array();
foreach (field_info_instances('fieldable_panels_pane', $bundle_name) as $field) {
$fields[] = $field['field_name'];
}
if (!empty($fields)) {
$map["$admin_path/fields/%field_ui_menu"]['parent'] = "$admin_path/fields";
$map["$admin_path/fields/%field_ui_menu"]['arguments'][] = array(
'%ctools_export_ui' => array($bundle_name),
'%field_ui_menu' => $fields,
);
}
}
}
}
Impacts:
Site builders, administrators, editors
Module developers
Comments
Worked for my site
Once I figured out to add the patch to "fieldable_panels_panes.module file," it became an easy fix to make.
Thanks Dave Reid!
g