Companion to GitLab issue #3600784 (reported by tobiasb, Drupal 10, drupal-rector dev-main).
Problem
When HookConvertRector converts a theme's hooks to OOP hook classes, it still generates a mytheme.services.yml. Themes don't load service providers (\Drupal\Core\DrupalKernel::discoverServiceProviders() ignores them), so the generated config is non-functional. For themes the src/Hook/<Class>.php (auto-discovered via the #[Hook] attribute + namespace) is enough; no services.yml should be written.
Root cause
.theme files became eligible for conversion in #325 ("Add theme extension"), but __destruct() writes the services.yml for any extension, guarded only against the core path — there's no theme-vs-module distinction:
// src/Rector/Convert/HookConvertRector.php (~lines 236-238)
if (!str_starts_with($this->moduleDir, $this->drupalCorePath)) {
static::writeServicesYml("$this->moduleDir/$this->module.services.yml", "$namespace\\$className");
}
Proposed fix
Track whether the extension being processed is a theme (the .theme extension is already known at HookConvertRector.php:142, or read the info.yml type:), and skip the writeServicesYml() call for themes. Add a theme fixture asserting the hook class is written but no services.yml is produced.
Related: #3481215, #3596308, #2002606.
Companion to GitLab issue #3600784 (reported by tobiasb, Drupal 10, drupal-rector dev-main).
Problem
When
HookConvertRectorconverts a theme's hooks to OOP hook classes, it still generates amytheme.services.yml. Themes don't load service providers (\Drupal\Core\DrupalKernel::discoverServiceProviders()ignores them), so the generated config is non-functional. For themes thesrc/Hook/<Class>.php(auto-discovered via the#[Hook]attribute + namespace) is enough; no services.yml should be written.Root cause
.themefiles became eligible for conversion in #325 ("Add theme extension"), but__destruct()writes the services.yml for any extension, guarded only against the core path — there's no theme-vs-module distinction:Proposed fix
Track whether the extension being processed is a theme (the
.themeextension is already known atHookConvertRector.php:142, or read the info.ymltype:), and skip thewriteServicesYml()call for themes. Add a theme fixture asserting the hook class is written but no services.yml is produced.Related: #3481215, #3596308, #2002606.