Loading core/lib/Drupal/Core/Command/GenerateTheme.php +27 −3 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Extension\InfoParser; use Drupal\Core\File\FileSystem; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; Loading Loading @@ -45,7 +46,9 @@ protected function configure() { ->addOption('name', NULL, InputOption::VALUE_OPTIONAL, 'A name for the theme.') ->addOption('description', NULL, InputOption::VALUE_OPTIONAL, 'A description of your theme.') ->addOption('path', NULL, InputOption::VALUE_OPTIONAL, 'The path where your theme will be created. Defaults to: themes') ->addUsage('custom_theme --name "Custom Theme" --description "Custom theme generated from a starterkit theme" --path themes'); ->addOption('starterkit', NULL, InputOption::VALUE_OPTIONAL, 'The theme to use as the starterkit', 'starterkit_theme') ->addUsage('custom_theme --name "Custom Theme" --description "Custom theme generated from a starterkit theme" --path themes') ->addUsage('custom_theme --name "Custom Theme" --starterkit mystarterkit'); } /** Loading @@ -68,11 +71,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int } // Source directory for the theme. $source_theme_name = 'starterkit_theme'; $source_theme_name = $input->getOption('starterkit'); if (!$source_theme = $this->getThemeInfo($source_theme_name)) { $io->getErrorStyle()->error("Theme source theme $source_theme_name cannot be found."); return 1; } if (!$this->isStarterkitTheme($source_theme)) { $io->getErrorStyle()->error("Theme source theme $source_theme_name is not a valid starter kit."); return 1; } $source = $source_theme->getPath(); if (!is_dir($source)) { Loading Loading @@ -274,6 +283,21 @@ private function getThemeInfo(string $theme): ? Extension { return $themes[$theme]; } /** * Checks if the theme is a starterkit theme. * * @param \Drupal\Core\Extension\Extension $theme * The theme extension. * * @return bool */ private function isStarterkitTheme(Extension $theme): bool { $info_parser = new InfoParser($this->root); $info = $info_parser->parse($theme->getPathname()); return $info['starterkit'] ?? FALSE === TRUE; } /** * Gets the current Drupal major version. * Loading core/misc/cspell/dictionary.txt +1 −0 Original line number Diff line number Diff line Loading @@ -856,6 +856,7 @@ mymodule mysite mysqladmin mysqldump mystarterkit myverylongurl myverylongurlexample műveletek Loading core/tests/Drupal/Tests/Core/Command/GenerateThemeTest.php +63 −4 Original line number Diff line number Diff line Loading @@ -27,6 +27,9 @@ class GenerateThemeTest extends QuickStartTestBase { * {@inheritdoc} */ protected function setUp(): void { if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) { $this->markTestSkipped(); } parent::setUp(); $php_executable_finder = new PhpExecutableFinder(); $this->php = $php_executable_finder->find(); Loading @@ -39,10 +42,6 @@ protected function setUp(): void { * Tests the generate-theme command. */ public function test() { if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) { $this->markTestSkipped(); } $install_command = [ $this->php, 'core/scripts/drupal', Loading Loading @@ -81,4 +80,64 @@ public function test() { $this->assertFileDoesNotExist($theme_path_absolute . '/test_custom_theme.theme'); } /** * Tests themes that do not exist return an error. */ public function testThemeDoesNotExist(): void { $install_command = [ $this->php, 'core/scripts/drupal', 'generate-theme', 'test_custom_theme', '--name="Test custom starterkit theme"', '--description="Custom theme generated from a starterkit theme"', '--starterkit', 'foobarbaz', ]; $process = new Process($install_command, NULL); $process->setTimeout(60); $result = $process->run(); $this->assertStringContainsString('Theme source theme foobarbaz cannot be found.', trim($process->getErrorOutput())); $this->assertSame(1, $result); } /** * Tests that only themes with `starterkit` flag can be used. */ public function testStarterKitFlag(): void { // Explicitly not a starter theme. $install_command = [ $this->php, 'core/scripts/drupal', 'generate-theme', 'test_custom_theme', '--name="Test custom starterkit theme"', '--description="Custom theme generated from a starterkit theme"', '--starterkit', 'stark', ]; $process = new Process($install_command, NULL); $process->setTimeout(60); $result = $process->run(); $this->assertStringContainsString('Theme source theme stark is not a valid starter kit.', trim($process->getErrorOutput())); $this->assertSame(1, $result); // Has not defined `starterkit`. $install_command = [ $this->php, 'core/scripts/drupal', 'generate-theme', 'test_custom_theme', '--name="Test custom starterkit theme"', '--description="Custom theme generated from a starterkit theme"', '--starterkit', 'bartik', ]; $process = new Process($install_command, NULL); $process->setTimeout(60); $result = $process->run(); $this->assertStringContainsString('Theme source theme bartik is not a valid starter kit.', trim($process->getErrorOutput())); $this->assertSame(1, $result); } } core/themes/stark/stark.info.yml +1 −0 Original line number Diff line number Diff line Loading @@ -4,3 +4,4 @@ description: 'An intentionally plain theme with no styling to demonstrate defaul package: Core version: VERSION base theme: false starterkit: false core/themes/starterkit_theme/starterkit_theme.info.yml +1 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ name: starterkit_theme type: theme 'base theme': stable9 hidden: true starterkit: true libraries: - starterkit_theme/base - starterkit_theme/messages Loading Loading
core/lib/Drupal/Core/Command/GenerateTheme.php +27 −3 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Extension\InfoParser; use Drupal\Core\File\FileSystem; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; Loading Loading @@ -45,7 +46,9 @@ protected function configure() { ->addOption('name', NULL, InputOption::VALUE_OPTIONAL, 'A name for the theme.') ->addOption('description', NULL, InputOption::VALUE_OPTIONAL, 'A description of your theme.') ->addOption('path', NULL, InputOption::VALUE_OPTIONAL, 'The path where your theme will be created. Defaults to: themes') ->addUsage('custom_theme --name "Custom Theme" --description "Custom theme generated from a starterkit theme" --path themes'); ->addOption('starterkit', NULL, InputOption::VALUE_OPTIONAL, 'The theme to use as the starterkit', 'starterkit_theme') ->addUsage('custom_theme --name "Custom Theme" --description "Custom theme generated from a starterkit theme" --path themes') ->addUsage('custom_theme --name "Custom Theme" --starterkit mystarterkit'); } /** Loading @@ -68,11 +71,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int } // Source directory for the theme. $source_theme_name = 'starterkit_theme'; $source_theme_name = $input->getOption('starterkit'); if (!$source_theme = $this->getThemeInfo($source_theme_name)) { $io->getErrorStyle()->error("Theme source theme $source_theme_name cannot be found."); return 1; } if (!$this->isStarterkitTheme($source_theme)) { $io->getErrorStyle()->error("Theme source theme $source_theme_name is not a valid starter kit."); return 1; } $source = $source_theme->getPath(); if (!is_dir($source)) { Loading Loading @@ -274,6 +283,21 @@ private function getThemeInfo(string $theme): ? Extension { return $themes[$theme]; } /** * Checks if the theme is a starterkit theme. * * @param \Drupal\Core\Extension\Extension $theme * The theme extension. * * @return bool */ private function isStarterkitTheme(Extension $theme): bool { $info_parser = new InfoParser($this->root); $info = $info_parser->parse($theme->getPathname()); return $info['starterkit'] ?? FALSE === TRUE; } /** * Gets the current Drupal major version. * Loading
core/misc/cspell/dictionary.txt +1 −0 Original line number Diff line number Diff line Loading @@ -856,6 +856,7 @@ mymodule mysite mysqladmin mysqldump mystarterkit myverylongurl myverylongurlexample műveletek Loading
core/tests/Drupal/Tests/Core/Command/GenerateThemeTest.php +63 −4 Original line number Diff line number Diff line Loading @@ -27,6 +27,9 @@ class GenerateThemeTest extends QuickStartTestBase { * {@inheritdoc} */ protected function setUp(): void { if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) { $this->markTestSkipped(); } parent::setUp(); $php_executable_finder = new PhpExecutableFinder(); $this->php = $php_executable_finder->find(); Loading @@ -39,10 +42,6 @@ protected function setUp(): void { * Tests the generate-theme command. */ public function test() { if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) { $this->markTestSkipped(); } $install_command = [ $this->php, 'core/scripts/drupal', Loading Loading @@ -81,4 +80,64 @@ public function test() { $this->assertFileDoesNotExist($theme_path_absolute . '/test_custom_theme.theme'); } /** * Tests themes that do not exist return an error. */ public function testThemeDoesNotExist(): void { $install_command = [ $this->php, 'core/scripts/drupal', 'generate-theme', 'test_custom_theme', '--name="Test custom starterkit theme"', '--description="Custom theme generated from a starterkit theme"', '--starterkit', 'foobarbaz', ]; $process = new Process($install_command, NULL); $process->setTimeout(60); $result = $process->run(); $this->assertStringContainsString('Theme source theme foobarbaz cannot be found.', trim($process->getErrorOutput())); $this->assertSame(1, $result); } /** * Tests that only themes with `starterkit` flag can be used. */ public function testStarterKitFlag(): void { // Explicitly not a starter theme. $install_command = [ $this->php, 'core/scripts/drupal', 'generate-theme', 'test_custom_theme', '--name="Test custom starterkit theme"', '--description="Custom theme generated from a starterkit theme"', '--starterkit', 'stark', ]; $process = new Process($install_command, NULL); $process->setTimeout(60); $result = $process->run(); $this->assertStringContainsString('Theme source theme stark is not a valid starter kit.', trim($process->getErrorOutput())); $this->assertSame(1, $result); // Has not defined `starterkit`. $install_command = [ $this->php, 'core/scripts/drupal', 'generate-theme', 'test_custom_theme', '--name="Test custom starterkit theme"', '--description="Custom theme generated from a starterkit theme"', '--starterkit', 'bartik', ]; $process = new Process($install_command, NULL); $process->setTimeout(60); $result = $process->run(); $this->assertStringContainsString('Theme source theme bartik is not a valid starter kit.', trim($process->getErrorOutput())); $this->assertSame(1, $result); } }
core/themes/stark/stark.info.yml +1 −0 Original line number Diff line number Diff line Loading @@ -4,3 +4,4 @@ description: 'An intentionally plain theme with no styling to demonstrate defaul package: Core version: VERSION base theme: false starterkit: false
core/themes/starterkit_theme/starterkit_theme.info.yml +1 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ name: starterkit_theme type: theme 'base theme': stable9 hidden: true starterkit: true libraries: - starterkit_theme/base - starterkit_theme/messages Loading