' . t('About') . ''; $output .= '
' . t('The Field UI module provides an administrative user interface (UI) for managing and displaying fields. Fields can be attached to most content entity sub-types. Different field types, widgets, and formatters are provided by the modules enabled on your site, and managed by the Field module. For background information and terminology related to fields and entities, see the Field module help page. For more information about the Field UI, see the online documentation for the Field UI module.', array('!field' => \Drupal::url('help.page', array('name' => 'field')), '!field_ui_docs' => 'https://www.drupal.org/documentation/modules/field-ui')) . '
'; $output .= '' . t('This list shows all fields currently in use for easy reference.') . '
'; } } /** * Implements hook_theme(). */ function field_ui_theme() { return array( 'field_ui_table' => array( 'render element' => 'elements', 'function' => 'theme_field_ui_table', ), ); } /** * Implements hook_entity_type_build(). */ function field_ui_entity_type_build(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ $entity_types['field_config']->setFormClass('edit', 'Drupal\field_ui\Form\FieldConfigEditForm'); $entity_types['field_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldConfigDeleteForm'); $entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder'); $entity_types['field_storage_config']->setFormClass('edit', 'Drupal\field_ui\Form\FieldStorageConfigEditForm'); $entity_types['field_storage_config']->setListBuilderClass('Drupal\field_ui\FieldStorageConfigListBuilder'); $entity_types['field_storage_config']->setLinkTemplate('collection', '/admin/reports/fields'); $entity_types['entity_form_display']->setFormClass('edit', 'Drupal\field_ui\Form\EntityFormDisplayEditForm'); $entity_types['entity_view_display']->setFormClass('edit', 'Drupal\field_ui\Form\EntityViewDisplayEditForm'); $form_mode = $entity_types['entity_form_mode']; $form_mode->setListBuilderClass('Drupal\field_ui\EntityFormModeListBuilder'); $form_mode->setFormClass('add', 'Drupal\field_ui\Form\EntityFormModeAddForm'); $form_mode->setFormClass('edit', 'Drupal\field_ui\Form\EntityDisplayModeEditForm'); $form_mode->setFormClass('delete', 'Drupal\field_ui\Form\EntityDisplayModeDeleteForm'); $form_mode->set('admin_permission', 'administer display modes'); $form_mode->setLinkTemplate('delete-form', '/admin/structure/display-modes/form/manage/{entity_form_mode}/delete'); $form_mode->setLinkTemplate('edit-form', '/admin/structure/display-modes/form/manage/{entity_form_mode}'); $form_mode->setLinkTemplate('add-form', '/admin/structure/display-modes/form/add/{entity_type_id}'); $form_mode->setLinkTemplate('collection', '/admin/structure/display-modes/form'); $view_mode = $entity_types['entity_view_mode']; $view_mode->setListBuilderClass('Drupal\field_ui\EntityDisplayModeListBuilder'); $view_mode->setFormClass('add', 'Drupal\field_ui\Form\EntityDisplayModeAddForm'); $view_mode->setFormClass('edit', 'Drupal\field_ui\Form\EntityDisplayModeEditForm'); $view_mode->setFormClass('delete', 'Drupal\field_ui\Form\EntityDisplayModeDeleteForm'); $view_mode->set('admin_permission', 'administer display modes'); $view_mode->setLinkTemplate('delete-form', '/admin/structure/display-modes/view/manage/{entity_view_mode}/delete'); $view_mode->setLinkTemplate('edit-form', '/admin/structure/display-modes/view/manage/{entity_view_mode}'); $view_mode->setLinkTemplate('add-form', '/admin/structure/display-modes/view/add/{entity_type_id}'); $view_mode->setLinkTemplate('collection', '/admin/structure/display-modes/view'); } /** * 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, FormStateInterface $form_state) { // We want to display the button only on add page. if ($form_state->getFormObject()->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(). */ function field_ui_entity_operation(EntityInterface $entity) { $operations = array(); $info = $entity->getEntityType(); // Add manage fields and display links if this entity type is the bundle // of another and that type has field UI enabled. if (($bundle_of = $info->getBundleOf()) && \Drupal::entityManager()->getDefinition($bundle_of)->get('field_ui_base_route')) { $account = \Drupal::currentUser(); if ($account->hasPermission('administer '. $bundle_of . ' fields')) { $operations['manage-fields'] = array( 'title' => t('Manage fields'), 'weight' => 15, 'url' => Url::fromRoute("entity.{$bundle_of}.field_ui_fields", array( $entity->getEntityTypeId() => $entity->id(), )), ); } if ($account->hasPermission('administer '. $bundle_of . ' form display')) { $operations['manage-form-display'] = array( 'title' => t('Manage form display'), 'weight' => 20, 'url' => Url::fromRoute("entity.entity_form_display.{$bundle_of}.default", array( $entity->getEntityTypeId() => $entity->id(), )), ); } if ($account->hasPermission('administer '. $bundle_of . ' display')) { $operations['manage-display'] = array( 'title' => t('Manage display'), 'weight' => 25, 'url' => Url::fromRoute("entity.entity_view_display.{$bundle_of}.default", array( $entity->getEntityTypeId() => $entity->id(), )), ); } } return $operations; } /** * 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, FormStateInterface $form_state) { if ($form_state->getTriggeringElement()['#parents'][0] === 'save_continue' && $route_info = FieldUI::getOverviewRouteInfo('node', $form_state->getValue('type'))) { $form_state->setRedirectUrl($route_info); } } /** * Implements hook_entity_view_mode_presave(). */ function field_ui_entity_view_mode_presave(EntityViewModeInterface $view_mode) { \Drupal::service('router.builder')->setRebuildNeeded(); } /** * Implements hook_entity_form_mode_presave(). */ function field_ui_entity_form_mode_presave(EntityFormModeInterface $form_mode) { \Drupal::service('router.builder')->setRebuildNeeded(); } /** * Implements hook_entity_view_mode_delete(). */ function field_ui_entity_view_mode_delete(EntityViewModeInterface $view_mode) { \Drupal::service('router.builder')->setRebuildNeeded(); } /** * Implements hook_entity_form_mode_delete(). */ function field_ui_entity_form_mode_delete(EntityFormModeInterface $form_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 = Html::getClass($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); }