diff options
Diffstat (limited to 'modules/field_ui/field_ui.module')
-rw-r--r-- | modules/field_ui/field_ui.module | 200 |
1 files changed, 74 insertions, 126 deletions
diff --git a/modules/field_ui/field_ui.module b/modules/field_ui/field_ui.module index 3bb5cd886..470abe6d7 100644 --- a/modules/field_ui/field_ui.module +++ b/modules/field_ui/field_ui.module @@ -49,6 +49,24 @@ function field_ui_help($path, $arg) { } /** + * Implements hook_theme(). + */ +function field_ui_theme() { + return array( + 'field_ui_field_overview_form' => array( + 'render element' => 'form', + 'file' => 'field_ui.admin.inc', + 'template' => 'field_ui-field-overview-form', + ), + 'field_ui_display_overview_table' => array( + 'render element' => 'elements', + 'file' => 'field_ui.admin.inc', + 'template' => 'field_ui-display-overview-table', + ), + ); +} + +/** * Implements hook_menu(). */ function field_ui_menu() { @@ -66,10 +84,11 @@ function field_ui_menu() { if (defined('MAINTENANCE_MODE')) { return $items; } + // Create tabs for all possible bundles. - foreach (entity_get_info() as $entity_type => $info) { - if ($info['fieldable']) { - foreach ($info['bundles'] as $bundle_name => $bundle_info) { + 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']; @@ -92,7 +111,12 @@ function field_ui_menu() { // 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"] = array( 'title' => 'Manage fields', @@ -145,24 +169,38 @@ function field_ui_menu() { 'file' => 'field_ui.admin.inc', ) + $access; - // 'Manage display' tab and context secondary tabs. + // 'Manage display' tab. $items["$path/display"] = array( 'title' => 'Manage display', 'page callback' => 'drupal_get_form', - 'page arguments' => array('field_ui_display_overview_form', $entity_type, $bundle_arg), + 'page arguments' => array('field_ui_display_overview_form', $entity_type, $bundle_arg, 'default'), 'type' => MENU_LOCAL_TASK, 'weight' => 2, 'file' => 'field_ui.admin.inc', ) + $access; - $tabs = field_ui_view_modes_tabs($entity_type); - foreach ($tabs as $key => $tab) { - $items["$path/display/$key"] = array( - 'title' => $tab['title'], - 'page arguments' => array('field_ui_display_overview_form', $entity_type, $bundle_arg, $key), - 'type' => $key == 'basic' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, - 'weight' => $key == 'basic' ? 0 : 1, + + // View modes secondary tabs. + // The same base $path for the menu item (with a placeholder) can be + // used for all bundles of a given entity type; but depending on + // administrator settings, each bundle has a different set of view + // modes available for customisation. So we define menu items for all + // view modes, and use an access callback to determine which ones are + // actually visible for a given bundle. + $weight = 0; + $view_modes = array('default' => array('label' => t('Default'))) + $entity_info['view modes']; + foreach ($view_modes as $view_mode => $view_mode_info) { + $items["$path/display/$view_mode"] = array( + 'title' => $view_mode_info['label'], + 'page arguments' => array('field_ui_display_overview_form', $entity_type, $bundle_arg, $view_mode), + // The access callback needs to check both the current 'custom + // display' setting for the view mode, and the overall access + // rules for the bundle admin pages. + 'access callback' => '_field_ui_view_mode_menu_access', + 'access arguments' => array_merge(array($entity_type, $bundle_arg, $view_mode, $access['access callback']), $access['access arguments']), + 'type' => ($view_mode == 'default' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK), + 'weight' => ($view_mode == 'default' ? -10 : $weight++), 'file' => 'field_ui.admin.inc', - ) + $access; + ); } } } @@ -219,100 +257,35 @@ function field_ui_menu_title($instance) { } /** - * Implements hook_theme(). + * Menu access callback for the 'view mode display settings' pages. */ -function field_ui_theme() { - return array( - 'field_ui_field_overview_form' => array( - 'render element' => 'form', - 'file' => 'field_ui.admin.inc', - 'template' => 'field_ui-field-overview-form', - ), - 'field_ui_display_overview_form' => array( - 'render element' => 'form', - 'file' => 'field_ui.admin.inc', - 'template' => 'field_ui-display-overview-form', - ), - ); -} +function _field_ui_view_mode_menu_access($entity_type, $bundle, $view_mode, $access_callback) { + // First, determine visibility according to the 'use custom display' + // setting for the view mode. + $bundle = field_extract_bundle($entity_type, $bundle); + $view_mode_settings = field_view_mode_settings($entity_type, $bundle); + $visibility = ($view_mode == 'default') || !empty($view_mode_settings[$view_mode]['custom_settings']); -/** - * Returns information about tab groups for view modes on an entity type. - * - * On the 'Manage display' page, an administrator can manage the display of - * fields for each view mode for an entity type. The view modes are organized - * into tabs. This function returns the list of entity types to display on - * each tab, as well as the titles of the tabs. - * - * @param $entity_type - * The type of entity to return tab information for. - * @param $tab_selector - * If not NULL, return only information for this particular tab; if NULL, - * return all tab information. - * - * @return - * Array of information about the tabs to display. The keys are internal-use - * tab names and the values are arrays of tab information, with the following - * elements: - * - 'title': Human-readable title of the tab. - * - 'view modes': Array of view modes for this entity type that should - * be displayed on this tab. - * - * @see hook_field_ui_view_modes_tabs() - * - * @todo Remove this completely and use vertical tabs? - */ -function field_ui_view_modes_tabs($entity_type, $tab_selector = NULL) { - $info = &drupal_static(__FUNCTION__); - - if (!isset($info[$entity_type])) { - $info[$entity_type] = module_invoke_all('field_ui_view_modes_tabs', $entity_type); - // Filter out inactive modes. - $entity_info = entity_get_info($entity_type); - foreach ($info[$entity_type] as $tab => $values) { - $modes = array(); - foreach ($info[$entity_type][$tab]['view modes'] as $mode) { - if (isset($entity_info['view modes'][$mode])) { - $modes[] = $mode; - } - } - if ($modes) { - $info[$entity_type][$tab]['view modes'] = $modes; + // Then, determine access according to the $access parameter. This duplicates + // part of _menu_check_access(). + if ($visibility) { + // Grab the variable 'access arguments' part. + $args = array_slice(func_get_args(), 4); + $callback = empty($access_callback) ? 0 : trim($access_callback); + if (is_numeric($callback)) { + return (bool) $callback; + } + else { + // As call_user_func_array() is quite slow and user_access is a very + // common callback, it is worth making a special case for it. + if ($access_callback == 'user_access') { + return (count($args) == 1) ? user_access($args[0]) : user_access($args[0], $args[1]); } - else { - unset($info[$entity_type][$tab]); + elseif (function_exists($access_callback)) { + return call_user_func_array($access_callback, $args); } } } - if ($tab_selector) { - return isset($info[$entity_type][$tab_selector]) ? $info[$entity_type][$tab_selector]['view modes'] : array(); - } - return $info[$entity_type]; -} - -/** - * Implements hook_field_ui_view_modes_tabs() on behalf of other core modules. - */ -function field_ui_field_ui_view_modes_tabs() { - $modes = array( - 'basic' => array( - 'title' => t('Basic'), - 'view modes' => array('teaser', 'full'), - ), - 'rss' => array( - 'title' => t('RSS'), - 'view modes' => array('rss'), - ), - 'print' => array( - 'title' => t('Print'), - 'view modes' => array('print'), - ), - 'search' => array( - 'title' => t('Search'), - 'view modes' => array('search_index', 'search_result'), - ), - ); - return $modes; } /** @@ -325,31 +298,6 @@ function field_ui_field_attach_create_bundle($entity_type, $bundle) { } /** - * Implements hook_field_attach_rename_bundle(). - */ -function field_ui_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { - if ($bundle_old !== $bundle_new) { - $extra_weights = variable_get('field_extra_weights', array()); - if (isset($info[$entity_type][$bundle_old])) { - $extra_weights[$entity_type][$bundle_new] = $extra_weights[$entity_type][$bundle_old]; - unset($extra_weights[$entity_type][$bundle_old]); - variable_set('field_extra_weights', $extra_weights); - } - } -} - -/** - * Implements hook_field_attach_delete_bundle(). - */ -function field_ui_field_attach_delete_bundle($entity_type, $bundle) { - $extra_weights = variable_get('field_extra_weights', array()); - if (isset($extra_weights[$entity_type][$bundle])) { - unset($extra_weights[$entity_type][$bundle]); - variable_set('field_extra_weights', $extra_weights); - } -} - -/** * Helper function to create the right administration path for a bundle. */ function _field_ui_bundle_admin_path($entity_type, $bundle_name) { |