function MediaHooks::formFieldUiFieldStorageAddFormAlter
Implements hook_form_FORM_ID_alter().
File
-
core/
modules/ media/ src/ Hook/ MediaHooks.php, line 139
Class
- MediaHooks
- Hook implementations for media.
Namespace
Drupal\media\HookCode
public function formFieldUiFieldStorageAddFormAlter(&$form, FormStateInterface $form_state, $form_id) : void {
// 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 installing 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(),
]);
}
$field_types = [
'file_upload',
'field_ui:entity_reference:media',
];
if (in_array($form_state->getValue('new_storage_type'), $field_types)) {
$form['group_field_options_wrapper']['description_wrapper'] = [
'#type' => 'item',
'#markup' => $description_text,
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.