If you enable Media without enabling File module previously (assumming that it will enable File as dependancy), you'll get a warning like "fieldexception: attempt to create a field of unknown type file. in field_create_field()"

It happens because Media does it's initialisation in hook_enable, when File module isn't yet finished to set up it's own structure. Instead, Media should init in hook_modules_enabled(). In this case, everything is good.

Comments

Status: Needs review » Needs work

The last submitted patch, media-install.patch, failed testing.

neochief’s picture

Status: Needs work » Needs review
StatusFileSize
new364 bytes

Status: Needs review » Needs work

The last submitted patch, media-install.patch, failed testing.

neochief’s picture

Status: Needs work » Needs review
StatusFileSize
new361 bytes

weird...

effulgentsia’s picture

Status: Needs review » Needs work

But we don't want that code running when any module is enabled. We only want it running when the media module is enabled. The problem is that we need some of the logic within field_modules_enabled() to run first, so the newly enabled file field is properly initialized. We could do this by changing to media_modules_enabled() as #4 suggests, but add a check to make sure 'media' is in the list of modules being enabled. But I'm not crazy about that, because it violates the pattern of modules taking care of their own enabling logic within hook_enable(). Basically, a lower weight module should be able to have its own hook_modules_enabled() that runs after the media module is properly enabled.

So what if instead, we keep it as media_enable(), but add this code at the top of it:

field_associate_fields('file');
field_cache_clear();

I'm not even sure if we need the first line, maybe just the second?

neochief’s picture

How the hook could work if module is disabled? :)

Leeteq’s picture

Title: Media module installation on vanila Drupal 7 throws errors » Media module installation throws errors if file module is disabled
effulgentsia’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Status: Needs work » Fixed

Fixed as part of #1086958: Switch from Media Entity to File Entity. See top of project page, however, for warnings about updating to the dev snapshot.

Status: Fixed » Closed (fixed)

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