diff -u b/core/includes/install.inc b/core/includes/install.inc --- b/core/includes/install.inc +++ b/core/includes/install.inc @@ -11,8 +11,6 @@ use Drupal\Component\Utility\OpCodeCache; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Extension\ExtensionDiscovery; -use Drupal\Core\Extension\ModuleHandler; -use Drupal\Core\Extension\ProfileHandler; use Drupal\Core\Site\Settings; /** diff -u b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php --- b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php +++ b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php @@ -78,7 +78,6 @@ $this->folders += $this->getCoreNames(); $install_profile = Settings::get('install_profile'); - $profile = drupal_get_profile(); $extensions = $this->configStorage->read('core.extension'); // @todo Remove this scan as part of https://www.drupal.org/node/2186491 $listing = new ExtensionDiscovery(\Drupal::root()); @@ -110,14 +109,7 @@ // default configuration. We do this by replacing the config file path // from the module/theme with the install profile version if there are // any duplicates. - if (isset($profile)) { - // Get the profile and any parents. - $profiles = \Drupal::service('profile_handler')->getProfiles($profile); - foreach ($profiles as $extension) { - $profile_folders = $this->getComponentNames(array($extension)); - $this->folders = $profile_folders + $this->folders; - } - } + $this->folders += $this->getComponentNames(\Drupal::service('profile_handler')->getProfiles($install_profile)); } } return $this->folders; diff -u b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php --- b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php @@ -5,7 +5,6 @@ use Drupal\Component\FileCache\FileCacheFactory; use Drupal\Core\DrupalKernel; use Drupal\Core\Extension\Discovery\RecursiveExtensionFilterIterator; -use Drupal\Core\Extension\ProfileHandlerInterface; use Drupal\Core\Site\Settings; use Symfony\Component\HttpFoundation\Request; @@ -125,6 +124,8 @@ $this->fileCache = $use_file_cache ? FileCacheFactory::get('extension_discovery') : NULL; $this->profileDirectories = $profile_directories; $this->sitePath = $site_path; + // ExtensionDiscovery can be called without a service container. + // (@drupalKernel::moduleData) so check if profile_handler is available. if (!isset($profile_handler) && \Drupal::hasService('profile_handler')) { $this->profileHandler = \Drupal::service('profile_handler'); } @@ -264,8 +265,6 @@ // In case both profile directories contain the same extension, the actual // profile always has precedence. if ($profile) { - // ExtensionDiscovery can be called without a service container. - // (@drupalKernel::moduleData) so check if profile_handler is available. if (isset($this->profileHandler)) { $profiles = $this->profileHandler->getProfiles($profile); $profile_directories = array_map(function($extension) { diff -u b/core/lib/Drupal/Core/Extension/ProfileHandler.php b/core/lib/Drupal/Core/Extension/ProfileHandler.php --- b/core/lib/Drupal/Core/Extension/ProfileHandler.php +++ b/core/lib/Drupal/Core/Extension/ProfileHandler.php @@ -43,6 +43,13 @@ protected $infoParser; /** + * An extension discovery instance. + * + * @var \Drupal\Core\Extension\ExtensionDiscovery + */ + protected $extensionDiscovery; + + /** * Local variable used to set profile weights * * @var int @@ -56,10 +63,26 @@ * The app root. * @param \Drupal\Core\Extension\InfoParserInterface $info_parser * The info parser to parse the profile.info.yml files. + * @param \Drupal\Core\Extension\ExtensionDiscovery $extension_discovery + * (optional) A extension discovery instance (for unit tests). */ - public function __construct($root, InfoParserInterface $info_parser) { + public function __construct($root, InfoParserInterface $info_parser, ExtensionDiscovery $extension_discovery = NULL) { $this->root = $root; $this->infoParser = $info_parser; + $this->extensionDiscovery = $extension_discovery; + } + + /** + * Returns an extension discovery object. + * + * @return \Drupal\Core\Extension\ExtensionDiscovery + * The extension discovery object. + */ + protected function getExtensionDiscovery() { + if (!isset($this->extensionDiscovery)) { + $this->extensionDiscovery = new ExtensionDiscovery($this->root); + } + return $this->extensionDiscovery; } /** @@ -76,7 +99,7 @@ // @todo Remove as part of https://www.drupal.org/node/2186491. $modules_cache = &drupal_static('system_rebuild_module_data'); if (!$this->scan_cache && !isset($modules_cache)) { - $listing = new ExtensionDiscovery(\Drupal::root()); + $listing = $this->getExtensionDiscovery(); // Find installation profiles. This needs to happen before performing a // module scan as the module scan requires knowing what the active profile is. // @todo Remove as part of https://www.drupal.org/node/2186491. @@ -232,7 +255,7 @@ /** * {@inheritdoc} */ - static function getProfileBaseName($info) { + static public function getProfileBaseName($info) { return !empty($info['base profile']['name']) ? $info['base profile']['name'] : (!empty($info['base profile']) ? $info['base profile'] : ''); diff -u b/core/lib/Drupal/Core/Extension/ProfileHandlerInterface.php b/core/lib/Drupal/Core/Extension/ProfileHandlerInterface.php --- b/core/lib/Drupal/Core/Extension/ProfileHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ProfileHandlerInterface.php @@ -59,5 +59,5 @@ * */ - static function getProfileBaseName($info); + static public function getProfileBaseName($info); } only in patch2: unchanged: --- /dev/null +++ b/core/profiles/testing_inherited/testing_inherited.info.yml @@ -0,0 +1,14 @@ +name: Testing Inherited +type: profile +description: 'Profile for testing base profile inheritance.' +version: VERSION +core: 8.x +hidden: true + +base profile: + name: minimal + excluded_dependencies: + - dblog + +dependencies: + - config only in patch2: unchanged: --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Extension/ProfileHandlerTest.php @@ -0,0 +1,71 @@ +container->get('profile_handler'); + $info = $profile_handler->getProfileInfo('testing_inherited'); + $this->assertNotEmpty($info); + $this->assertEquals(ProfileHandler::getProfileBaseName($info), 'minimal'); + $this->assertEquals($info['name'], 'Testing Inherited'); + $this->assertTrue(in_array('config', $info['dependencies'], 'config should be found in dependencies')); + $this->assertFalse(in_array('dblog', $info['dependencies'], 'dblog should not be found in dependencies')); + $this->assertTrue($info['hidden'], 'Profiles should be hidden'); + $this->assertNotEmpty($info['profile_list']); + $profile_list = $info['profile_list']; + // Testing order of profile list. + $this->assertEquals($profile_list, array('minimal' => 'minimal', 'testing_inherited' => 'testing_inherited')); + $this->assertEquals($info['distribution']['name'], 'Drupal', 'Check default distribution name'); + } + + /** + * Tests getting profile dependency list. + * + * @covers ::getProfiles + */ + public function testGetProfiles() { + $profile_handler = $this->container->get('profile_handler'); + $profiles = $profile_handler->getProfiles('testing_inherited'); + $this->assertCount(2, $profiles); + + $first_profile = current($profiles); + $this->assertEquals(get_class($first_profile), 'Drupal\Core\Extension\Extension'); + $this->assertEquals($first_profile->getName(), 'minimal'); + $this->assertEquals($first_profile->weight, 1000); + $this->assertObjectHasAttribute('origin', $first_profile); + + $second_profile = next($profiles); + $this->assertEquals(get_class($second_profile), 'Drupal\Core\Extension\Extension'); + $this->assertEquals($second_profile->getName(), 'testing_inherited'); + $this->assertEquals($second_profile->weight, 1001); + $this->assertObjectHasAttribute('origin', $second_profile); + } + +}