' . t('About') . ''; $output .= '
' . t('The Field UI module provides an administrative user interface (UI) for attaching and managing fields. Fields can be defined at the content-type level for content items and comments, at the vocabulary level for taxonomy terms, and at the site level for user accounts. Other modules may also enable fields to be defined for their data. Field types (text, image, number, etc.) are defined by modules, and collected and managed by the Field module. For more information, see the online handbook entry for Field UI module.', array('@field' => url('admin/help/field'), '@field_ui' => 'http://drupal.org/documentation/modules/field-ui')) . '
'; $output .= '' . t('This list shows all fields currently in use for easy reference.') . '
'; } } /** * Implements hook_menu(). */ function field_ui_menu() { $items['admin/reports/fields'] = array( 'title' => 'Field list', 'description' => 'Overview of fields on all entity types.', 'page callback' => 'field_ui_fields_list', 'access arguments' => array('administer content types'), 'type' => MENU_NORMAL_ITEM, 'file' => 'field_ui.admin.inc', ); $items['admin/reports/fields/list'] = array( 'title' => 'Entities', 'type' => MENU_DEFAULT_LOCAL_TASK, ); // Create tabs for all possible bundles. foreach (entity_get_info() as $entity_type => $entity_info) { if ($entity_info['fieldable']) { foreach (entity_get_bundles($entity_type) 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_instance_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_instance placeholder in the // items below. $field_position = count(explode('/', $path)) + 1; // User access check to be done against the permission to edit // fields or the display per entity type. $access_fields = array( 'access callback' => 'user_access', 'access arguments' => array('administer ' . $entity_type . ' fields'), ); $access_display = array( 'access callback' => 'user_access', 'access arguments' => array('administer ' . $entity_type . ' display'), ); $items["$path/fields"] = array( 'title' => 'Manage fields', 'page callback' => 'field_ui_field_overview', 'page arguments' => array($entity_type, $bundle_arg), 'type' => MENU_LOCAL_TASK, 'weight' => 1, 'file' => 'field_ui.admin.inc', ) + $access_fields; $items["$path/fields/%field_ui_instance"] = array( 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), 'title callback' => 'field_ui_instance_title', 'title arguments' => array($field_position), 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_field_edit_form', $field_position), 'file' => 'field_ui.admin.inc', ) + $access_fields; $items["$path/fields/%field_ui_instance/edit"] = array( 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), 'title' => 'Edit', 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_field_edit_form', $field_position), 'type' => MENU_DEFAULT_LOCAL_TASK, 'file' => 'field_ui.admin.inc', ) + $access_fields; $items["$path/fields/%field_ui_instance/field-settings"] = array( 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), 'title' => 'Field settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_field_settings_form', $field_position), 'type' => MENU_LOCAL_TASK, 'file' => 'field_ui.admin.inc', ) + $access_fields; $items["$path/fields/%field_ui_instance/widget-type"] = array( 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), 'title' => 'Widget type', 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_widget_type_form', $field_position), 'type' => MENU_LOCAL_TASK, 'file' => 'field_ui.admin.inc', ) + $access_fields; $items["$path/fields/%field_ui_instance/delete"] = array( 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), 'title' => 'Delete', 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_field_delete_form', $field_position), 'type' => MENU_VISIBLE_IN_BREADCRUMB, 'weight' => 10, 'file' => 'field_ui.admin.inc', ) + $access_fields; // 'Manage display' tab. $items["$path/display"] = array( 'title' => 'Manage display', 'page callback' => 'field_ui_display_overview', 'page arguments' => array($entity_type, $bundle_arg, 'default'), 'type' => MENU_LOCAL_TASK, 'weight' => 2, 'file' => 'field_ui.admin.inc', ) + $access_display; // 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_get_view_modes($entity_type); foreach ($view_modes as $view_mode => $view_mode_info) { $items["$path/display/$view_mode"] = array( 'title' => $view_mode_info['label'], 'page callback' => 'field_ui_display_overview', 'page arguments' => array($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($entity_type, $bundle_arg, $view_mode, $access_display['access arguments'][0]), 'type' => ($view_mode == 'default' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK), 'file' => 'field_ui.admin.inc', ); if ($view_mode != 'default') { $items["$path/display/$view_mode"]['weight'] = $weight++; } } } } } } return $items; } /** * Implements hook_permission(). */ function field_ui_permission() { $permissions = array(); foreach (entity_get_info() as $entity_type => $entity_info) { if ($entity_info['fieldable']) { // Create a permission for each fieldable entity to manage // the fields and the display. $permissions['administer ' . $entity_type . ' fields'] = array( 'title' => t('%entity_label: Administer fields', array('%entity_label' => $entity_info['label'])), 'restrict access' => TRUE, ); $permissions['administer ' . $entity_type . ' display'] = array( 'title' => t('%entity_label: Administer display', array('%entity_label' => $entity_info['label'])) ); } } return $permissions; } /** * Menu loader callback: Loads a field instance based on field and bundle name. * * @param $field_name * The name of the field, as contained in the path. * @param $entity_type * The name of the entity. * @param $bundle_name * The name of the bundle, as contained in the path. * @param $bundle_pos * The position of $bundle_name in $map. * @param $map * The translated menu router path argument map. * * @return * The field instance array. * * @ingroup field */ function field_ui_instance_load($field_name, $entity_type, $bundle_name, $bundle_pos, $map) { // Extract the actual bundle name from the translated argument map. // The menu router path to manage fields of an entity can be shared among // multiple bundles. For example: // - admin/structure/types/manage/%node_type/fields/%field_ui_instance // - admin/structure/types/manage/%comment_node_type/fields/%field_ui_instance // The menu system will automatically load the correct bundle depending on the // actual path arguments, but this menu loader function only receives the node // type string as $bundle_name, which is not the bundle name for comments. // We therefore leverage the dynamically translated $map provided by the menu // system to retrieve the actual bundle and bundle name for the current path. if ($bundle_pos > 0) { $bundle = $map[$bundle_pos]; $bundle_name = field_extract_bundle($entity_type, $bundle); } // Check whether the field exists at all. if ($field = field_info_field($field_name)) { // Only return the field if a field instance exists for the given entity // type and bundle. if ($instance = field_info_instance($entity_type, $field_name, $bundle_name)) { return $instance; } } return FALSE; } /** * Title callback: Returns the name of a given instance. * * @see field_ui_menu() */ function field_ui_instance_title($instance) { return $instance['label']; } /** * Access callback: Checks access for the 'view mode display settings' pages. * * @see field_ui_menu() */ function _field_ui_view_mode_menu_access($entity_type, $bundle, $view_mode, $permission) { // 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']); // Then, determine access according to the $permission parameter. if ($visibility) { return user_access($permission); } } /** * Implements hook_theme(). */ function field_ui_theme() { return array( 'field_ui_table' => array( 'render element' => 'elements', ), ); } /** * Implements hook_element_info(). */ function field_ui_element_info() { return array( 'field_ui_table' => array( '#theme' => 'field_ui_table', '#pre_render' => array('field_ui_table_pre_render'), '#regions' => array('' => array()), ), ); } /** * Implements hook_entity_bundle_create(). */ function field_ui_entity_bundle_create($entity_type, $bundle) { // When a new bundle is created, the menu needs to be rebuilt to add our // menu item tabs. state()->set('menu_rebuild_needed', TRUE); } /** * Implements hook_entity_bundle_rename(). */ function field_ui_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { // When a bundle is renamed, the menu needs to be rebuilt to add our // menu item tabs. state()->set('menu_rebuild_needed', TRUE); } /** * Determines the adminstration path for a bundle. */ function field_ui_bundle_admin_path($entity_type, $bundle_name) { $bundles = entity_get_bundles($entity_type); $bundle_info = $bundles[$bundle_name]; if (isset($bundle_info['admin'])) { return isset($bundle_info['admin']['real path']) ? $bundle_info['admin']['real path'] : $bundle_info['admin']['path']; } } /** * Identifies inactive fields within a bundle. */ function field_ui_inactive_instances($entity_type, $bundle_name = NULL) { $params = array('entity_type' => $entity_type); if (empty($bundle_name)) { $active = field_info_instances($entity_type); $inactive = array(); } else { // Restrict to the specified bundle. For consistency with the case where // $bundle_name is NULL, the $active and $inactive arrays are keyed by // bundle name first. $params['bundle'] = $bundle_name; $active = array($bundle_name => field_info_instances($entity_type, $bundle_name)); $inactive = array($bundle_name => array()); } // Iterate on existing definitions, and spot those that do not appear in the // $active list collected earlier. $all_instances = field_read_instances($params, array('include_inactive' => TRUE)); foreach ($all_instances as $instance) { if (!isset($active[$instance['bundle']][$instance['field_name']])) { $inactive[$instance['bundle']][$instance['field_name']] = $instance; } } if (!empty($bundle_name)) { return $inactive[$bundle_name]; } return $inactive; } /** * Implements hook_form_FORM_ID_alter(). * * Adds a button 'Save and manage fields' to the 'Create content type' form. * * @see node_type_form() * @see field_ui_form_node_type_form_submit() */ function field_ui_form_node_type_form_alter(&$form, $form_state) { // We want to display the button only on add page. if (empty($form['#node_type']->type)) { $form['actions']['save_continue'] = array( '#type' => 'submit', '#value' => t('Save and manage fields'), '#weight' => 45, ); $form['#submit'][] = 'field_ui_form_node_type_form_submit'; } } /** * Form submission handler for the 'Save and manage fields' button. * * @see field_ui_form_node_type_form_alter() */ function field_ui_form_node_type_form_submit($form, &$form_state) { if ($form_state['triggering_element']['#parents'][0] === 'save_continue') { $form_state['redirect'] = field_ui_bundle_admin_path('node', $form_state['values']['type']) .'/fields'; } } /** * Implements hook_library_info(). */ function field_ui_library_info() { $libraries['drupal.field_ui'] = array( 'title' => 'Field UI', 'version' => VERSION, 'js' => array( drupal_get_path('module', 'field_ui') . '/field_ui.js' => array(), ), 'css' => array( drupal_get_path('module', 'field_ui') . '/field_ui.admin.css' => array(), ), 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), array('system', 'drupalSettings'), array('system', 'jquery.once'), ), ); return $libraries; }