' . 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.', [':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString(), ':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 [ 'field_ui_table' => [ 'variables' => [ 'header' => NULL, 'rows' => NULL, 'footer' => NULL, 'attributes' => [], 'caption' => NULL, 'colgroups' => [], 'sticky' => FALSE, 'responsive' => TRUE, 'empty' => '', ], ], ]; } /** * Implements hook_entity_type_build(). */ function field_ui_entity_type_build(array &$entity_types) { /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ $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_form_FORM_ID_alter(). * * Adds a button 'Save and manage fields' to the 'Create content type' form. * * @see \Drupal\node\NodeTypeForm * @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 = []; $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::entityTypeManager()->getDefinition($bundle_of)->get('field_ui_base_route')) { $account = \Drupal::currentUser(); if ($account->hasPermission('administer ' . $bundle_of . ' fields')) { $operations['manage-fields'] = [ 'title' => t('Manage fields'), 'weight' => 15, 'url' => Url::fromRoute("entity.{$bundle_of}.field_ui_fields", [ $entity->getEntityTypeId() => $entity->id(), ]), ]; } if ($account->hasPermission('administer ' . $bundle_of . ' form display')) { $operations['manage-form-display'] = [ 'title' => t('Manage form display'), 'weight' => 20, 'url' => Url::fromRoute("entity.entity_form_display.{$bundle_of}.default", [ $entity->getEntityTypeId() => $entity->id(), ]), ]; } if ($account->hasPermission('administer ' . $bundle_of . ' display')) { $operations['manage-display'] = [ 'title' => t('Manage display'), 'weight' => 25, 'url' => Url::fromRoute("entity.entity_view_display.{$bundle_of}.default", [ $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(); } /** * Prepares variables for field UI overview table templates. * * Default template: field-ui-table.html.twig. * * @param array $variables * An associative array containing: * - elements: An associative array containing a Form API structure to be * rendered as a table. */ function template_preprocess_field_ui_table(&$variables) { template_preprocess_table($variables); } /** * 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); } /** * Implements hook_form_FORM_ID_alter() for 'field_ui_field_storage_add_form'. */ function field_ui_form_field_ui_field_storage_add_form_alter(array &$form) { $optgroup = (string) t('Reference'); // Move the "Entity reference" option to the end of the list and rename it to // "Other". unset($form['add']['new_storage_type']['#options'][$optgroup]['entity_reference']); $form['add']['new_storage_type']['#options'][$optgroup]['entity_reference'] = t('Other…'); }