You are here

function _media_entity_get_incompatible_modules in Media entity 8.2

Checks if all contrib modules depending on media_entity were updated.

Return value

array An empty array if all modules that depend on media_entity were updated, or an array of incompatible modules otherwise. This array will be keyed by either "providers" or "modules", depending if the incompatible module is a contrib module that provides a type plugin (in which case it is expected to have been upgraded to its 2.x branch) or just a module that depends on "media_entity", respectively.

1 call to _media_entity_get_incompatible_modules()
CliService::validateDbUpdateRequirements in src/CliService.php
Verify if the upgrade to Media in core is possible.

File

./media_entity.install, line 46
Install, uninstall and update hooks for Media entity module.

Code

function _media_entity_get_incompatible_modules() {
  \Drupal::service('plugin.cache_clearer')
    ->clearCachedDefinitions();
  $incompatible_modules = [];

  // Modules that provide provider plugins need to have ben updated and be
  // implementing now @MediaSource instead of @MediaType plugins.
  $old_plugins = \Drupal::service('plugin.manager.media_entity.type')
    ->getDefinitions();

  // The main media_entity module defines a "generic" type. We are directly
  // handling this provider's configs in the update hook.
  unset($old_plugins['generic']);
  foreach ($old_plugins as $definition) {
    $incompatible_modules['providers'][$definition['provider']] = $definition['provider'];
  }

  // None of the enabled modules in the system should at this point depend on
  // media_entity anymore.

  /** @var \Drupal\Core\Extension\Extension[] $module_list */
  $module_list = \Drupal::moduleHandler()
    ->getModuleList();
  foreach (array_keys($module_list) as $module_name) {
    $info = system_get_info('module', $module_name);
    if (!empty($info['dependencies'])) {
      foreach ($info['dependencies'] as $dependency) {
        if ($dependency === 'media_entity' || $dependency === 'media_entity:media_entity') {
          $incompatible_modules['modules'][$module_name] = $module_name;
        }
      }
    }
  }

  // Disregard "media_entity_document" and "media_entity_image", once we will
  // uninstall them ourselves as part of the update hook.
  unset($incompatible_modules['providers']['media_entity_document']);
  unset($incompatible_modules['modules']['media_entity_document']);
  unset($incompatible_modules['providers']['media_entity_image']);
  unset($incompatible_modules['modules']['media_entity_image']);
  if (empty($incompatible_modules['providers'])) {
    unset($incompatible_modules['providers']);
  }
  if (empty($incompatible_modules['modules'])) {
    unset($incompatible_modules['modules']);
  }
  return $incompatible_modules;
}