function media_form_field_ui_field_storage_add_form_alter in Drupal 10
Same name and namespace in other branches
- 8 core/modules/media/media.module \media_form_field_ui_field_storage_add_form_alter()
- 9 core/modules/media/media.module \media_form_field_ui_field_storage_add_form_alter()
Implements hook_form_FORM_ID_alter().
File
- core/
modules/ media/ media.module, line 192 - Provides media items.
Code
function media_form_field_ui_field_storage_add_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Provide some help text to aid users decide whether they need a Media,
// File, or Image reference field.
$description_text = t('Use <em>Media</em> reference fields for most files, images, audio, videos, and remote media. Use <em>File</em> or <em>Image</em> reference fields when creating your own media types, or for legacy files and images created before enabling the Media module.');
if (\Drupal::moduleHandler()
->moduleExists('help')) {
$description_text .= ' ' . t('For more information, see the <a href="@help_url">Media help page</a>.', [
'@help_url' => Url::fromRoute('help.page', [
'name' => 'media',
])
->toString(),
]);
}
$form['add']['description_wrapper'] = [
'#type' => 'container',
];
$field_types = [
'file',
'image',
'field_ui:entity_reference:media',
];
foreach ($field_types as $field_name) {
$form['add']['description_wrapper']["description_{$field_name}"] = [
'#type' => 'item',
'#markup' => $description_text,
'#states' => [
'visible' => [
':input[name="new_storage_type"]' => [
'value' => $field_name,
],
],
],
];
}
$form['add']['new_storage_type']['#weight'] = 0;
$form['add']['description_wrapper']['#weight'] = 1;
}