diff --git a/core/lib/Drupal/Core/Command/GenerateTheme.php b/core/lib/Drupal/Core/Command/GenerateTheme.php index bb09d380aed..0cf50fea93a 100644 --- a/core/lib/Drupal/Core/Command/GenerateTheme.php +++ b/core/lib/Drupal/Core/Command/GenerateTheme.php @@ -97,6 +97,13 @@ class GenerateTheme extends Command { $tmp_dir = $this->getUniqueTmpDirPath(); $this->copyRecursive($source, $tmp_dir); + // Readme is specific to Starterkit, so remove it from the generated theme. + $readme_file = "$tmp_dir/README.md"; + if (!file_put_contents($readme_file, "$destination_theme theme, generated from $source_theme_name. Additional information on generating themes can be found in the [Starterkit documentation](https://www.drupal.org/docs/core-modules-and-themes/core-themes/starterkit-theme).")) { + $io->getErrorStyle()->error("The readme could not be rewritten."); + return 1; + } + // Rename files based on the theme machine name. $file_pattern = "/$source_theme_name\.(theme|[^.]+\.yml)/"; if ($files = @scandir($tmp_dir)) { diff --git a/core/tests/Drupal/Tests/Core/Command/GenerateThemeTest.php b/core/tests/Drupal/Tests/Core/Command/GenerateThemeTest.php index 9ebc09bdc8c..5aa980067da 100644 --- a/core/tests/Drupal/Tests/Core/Command/GenerateThemeTest.php +++ b/core/tests/Drupal/Tests/Core/Command/GenerateThemeTest.php @@ -99,6 +99,10 @@ class GenerateThemeTest extends QuickStartTestBase { self::assertArrayHasKey('generator', $info); self::assertEquals('starterkit_theme:9.4.0', $info['generator']); + // Confirm readme is rewritten. + $readme_file = $this->getWorkspaceDirectory() . "/$theme_path_relative/README.md"; + $this->assertSame('test_custom_theme theme, generated from starterkit_theme. Additional information on generating themes can be found in the [Starterkit documentation](https://www.drupal.org/docs/core-modules-and-themes/core-themes/starterkit-theme).', file_get_contents($readme_file)); + // Ensure that the generated theme can be installed. $this->installQuickStart('minimal'); $this->formLogin($this->adminUsername, $this->adminPassword); @@ -121,6 +125,40 @@ class GenerateThemeTest extends QuickStartTestBase { $this->assertFileDoesNotExist($theme_path_absolute . '/test_custom_theme.theme'); } + /** + * Tests generating a theme from another Starterkit enabled theme. + */ + public function testGeneratingFromAnotherTheme() { + // Do not rely on \Drupal::VERSION: change the version to a concrete version + // number, to simulate using a tagged core release. + $starterkit_info_yml = $this->getWorkspaceDirectory() . '/core/themes/starterkit_theme/starterkit_theme.info.yml'; + $info = Yaml::decode(file_get_contents($starterkit_info_yml)); + $info['version'] = '9.4.0'; + file_put_contents($starterkit_info_yml, Yaml::encode($info)); + + $process = $this->generateThemeFromStarterkit(); + $exit_code = $process->run(); + $this->assertSame('Theme generated successfully to themes/test_custom_theme', trim($process->getOutput()), $process->getErrorOutput()); + $this->assertSame(0, $exit_code); + $install_command = [ + $this->php, + 'core/scripts/drupal', + 'generate-theme', + 'generated_from_another_theme', + '--name="Generated from another theme"', + '--description="Custom theme generated from a theme other than starterkit_theme"', + '--starterkit=test_custom_theme', + ]; + $process = new Process($install_command); + $exit_code = $process->run(); + $this->assertSame('Theme generated successfully to themes/generated_from_another_theme', trim($process->getOutput()), $process->getErrorOutput()); + $this->assertSame(0, $exit_code); + + // Confirm readme is rewritten. + $readme_file = $this->getWorkspaceDirectory() . '/themes/generated_from_another_theme/README.md'; + $this->assertSame('generated_from_another_theme theme, generated from test_custom_theme. Additional information on generating themes can be found in the [Starterkit documentation](https://www.drupal.org/docs/core-modules-and-themes/core-themes/starterkit-theme).', file_get_contents($readme_file)); + } + /** * Tests the generate-theme command on a dev snapshot of Drupal core. */ diff --git a/core/themes/starterkit_theme/README.md b/core/themes/starterkit_theme/README.md new file mode 100644 index 00000000000..9a1b58243b8 --- /dev/null +++ b/core/themes/starterkit_theme/README.md @@ -0,0 +1,11 @@ +# Starterkit Theme + +## How to use Starterkit +The Starterkit theme is not directly used by Drupal, nor is it used as a base theme. +**Starterkit is for generating new themes** that include +reasonably un-opinionated templates and styles that eliminate much of the +the initial work required to create a theme. + +Starterkit is the recommended approach for creating new themes. For more +information, consult the +[Starterkit documentation on Drupal.org](https://www.drupal.org/docs/core-modules-and-themes/core-themes/starterkit-theme).