Commit 3834d60f authored by catch's avatar catch
Browse files

Issue #3072702 by alexpott, Wim Leers, mikelutz, xjm, catch, Berdir, tedbow,...

Issue #3072702 by alexpott, Wim Leers, mikelutz, xjm, catch, Berdir, tedbow, shaal, webchick, Mixologic, heddn: Core extensions should not need to specify the new core_version_requirement in *.info.yml files so that 9.0.x can be installed
parent 962d2db5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1629,6 +1629,7 @@ services:
    arguments: ['@library.discovery', '@library.dependency_resolver', '@module_handler', '@theme.manager', '@language_manager', '@cache.data']
  info_parser:
    class: Drupal\Core\Extension\InfoParser
    arguments: ['@app.root']
  twig:
    class: Drupal\Core\Template\TwigEnvironment
    arguments: ['@app.root', '@cache.default', '%twig_extension_hash%', '@state', '@twig.loader', '%twig.config%']
+1 −1
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ protected function getProfiles($include_hidden = FALSE, $auto_select_distributio
    $listing = new ExtensionDiscovery(getcwd(), FALSE);
    $listing->setProfileDirectories([]);
    $profiles = [];
    $info_parser = new InfoParserDynamic();
    $info_parser = new InfoParserDynamic(getcwd());
    foreach ($listing->scan('profile') as $profile) {
      $details = $info_parser->parse($profile->getPathname());
      // Don't show hidden profiles.
+32 −6
Original line number Diff line number Diff line
@@ -11,11 +11,33 @@
 */
class InfoParserDynamic implements InfoParserInterface {

  /**
   * The root directory of the Drupal installation.
   *
   * @var string
   */
  protected $root;

  /**
   * The earliest Drupal version that supports the 'core_version_requirement'.
   */
  const FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION = '8.7.7';

  /**
   * InfoParserDynamic constructor.
   *
   * @param string|null $app_root
   *   The root directory of the Drupal installation.
   */
  public function __construct(string $app_root = NULL) {
    if ($app_root === NULL) {
      // @todo https://www.drupal.org/project/drupal/issues/3087975 Require
      //   $app_root argument.
      $app_root = \Drupal::hasService('app.root') ? (string) \Drupal::service('app.root') : DRUPAL_ROOT;
    }
    $this->root = $app_root;
  }

  /**
   * {@inheritdoc}
   */
@@ -34,14 +56,18 @@ public function parse($filename) {
      if (!empty($missing_keys)) {
        throw new InfoParserException('Missing required keys (' . implode(', ', $missing_keys) . ') in ' . $filename);
      }
      if ($parsed_info['type'] === 'profile' && isset($parsed_info['core_version_requirement'])) {
        // @todo Support the 'core_version_requirement' key in profiles in
        //   https://www.drupal.org/node/3070401.
        throw new InfoParserException("The 'core_version_requirement' key is not supported in profiles in $filename");
      }
      if (!isset($parsed_info['core']) && !isset($parsed_info['core_version_requirement'])) {
        if (strpos($filename, 'core/') === 0 || strpos($filename, $this->root . '/core/') === 0) {
          // Core extensions do not need to specify core compatibility: they are
          // by definition compatible so a sensible default is used. Core
          // modules are allowed to provide these for testing purposes.
          $parsed_info['core_version_requirement'] = \Drupal::VERSION;
        }
        else {
          // Non-core extensions must specify core compatibility.
          throw new InfoParserException("The 'core' or the 'core_version_requirement' key must be present in " . $filename);
        }
      }
      if (isset($parsed_info['core']) && !preg_match("/^\d\.x$/", $parsed_info['core'])) {
        throw new InfoParserException("Invalid 'core' value \"{$parsed_info['core']}\" in " . $filename);
      }
+5 −7
Original line number Diff line number Diff line
@@ -67,9 +67,7 @@ protected function setUp() {
    $this->themeHandler = $this->container->get('theme_handler');
    $this->themeHandler->refreshInfo();

    $vfs_root = vfsStream::setup('root');
    $vfs_root->addChild(vfsStream::newDirectory($this->siteDirectory));
    $site_dir = $vfs_root->getChild($this->siteDirectory);
    $vfs_root = vfsStream::setup('core');
    vfsStream::create([
      'themes' => [
        'test_stable' => [
@@ -81,7 +79,7 @@ protected function setUp() {
          'stable.theme' => file_get_contents(DRUPAL_ROOT . '/core/themes/stable/stable.theme'),
        ],
      ],
    ], $site_dir);
    ], $vfs_root);
  }

  /**
@@ -116,8 +114,8 @@ class VfsThemeExtensionList extends ThemeExtensionList {
   */
  public function __construct(string $root, string $type, CacheBackendInterface $cache, InfoParserInterface $info_parser, ModuleHandlerInterface $module_handler, StateInterface $state, ConfigFactoryInterface $config_factory, ThemeEngineExtensionList $engine_list, $install_profile) {
    parent::__construct($root, $type, $cache, $info_parser, $module_handler, $state, $config_factory, $engine_list, $install_profile);
    $this->extensionDiscovery = new ExtensionDiscovery('vfs://root');
    $this->infoParser = new VfsInfoParser();
    $this->extensionDiscovery = new ExtensionDiscovery('vfs://core');
    $this->infoParser = new VfsInfoParser('vfs:/');
  }

  /**
@@ -135,7 +133,7 @@ class VfsInfoParser extends InfoParser {
   * {@inheritdoc}
   */
  public function parse($filename) {
    return parent::parse("vfs://root/$filename");
    return parent::parse("vfs://core/$filename");
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ public function testUploadModule() {
    // child site has access to, standard module API functions won't find it
    // when called here. To get the version, the info file must be parsed
    // directly instead.
    $info_parser = new InfoParserDynamic();
    $info_parser = new InfoParserDynamic(DRUPAL_ROOT);
    $info = $info_parser->parse($installedInfoFilePath);
    $this->assertEqual($info['version'], '8.x-1.0');

Loading