' . 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.', 'route_name' => 'field_list', 'type' => MENU_NORMAL_ITEM, ); $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'] && isset($entity_info['route_base_path'])) { // Extract path information from the entity type. $path = $entity_info['route_base_path']; $default_path = preg_replace('/{' . DRUPAL_PHP_FUNCTION_PATTERN . '}/', '%', $path); // This is the position of the %field_ui_instance placeholder in the // items below. $field_position = count(explode('/', $path)) + 1; $items["$path/fields"] = array( 'title' => 'Manage fields', 'type' => MENU_LOCAL_TASK, 'route_name' => "field_ui.overview.$entity_type", 'weight' => 1, ); $items["$path/fields/%"] = array( 'title callback' => 'entity_page_label', 'title arguments' => array($field_position), 'route_name' => "field_ui.instance_edit.$entity_type", ); $items["$default_path/fields/%/edit"] = array( 'title' => 'Edit', 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items["$path/fields/%/field"] = array( 'title' => 'Field settings', 'type' => MENU_LOCAL_TASK, 'route_name' => "field_ui.field_edit.$entity_type", ); $items["$path/fields/%/delete"] = array( 'title' => 'Delete', 'type' => MENU_VISIBLE_IN_BREADCRUMB, 'route_name' => "field_ui.delete.$entity_type", 'weight' => 10, ); // 'Manage form display' tab. $items["$path/form-display"] = array( 'title' => 'Manage form display', 'type' => MENU_LOCAL_TASK, 'route_name' => "field_ui.form_display_overview.$entity_type", 'weight' => 2, ); // 'Manage display' tab. $items["$path/display"] = array( 'title' => 'Manage display', 'type' => MENU_LOCAL_TASK, 'route_name' => "field_ui.display_overview.$entity_type", 'weight' => 3, ); // View and form 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 a route requirement to determine which ones are // actually visible for a given bundle. $items["$default_path/form-display/default"] = array( 'title' => t('Default'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items["$default_path/display/default"] = array( 'title' => t('Default'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); $weight = 0; foreach (entity_get_form_modes($entity_type) as $form_mode => $form_mode_info) { $items["$path/form-display/$form_mode"] = array( 'title' => $form_mode_info['label'], 'type' => MENU_LOCAL_TASK, 'weight' => $weight++, 'route_name' => "field_ui.form_display_overview.$entity_type.$form_mode", ); } $weight = 0; foreach (entity_get_view_modes($entity_type) as $view_mode => $view_mode_info) { $items["$path/display/$view_mode"] = array( 'title' => $view_mode_info['label'], 'type' => MENU_LOCAL_TASK, 'weight' => $weight++, 'route_name' => "field_ui.display_overview.$entity_type.$view_mode", ); } } } 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 . ' form display'] = array( 'title' => t('%entity_label: Administer form display', array('%entity_label' => $entity_info['label'])) ); $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($entity_type, $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; } /** * 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', '#regions' => array('' => array()), ), ); } /** * Implements hook_entity_info(). */ function field_ui_entity_info(&$entity_info) { $entity_info['field_instance']['controllers']['form']['delete'] = 'Drupal\field_ui\Form\FieldDeleteForm'; $entity_info['field_entity']['controllers']['list'] = 'Drupal\field_ui\FieldListController'; } /** * 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. Drupal::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. Drupal::state()->set('menu_rebuild_needed', TRUE); } /** * 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 ($form_state['controller']->getEntity()->isNew()) { $form['actions']['save_continue'] = $form['actions']['submit']; $form['actions']['save_continue']['#value'] = t('Save and manage fields'); $form['actions']['save_continue']['#weight'] = $form['actions']['save_continue']['#weight'] + 5; $form['actions']['save_continue']['#submit'][] = 'field_ui_form_node_type_form_submit'; } } /** * Implements hook_entity_operation_alter(). */ function field_ui_entity_operation_alter(array &$operations, EntityInterface $entity) { $info = $entity->entityInfo(); // Add manage fields and display links if this entity type is the bundle // of another. if (!empty($info['bundle_of'])) { $bundle_of = $info['bundle_of']; $uri = $entity->uri(); if (user_access('administer '. $bundle_of . ' fields')) { $operations['manage-fields'] = array( 'title' => t('Manage fields'), 'href' => $uri['path'] . '/fields', 'options' => $uri['options'], 'weight' => 15, ); } if (user_access('administer '. $bundle_of . ' form display')) { $operations['manage-form-display'] = array( 'title' => t('Manage form display'), 'href' => $uri['path'] . '/form-display', 'options' => $uri['options'], 'weight' => 20, ); } if (user_access('administer '. $bundle_of . ' display')) { $operations['manage-display'] = array( 'title' => t('Manage display'), 'href' => $uri['path'] . '/display', 'options' => $uri['options'], 'weight' => 25, ); } } } /** * 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') { $admin_path = Drupal::entityManager()->getAdminPath('node', $form_state['values']['type']); $form_state['redirect'] = "$admin_path/fields"; } } /** * Implements hook_library_info(). */ function field_ui_library_info() { $libraries['drupal.field_ui'] = array( 'title' => 'Field UI', 'version' => Drupal::VERSION, 'js' => array( drupal_get_path('module', 'field_ui') . '/field_ui.js' => array(), ), 'css' => array( drupal_get_path('module', 'field_ui') . '/css/field_ui.admin.css' => array(), ), 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), array('system', 'drupalSettings'), array('system', 'jquery.once'), ), ); return $libraries; } /** * Implements hook_view_mode_presave(). */ function field_ui_view_mode_presave(EntityViewModeInterface $view_mode) { Drupal::state()->set('menu_rebuild_needed', TRUE); } /** * Implements hook_view_mode_delete(). */ function field_ui_view_mode_delete(EntityViewModeInterface $view_mode) { Drupal::state()->set('menu_rebuild_needed', TRUE); } /** * Returns HTML for Field UI overview tables. * * @param $variables * An associative array containing: * - elements: An associative array containing a Form API structure to be * rendered as a table. * * @ingroup themeable */ function theme_field_ui_table($variables) { $elements = $variables['elements']; $table = array('#theme' => 'table'); // Add table headers and attributes. foreach (array('#header', '#attributes') as $key) { if (isset($elements[$key])) { $table[$key] = $elements[$key]; } } // Determine the colspan to use for region rows, by checking the number of // columns in the headers. $columns_count = 0; foreach ($table['#header'] as $header) { $columns_count += (is_array($header) && isset($header['colspan']) ? $header['colspan'] : 1); } // Render rows, region by region. foreach ($elements['#regions'] as $region_name => $region) { $region_name_class = drupal_html_class($region_name); // Add region rows. if (isset($region['title']) && empty($region['invisible'])) { $table['#rows'][] = array( 'class' => array('region-title', 'region-' . $region_name_class . '-title'), 'no_striping' => TRUE, 'data' => array( array('data' => $region['title'], 'colspan' => $columns_count), ), ); } if (isset($region['message'])) { $class = (empty($region['rows_order']) ? 'region-empty' : 'region-populated'); $table['#rows'][] = array( 'class' => array('region-message', 'region-' . $region_name_class . '-message', $class), 'no_striping' => TRUE, 'data' => array( array('data' => $region['message'], 'colspan' => $columns_count), ), ); } // Add form rows, in the order determined at pre-render time. foreach ($region['rows_order'] as $name) { $element = $elements[$name]; $row = array('data' => array()); if (isset($element['#attributes'])) { $row += $element['#attributes']; } // Render children as table cells. foreach (element_children($element) as $cell_key) { $child = &$element[$cell_key]; // Do not render a cell for children of #type 'value'. if (!(isset($child['#type']) && $child['#type'] == 'value')) { $cell = array('data' => drupal_render($child)); if (isset($child['#cell_attributes'])) { $cell += $child['#cell_attributes']; } $row['data'][] = $cell; } } $table['#rows'][] = $row; } } return drupal_render($table); }