function MediaHooks::formFieldUiFieldStorageAddFormAlter

Implements hook_form_FORM_ID_alter().

Attributes

#[Hook('form_field_ui_field_storage_add_form_alter')]

File

core/modules/media/src/Hook/MediaHooks.php, line 144

Class

MediaHooks
Hook implementations for media.

Namespace

Drupal\media\Hook

Code

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 = $this->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 .= ' ' . $this->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->getStorage()['field_type'], $field_types)) {
    $form['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.