I had this module enabled on a project where I was trying to get core media working I ran into a problem that the entity 'media_bundle' could not be loaded. Digging a bit deeper I found that this module was trying to load that bundle with the following code

$entity = $form_state->getFormObject()->getEntity();
$bundle = $entity->bundle();
$entity_type = entity_load($type, $bundle);

And that confused me a little cause the entity is clearly from the type 'media' but the 'media_bundle' wasn't defined anywhere as far as I know except that this module makes some assumptions about it.

elseif ($info['base_form_id'] === 'media_form') {
$type = 'media_bundle';
}
.... and ....
elseif ($info['base_form_id'] === 'media_form') {
$type = 'media_bundle';
$route = 'media';
}

Can you please shine some light on it?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Rene Bakx created an issue. See original summary.

villette’s picture

Title: Strange behaviour when using core media » Support core media module
FileSize
781 bytes

I have the same error, it is caused by the fact that the entity defining the media type is called "media_type" in the core module whereas its name is "media_bundle" in the media_entity contrib module.

It means that this module does not support core media module, or partially. I haven't reviewed all the code of the module but I made a patch that answers this exact need. Maybe it would be necessary to check if there are some other places in the code to adapt.

I'm renaming this issue to encompass a larger scale.

iampuma’s picture

Category: Support request » Bug report
Priority: Normal » Major

Currently this module is broken with Drupal >= 8.5. As from there media has been added to core.

Reproduce by:
- Install vanilla Drupal
- Enable media
- Enable entity_redirect
- Observe error on /media/add/image

Setting this issue to bug report and priority to major as it breaks part of the site .

thejimbirch’s picture

Status: Active » Needs review

The error message is "The "media_bundle" entity type does not exist." when trying to edit a Media item.

The patch in #2 fixes this issue. Thanks @villette ! Thanks @Rene Bakx for posting!

dqd’s picture

Status: Needs review » Needs work

Applying the patch removes the first error when /media/add/image gets called first time, but it seems that there is one more spot where this needs to be fixed. Saving and publishing the added media causes still the same error after patch has been applied. But the files have been saved.

Running grep -rnw ./ -e media_bundle in module folder shows me a second place which needs to be fixed.

entity_redirect $ grep -rnw  ./ -e 'media_bundle'
./entity_redirect.module:102:      // 'media_bundle', if not, it means we are using the core media module
./entity_redirect.module:104:      $type = \Drupal::moduleHandler()->moduleExists('media_entity') ? 'media_bundle' : 'media_type';
./entity_redirect.module:148:    $type = 'media_bundle';
./entity_redirect.module:230:    'media_bundle' => [
dqd’s picture

Status: Needs work » Needs review
FileSize
2.15 KB
2.15 KB

First attempt to add issue fix on line 148 and 230 ...

dqd’s picture

FileSize
3.16 KB
3.16 KB

Oooops, mixed lines (if/else) ... wrong wrapping. again.

dqd’s picture

Version: 8.x-1.4 » 8.x-1.x-dev

Testing ... I can confirm error disappears on all instances of add > upload > save forms and redirects. Patch tested on 1.4 and latest dev for further release management.

  • diqidoq authored a51fdae on 8.x-1.x
    Issue #2917605 by diqidoq, villette, Rene Bakx, iampuma, thejimbirch:...
NickDickinsonWilde’s picture

Status: Needs review » Fixed

git commit -m 'Issue #2917605 by diqidoq, villette, Rene Bakx, iampuma, thejimbirch: Support core media module' --author="Digidog "

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.