Thank you for your great work in different Media Entity modules!

In the last week I built a website-skeleton with Lightning.

In addition, I installed the Media Entity Audio module. I am aware, that this module is in development. Nevertheless I’d like to report some issues, which I have with it:

From /admin/content/media/add/audio

Notice: Trying to get property of non-object in Drupal\media_entity_audio\Plugin\MediaEntity\Type\Audio->thumbnail() (line 73 of /Path/to/my/website.com/docroot/modules/contrib/media_entity_audio/src/Plugin/MediaEntity/Type/Audio.php).

From the node-edit-form with the Entity-browser-widget/views-view/Dropzone.js:

The website encountered an unexpected error. Please try again later.

TypeError: Argument 2 passed to Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent::__construct() must implement interface Drupal\file\FileInterface, null given, called in /Path/to/my/website.com/docroot/modules/contrib/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/MediaEntityDropzoneJsEbWidget.php on line 184 in Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent->__construct() (line 69 of /Path/to/my/website.com/docroot/modules/contrib/dropzonejs/src/Events/DropzoneMediaEntityCreateEvent.php).

From the node-edit-form with the Entity-browser-widget/media_entity_audio_upload:

Error: The media bundle is not configured correctly.

From the node-edit-form with the Entity-browser-widget/file_upload:

Does not respect the alowed file extensions setting (mp3) in field-setting of the media audio bundle:

System-Message:
“The specified file MyFile.mp3 could not be uploaded.
Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.”

I also tried 8.x-1.0-beta3 with similar issues.

If it helps further, I could also report those in detail.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Thomas Factory created an issue. See original summary.

tedfordgif’s picture

The file extension part is related to Lightning, which provides the file upload widget, but doesn't take into account the allowed extensions of all the media bundles included in the media browser. You can use hook_form_alter() to allow additional file types.

/**
 * Implements hook_form_alter().
 *
 * Allows audio extensions for media upload form.
 */
function customizations_form_entity_browser_media_browser_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  // See file_save_upload().
  $extensions = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp mp3 m4a ogg webm';
  $validators = ['file_validate_extensions' => [$extensions]];
  $form['widget']['file']['#upload_validators'] = $validators;
}

See #2719067: Additional out of box media bundles for future discussion and direction.

bkosborne’s picture

The reason you're getting the Notice: Trying to get property of non-object in Drupal\media_entity_audio\Plugin\MediaEntity\Type\Audio notice is because you need to re-edit the media bundle after adding the File field and save it again. The audio media handler relies on knowing which file field stores the audio file, and this is not known until you've already configured all the file fields. So after you do that, you must go back to edit the media bundle and save it after selecting your file field.

I suggest creating separate issues for everything else remaining.

bkosborne’s picture

jonathanshaw’s picture

Status: Active » Closed (works as designed)

So it look like none of this is actually a Media Entity Audio issue.

Nigel Cunningham’s picture

Status: Closed (works as designed) » Needs review
FileSize
1.03 KB

Hi there.

I'm reopening this bug as I've found the beta 3 doesn't work with the media widget, even after doing the above, and have diagnosed the cause and prepared a patch. The problem was that the Audio MediaEntity type doesn't implement the required interfaces for the supported file types to be picked up by the validation checks. The attached patch addresses this.

(Edit:)

With this patch applied, you can use the File Upload widget in the Media Browser in a WYSIWYG and extensions. Assuming that it's configured to allow audio uploads, files with the chosen extensions will successfully upload and save.