You are here

public function MediaSubFormManager::buildMediaSubForm in Media Bulk Upload 8

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

Overrides MediaSubFormManagerInterface::buildMediaSubForm

File

src/MediaSubFormManager.php, line 161

Class

MediaSubFormManager
Class MediaSubFormManager.

Namespace

Drupal\media_bulk_upload

Code

public function buildMediaSubForm(array &$form, FormStateInterface $form_state, MediaBulkConfigInterface $mediaBulkConfig) {
  $mediaTypes = $this->mediaTypeManager
    ->getBulkMediaTypes($mediaBulkConfig);
  $mediaType = reset($mediaTypes);

  /** @var \Drupal\media\MediaInterface $dummyMedia */
  $dummyMedia = $this->mediaStorage
    ->create([
    'bundle' => $mediaType
      ->id(),
  ]);
  $mediaFormDisplay = $this
    ->getMediaFormDisplay($mediaBulkConfig, $mediaType);
  $mediaFormDisplay
    ->buildForm($dummyMedia, $form, $form_state);
  $targetFieldName = $this->mediaTypeManager
    ->getTargetFieldName($mediaType);
  unset($form[$targetFieldName]);
  $fields = $this
    ->getFields($mediaBulkConfig);
  if (empty($fields)) {
    return $this;
  }
  $this
    ->configureSharedFields($form, $fields);
  return $this;
}