diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php index 838b189..70f1e5b 100644 --- a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php @@ -18,8 +18,8 @@ * @FieldType( * id = "file", * label = @Translation("File"), - * description = @Translation("This field stores the ID of a file as an integer value. Use a file field when you want to upload an arbitrary file to an entity, generally without re-usability needs. If in doubt, 'Media' field types should be preferred instead."), - * category = @Translation("[Non-reusable assets]"), + * description = @Translation("Use a file field when you want to upload an arbitrary file to an entity, generally without re-usability needs. If in doubt, 'Media' field types should be preferred instead."), + * category = @Translation("Reference"), * default_widget = "file_generic", * default_formatter = "file_default", * list_class = "\Drupal\file\Plugin\Field\FieldType\FileFieldItemList", diff --git a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php index 72e90d5..c9189ae 100644 --- a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php +++ b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php @@ -18,8 +18,8 @@ * @FieldType( * id = "image", * label = @Translation("Image"), - * description = @Translation("This field stores the ID of an image file as an integer value. Use an image field when you want to upload an image to on entity, generally without re-usability needs. If in doubt, 'Media' field types should be preferred instead."), - * category = @Translation("[Non-reusable assets]"), + * description = @Translation("Use an image field when you want to upload an image to on entity, generally without re-usability needs. If in doubt, 'Media' field types should be preferred instead."), + * category = @Translation("Reference"), * default_widget = "image_image", * default_formatter = "image", * column_groups = { diff --git a/core/modules/media/media.module b/core/modules/media/media.module index dc2d898..4aebfda 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -10,6 +10,7 @@ use Drupal\field\FieldConfigInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Render\Element; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; @@ -96,3 +97,21 @@ function template_preprocess_media(array &$variables) { $variables['content'][$key] = $variables['elements'][$key]; } } + +/** + * Implements hook_form_FORM_ID_alter(). + */ +function media_form_field_ui_field_storage_add_form_alter(array &$form, FormStateInterface $form_state) { + // Move the "File" and "Image" field types to a new category to favor the use + // of "Media" reference fields instead. + $reference_category = t('Reference')->__toString(); + $new_category = t('[Non-reusable assets]')->__toString(); + if (isset($form['add']['new_storage_type']['#options'][$reference_category]['image'])) { + $form['add']['new_storage_type']['#options'][$new_category]['image'] = $form['add']['new_storage_type']['#options'][$reference_category]['image']; + unset($form['add']['new_storage_type']['#options'][$reference_category]['image']); + } + if (isset($form['add']['new_storage_type']['#options'][$reference_category]['file'])) { + $form['add']['new_storage_type']['#options'][$new_category]['file'] = $form['add']['new_storage_type']['#options'][$reference_category]['file']; + unset($form['add']['new_storage_type']['#options'][$reference_category]['file']); + } +}