diff -u b/core/modules/media_library/src/Form/MediaLibraryUploadForm.php b/core/modules/media_library/src/Form/MediaLibraryUploadForm.php --- b/core/modules/media_library/src/Form/MediaLibraryUploadForm.php +++ b/core/modules/media_library/src/Form/MediaLibraryUploadForm.php @@ -128,7 +128,7 @@ '#process' => array_merge(['::validateUploadElement'], $process, ['::processUploadElement']), '#allowed_types' => $this->getTypes(), ]; - $this->typeResolver->alterFormElement($element, $form, $form_state); + $this->typeResolver->alterFormElement($form['upload'], $form, $form_state); $form['upload_help'] = [ '#theme' => 'file_upload_help', '#description' => $this->t('Upload files here to add new media.'), @@ -422,8 +422,10 @@ 'bundle' => $type, 'name' => $file->getFilename(), ]); - $source_field = $media->bundle->entity->getSource()->getSourceFieldDefinition($type)->getName(); - $media->set($source_field, $file->id()); + $source_field = $media->bundle->entity->getSource() + ->getSourceFieldDefinition($media->bundle->entity) + ->getName(); + $location = $media ->set($source_field, $file->id()) ->get($source_field)