Commit a87084f9 authored by catch's avatar catch
Browse files

Issue #3262805 by andypost, ravi.shankar, voleger, catch: Deprecate drupal_required_modules()

parent c25e7730
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -1126,7 +1126,9 @@ function install_profile_info($profile, $langcode = 'en') {
      'config_install_path' => NULL,
    ];
    $profile_path = \Drupal::service('extension.list.profile')->getPath($profile);
    $info = \Drupal::service('info_parser')->parse("$profile_path/$profile.info.yml");
    /** @var \Drupal\Core\Extension\InfoParserInterface $parser */
    $parser = \Drupal::service('info_parser');
    $info = $parser->parse("$profile_path/$profile.info.yml");
    $info += $defaults;

    $dependency_name_function = function ($dependency) {
@@ -1138,9 +1140,16 @@ function install_profile_info($profile, $langcode = 'en') {
    // Convert install key in [project:module] format.
    $info['install'] = array_map($dependency_name_function, $info['install']);

    // drupal_required_modules() includes the current profile as a dependency.
    // Remove that dependency, since a module cannot depend on itself.
    $required = array_diff(drupal_required_modules(), [$profile]);
    // Get a list of core's required modules.
    $required = [];
    $listing = new ExtensionDiscovery(\Drupal::root());
    $files = $listing->scan('module');
    foreach ($files as $name => $file) {
      $parsed = $parser->parse($file->getPathname());
      if (!empty($parsed) && !empty($parsed['required']) && $parsed['required']) {
        $required[] = $name;
      }
    }

    $locale = !empty($langcode) && $langcode != 'en' ? ['locale'] : [];

+6 −0
Original line number Diff line number Diff line
@@ -93,8 +93,14 @@ function module_load_include($type, $module, $name = NULL) {

/**
 * Returns an array of modules required by core.
 *
 * @deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. There's no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3262811
 */
function drupal_required_modules() {
  @trigger_error(__FUNCTION__ . "() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. There's no replacement. See https://www.drupal.org/node/3262811", E_USER_DEPRECATED);
  $listing = new ExtensionDiscovery(\Drupal::root());
  $files = $listing->scan('module');
  $required = [];
+21 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\KernelTests\Core\Extension;

use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\KernelTests\KernelTestBase;

/**
@@ -32,4 +33,24 @@ public function testModuleLoadInstall() {
    $this->assertStringEndsWith("node.install", $filename);
  }

  /**
   * Test deprecation of drupal_required_modules() function.
   */
  public function testDrupalRequiredModules() {
    $this->expectDeprecation("drupal_required_modules() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. There's no replacement. See https://www.drupal.org/node/3262811");
    /** @var \Drupal\Core\Extension\InfoParserInterface $parser */
    $parser = \Drupal::service('info_parser');
    $listing = new ExtensionDiscovery(\Drupal::root());
    $files = $listing->scan('module');
    // Empty as there's no install profile.
    $required = [];
    foreach ($files as $name => $file) {
      $info = $parser->parse($file->getPathname());
      if (!empty($info) && !empty($info['required']) && $info['required']) {
        $required[] = $name;
      }
    }
    $this->assertSame($required, drupal_required_modules());
  }

}