function media_form_field_ui_field_storage_add_form_alter

Same name and namespace in other branches
  1. 9 core/modules/media/media.module \media_form_field_ui_field_storage_add_form_alter()
  2. 8.9.x 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 198

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 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.