Skip to content
Snippets Groups Projects
Commit aabf5955 authored by Adam G-H's avatar Adam G-H Committed by Chris Wells
Browse files

Issue #3504781: Profile should not be shown in drupal_core plugin

parent 22f457e3
No related branches found
No related tags found
1 merge request!708Refactor for clarity
Pipeline #418248 passed
......@@ -26,50 +26,14 @@ use Symfony\Component\HttpFoundation\RequestStack;
*/
final class DrupalCore extends ProjectBrowserSourceBase {
/**
* All core modules are covered under security policy.
*
* @var string
*/
const COVERED = 'covered';
/**
* All core modules are "Active" modules.
*
* @var string
*/
const ACTIVE = 'active';
/**
* All core modules are "Maintained" modules.
*
* @var string
*/
const MAINTAINED = 'maintained';
/**
* Constructor for Drupal Core plugin.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request from the browser.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBin
* The cache back end interface.
* @param \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList
* The list of available modules.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
private readonly RequestStack $requestStack,
private readonly CacheBackendInterface $cacheBin,
private readonly ModuleExtensionList $moduleExtensionList,
private readonly ModuleExtensionList $moduleList,
private readonly string|false|null $installProfile,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
......@@ -78,6 +42,9 @@ final class DrupalCore extends ProjectBrowserSourceBase {
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
$install_profile = $container->getParameter('install_profile');
assert(is_string($install_profile) || $install_profile === FALSE || is_null($install_profile));
return new static(
$configuration,
$plugin_id,
......@@ -85,6 +52,7 @@ final class DrupalCore extends ProjectBrowserSourceBase {
$container->get(RequestStack::class),
$container->get('cache.project_browser'),
$container->get(ModuleExtensionList::class),
$install_profile,
);
}
......@@ -94,13 +62,24 @@ final class DrupalCore extends ProjectBrowserSourceBase {
* @return \Drupal\Core\Extension\Extension[]
* The array containing core modules, keyed by module machine name.
*/
protected function getCoreModules() {
$projects = array_filter($this->moduleExtensionList->reset()->getList(), fn(Extension $project): bool => $project->origin === 'core');
$include_tests = Settings::get('extension_discovery_scan_tests') || drupal_valid_test_ua();
if (!$include_tests) {
$projects = array_filter($projects, fn(Extension $project): bool => empty($project->info['hidden']) && $project->info['package'] !== 'Testing');
protected function getCoreModules(): array {
$modules = array_filter(
$this->moduleList->reset()->getList(),
fn (Extension $module): bool => $module->origin === 'core',
);
// Don't include the current install profile, if there is one.
if ($this->installProfile) {
unset($modules[$this->installProfile]);
}
return $projects;
// If we're including test modules, no further filtering is needed.
if (Settings::get('extension_discovery_scan_tests') || drupal_valid_test_ua()) {
return $modules;
}
// Only return non-hidden modules that aren't in the `Testing` package.
return array_filter(
$modules,
fn (Extension $module): bool => empty($module->info['hidden']) && $module->info['package'] !== 'Testing',
);
}
/**
......
......@@ -32,7 +32,7 @@ class EnabledSourceHandlerTest extends BrowserTestBase {
parent::setUp();
$this->config('project_browser.admin_settings')
->set('enabled_sources', ['project_browser_test_mock'])
->set('enabled_sources', ['project_browser_test_mock', 'drupal_core'])
->save(TRUE);
}
......@@ -129,4 +129,14 @@ class EnabledSourceHandlerTest extends BrowserTestBase {
return $status->isInitialized($project) && $commands->isInitialized($project);
}
/**
* Tests that the install profile is ignored by the drupal_core source.
*/
public function testProfileNotListedByCoreSource(): void {
$projects = $this->container->get(EnabledSourceHandler::class)->getProjects('drupal_core');
$this->assertNotEmpty($projects);
// Assert that the current install profile is not returned by the source.
$this->assertNotContains($this->profile, array_column(reset($projects)->list, 'machineName'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment