diff -u b/media_entity.drush.inc b/media_entity.drush.inc --- b/media_entity.drush.inc +++ b/media_entity.drush.inc @@ -109,6 +109,19 @@ $passes[] = dt('Successfully checked that the "Media" module is not installed.'); } + // If there are any generic media bundles, ensure that media_entity_generic + // is available. + $generic_types = _media_entity_get_bundles_by_plugin('generic'); + if ($generic_types) { + $module_data = system_rebuild_module_data(); + if (isset($module_data['media_entity_generic'])) { + $passes[] = dt('Successfully located the media_entity_generic module.'); + } + else { + $errors[] = dt('One or more of your existing media types use the Generic source, which has been moved into a separate Media Entity Generic module. Please ensure this module is available before continuing.'); + } + } + // Check dependent modules and provider plugins. $incompatible_modules = _media_entity_get_incompatible_modules(); if (!empty($incompatible_modules)) { diff -u b/media_entity.install b/media_entity.install --- b/media_entity.install +++ b/media_entity.install @@ -130,6 +130,25 @@ } /** + * Gets the names of all media bundles that use a particular type plugin. + * + * @param string $plugin_id + * The type plugin ID. + * + * @return string[] + * The media bundle IDs which use the specified plugin. + */ +function _media_entity_get_bundles_by_plugin($plugin_id) { + $types = []; + foreach (\Drupal::configFactory()->listAll('media_entity.bundle') as $name) { + if (\Drupal::config($name)->get('type') == $plugin_id) { + $types[] = explode('.', $name, 3)[2]; + } + } + return $types; +} + +/** * Implements hook_requirements(). */ function media_entity_requirements($phase) { @@ -202,20 +221,13 @@ ]; } - $generic_is_used = FALSE; - foreach (\Drupal::configFactory()->listAll('media_entity.bundle') as $bundle) { - $type = \Drupal::config($bundle)->get('type'); - if ($type == 'generic') { - $generic_is_used = TRUE; - break; - } - } - if ($generic_is_used) { + $generic_types = _media_entity_get_bundles_by_plugin('generic'); + if ($generic_types) { $module_data = system_rebuild_module_data(); if (!isset($module_data['media_entity_generic'])) { $requirements['media_entity_generic'] = [ 'title' => t('Media entity generic'), - 'description' => t('One or more of your existing media types are using the Generic source, which has been moved into a separate Media Entity Generic module. You need to download this module before continuning.'), + 'description' => t('One or more of your existing media types are using the Generic source, which has been moved into a separate Media Entity Generic module. You need to download this module before continuing.'), 'severity' => REQUIREMENT_ERROR, ]; } @@ -412,6 +424,16 @@ } } + // Install media_entity_generic if available. It stands to reason that this + // module will only be available if you have at least one media type that uses + // the generic plugin, since it has been split out into its own module and is + // only requested if there are media bundles that use it. + // See media_entity_requirements(). + $module_data = system_rebuild_module_data(); + if (isset($module_data['media_entity_generic'])) { + \Drupal::service('module_installer')->install(['media_entity_generic']); + } + // Disable media_entity_image and media_entity_document straight away. $uninstall = ['media_entity_image', 'media_entity_document']; foreach ($uninstall as $module) {