' . 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_permission(). */ function field_ui_permission() { $permissions = array(); foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) { if ($entity_type->isFieldable()) { // Create a permission for each fieldable entity to manage // the fields and the display. $permissions['administer ' . $entity_type_id . ' fields'] = array( 'title' => t('%entity_label: Administer fields', array('%entity_label' => $entity_type->getLabel())), 'restrict access' => TRUE, ); $permissions['administer ' . $entity_type_id . ' form display'] = array( 'title' => t('%entity_label: Administer form display', array('%entity_label' => $entity_type->getLabel())) ); $permissions['administer ' . $entity_type_id . ' display'] = array( 'title' => t('%entity_label: Administer display', array('%entity_label' => $entity_type->getLabel())) ); } } return $permissions; } /** * 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_type_build(). */ function field_ui_entity_type_build(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ $entity_types['field_instance_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldInstanceConfigDeleteForm'); $entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder'); foreach ($entity_types as $entity_type) { if ($bundle = $entity_type->getBundleOf()) { $entity_type ->setLinkTemplate('field_ui-fields', "field_ui.overview_$bundle") ->setLinkTemplate('field_ui-form-display', "field_ui.form_display_overview_$bundle") ->setLinkTemplate('field_ui-display', "field_ui.display_overview_$bundle"); } } } /** * 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::service('router.builder')->setRebuildNeeded(); } /** * 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::service('router.builder')->setRebuildNeeded(); } /** * 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'; // Hide the 'Save content type' button. $form['actions']['submit']['#access'] = FALSE; } } /** * Implements hook_entity_operation_alter(). */ function field_ui_entity_operation_alter(array &$operations, EntityInterface $entity) { $info = $entity->getEntityType(); // Add manage fields and display links if this entity type is the bundle // of another. if ($bundle_of = $info->getBundleOf()) { if (user_access('administer '. $bundle_of . ' fields')) { $operations['manage-fields'] = array( 'title' => t('Manage fields'), 'weight' => 15, ) + $entity->urlInfo('field_ui-fields')->toArray(); } if (user_access('administer '. $bundle_of . ' form display')) { $operations['manage-form-display'] = array( 'title' => t('Manage form display'), 'weight' => 20, ) + $entity->urlInfo('field_ui-form-display')->toArray(); } if (user_access('administer '. $bundle_of . ' display')) { $operations['manage-display'] = array( 'title' => t('Manage display'), 'weight' => 25, ) + $entity->urlInfo('field_ui-display')->toArray(); } } } /** * 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' && $route_info = FieldUI::getOverviewRouteInfo('node', $form_state['values']['type'])) { $form_state['redirect_route'] = $route_info; } } /** * Implements hook_view_mode_presave(). */ function field_ui_view_mode_presave(EntityViewModeInterface $view_mode) { \Drupal::service('router.builder')->setRebuildNeeded(); } /** * Implements hook_view_mode_delete(). */ function field_ui_view_mode_delete(EntityViewModeInterface $view_mode) { \Drupal::service('router.builder')->setRebuildNeeded(); } /** * 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('#type' => '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); } /** * Implements hook_local_tasks_alter(). */ function field_ui_local_tasks_alter(&$local_tasks) { $container = \Drupal::getContainer(); $local_task = FieldUiLocalTask::create($container, 'field_ui.fields'); $local_task->alterLocalTasks($local_tasks); }