You are here

protected function FileUploadForm::buildEntityFormElement in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::buildEntityFormElement()

Builds the sub-form for setting required fields on a new media item.

Parameters

\Drupal\media\MediaInterface $media: A new, unsaved media item.

array $form: The complete form.

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

int $delta: The delta of the media item.

Return value

array The element containing the required fields sub-form.

Overrides AddFormBase::buildEntityFormElement

File

core/modules/media_library/src/Form/FileUploadForm.php, line 246

Class

FileUploadForm
Creates a form to create media entities from uploaded files.

Namespace

Drupal\media_library\Form

Code

protected function buildEntityFormElement(MediaInterface $media, array $form, FormStateInterface $form_state, $delta) {
  $element = parent::buildEntityFormElement($media, $form, $form_state, $delta);
  $source_field = $this
    ->getSourceFieldName($media->bundle->entity);
  if (isset($element['fields'][$source_field])) {
    $element['fields'][$source_field]['widget'][0]['#process'][] = [
      static::class,
      'hideExtraSourceFieldComponents',
    ];
  }
  return $element;
}