Loading core/lib/Drupal/Core/Command/GenerateTheme.php +17 −3 Original line number Diff line number Diff line Loading @@ -2,11 +2,13 @@ namespace Drupal\Core\Command; use Composer\Autoload\ClassLoader; 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 Drupal\Core\Theme\StarterKitInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; Loading Loading @@ -124,9 +126,6 @@ protected function execute(InputInterface $input, OutputInterface $output) { $info = Yaml::decode(file_get_contents($info_file)); $info['name'] = $input->getOption('name') ?: $destination_theme; // Unhide hidden themes. unset($info['hidden']); $info['core_version_requirement'] = '^' . $this->getVersion(); if ($description = $input->getOption('description')) { Loading Loading @@ -198,6 +197,21 @@ protected function execute(InputInterface $input, OutputInterface $output) { } } $loader = new ClassLoader(); $loader->addPsr4("Drupal\\$source_theme_name\\", "$source/src"); $loader->register(); $generator_classname = "Drupal\\$source_theme_name\\StarterKit"; if (class_exists($generator_classname)) { if (is_a($generator_classname, StarterKitInterface::class, TRUE)) { $generator_classname::postProcess($tmp_dir, $destination_theme, $info['name']); } else { $io->getErrorStyle()->error("The $generator_classname does not implement \Drupal\Core\Theme\StarterKitInterface and cannot perform post-processing."); return 1; } } if (!rename($tmp_dir, $destination)) { $io->getErrorStyle()->error("The theme could not be moved to the destination: $destination."); return 1; Loading core/lib/Drupal/Core/Theme/StarterKitInterface.php 0 → 100644 +22 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Theme; /** * Allows starter kits to interact with theme generation. */ interface StarterKitInterface { /** * Performs post-processing of a generated theme. * * @param string $working_dir * The working directory of the template being generated. * @param string $machine_name * The theme's machine name. * @param string $theme_name * The theme's name. */ public static function postProcess(string $working_dir, string $machine_name, string $theme_name): void; } core/tests/Drupal/Tests/Core/Command/GenerateThemeTest.php +4 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Command; use Drupal\BuildTests\QuickStart\QuickStartTestBase; use Drupal\Core\Serialization\Yaml; use Drupal\sqlite\Driver\Database\sqlite\Install\Tasks; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; Loading Loading @@ -53,12 +54,14 @@ public function test() { $process = new Process($install_command, NULL); $process->setTimeout(60); $result = $process->run(); $this->assertEquals('Theme generated successfully to themes/test_custom_theme', trim($process->getOutput())); $this->assertEquals('Theme generated successfully to themes/test_custom_theme', trim($process->getOutput()), $process->getErrorOutput()); $this->assertSame(0, $result); $theme_path_relative = 'themes/test_custom_theme'; $theme_path_absolute = $this->getWorkspaceDirectory() . "/$theme_path_relative"; $this->assertFileExists($theme_path_absolute . '/test_custom_theme.info.yml'); $info = Yaml::decode(file_get_contents($theme_path_absolute . '/test_custom_theme.info.yml')); self::assertArrayNotHasKey('hidden', $info); // Ensure that the generated theme can be installed. $this->installQuickStart('minimal'); Loading core/themes/starterkit_theme/src/StarterKit.php 0 → 100644 +20 −0 Original line number Diff line number Diff line <?php namespace Drupal\starterkit_theme; use Drupal\Component\Serialization\Yaml; use Drupal\Core\Theme\StarterKitInterface; final class StarterKit implements StarterKitInterface { /** * {@inheritdoc} */ public static function postProcess(string $working_dir, string $machine_name, string $theme_name): void { $info_file = "$working_dir/$machine_name.info.yml"; $info = Yaml::decode(file_get_contents($info_file)); unset($info['hidden']); file_put_contents($info_file, Yaml::encode($info)); } } Loading
core/lib/Drupal/Core/Command/GenerateTheme.php +17 −3 Original line number Diff line number Diff line Loading @@ -2,11 +2,13 @@ namespace Drupal\Core\Command; use Composer\Autoload\ClassLoader; 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 Drupal\Core\Theme\StarterKitInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; Loading Loading @@ -124,9 +126,6 @@ protected function execute(InputInterface $input, OutputInterface $output) { $info = Yaml::decode(file_get_contents($info_file)); $info['name'] = $input->getOption('name') ?: $destination_theme; // Unhide hidden themes. unset($info['hidden']); $info['core_version_requirement'] = '^' . $this->getVersion(); if ($description = $input->getOption('description')) { Loading Loading @@ -198,6 +197,21 @@ protected function execute(InputInterface $input, OutputInterface $output) { } } $loader = new ClassLoader(); $loader->addPsr4("Drupal\\$source_theme_name\\", "$source/src"); $loader->register(); $generator_classname = "Drupal\\$source_theme_name\\StarterKit"; if (class_exists($generator_classname)) { if (is_a($generator_classname, StarterKitInterface::class, TRUE)) { $generator_classname::postProcess($tmp_dir, $destination_theme, $info['name']); } else { $io->getErrorStyle()->error("The $generator_classname does not implement \Drupal\Core\Theme\StarterKitInterface and cannot perform post-processing."); return 1; } } if (!rename($tmp_dir, $destination)) { $io->getErrorStyle()->error("The theme could not be moved to the destination: $destination."); return 1; Loading
core/lib/Drupal/Core/Theme/StarterKitInterface.php 0 → 100644 +22 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Theme; /** * Allows starter kits to interact with theme generation. */ interface StarterKitInterface { /** * Performs post-processing of a generated theme. * * @param string $working_dir * The working directory of the template being generated. * @param string $machine_name * The theme's machine name. * @param string $theme_name * The theme's name. */ public static function postProcess(string $working_dir, string $machine_name, string $theme_name): void; }
core/tests/Drupal/Tests/Core/Command/GenerateThemeTest.php +4 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Command; use Drupal\BuildTests\QuickStart\QuickStartTestBase; use Drupal\Core\Serialization\Yaml; use Drupal\sqlite\Driver\Database\sqlite\Install\Tasks; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; Loading Loading @@ -53,12 +54,14 @@ public function test() { $process = new Process($install_command, NULL); $process->setTimeout(60); $result = $process->run(); $this->assertEquals('Theme generated successfully to themes/test_custom_theme', trim($process->getOutput())); $this->assertEquals('Theme generated successfully to themes/test_custom_theme', trim($process->getOutput()), $process->getErrorOutput()); $this->assertSame(0, $result); $theme_path_relative = 'themes/test_custom_theme'; $theme_path_absolute = $this->getWorkspaceDirectory() . "/$theme_path_relative"; $this->assertFileExists($theme_path_absolute . '/test_custom_theme.info.yml'); $info = Yaml::decode(file_get_contents($theme_path_absolute . '/test_custom_theme.info.yml')); self::assertArrayNotHasKey('hidden', $info); // Ensure that the generated theme can be installed. $this->installQuickStart('minimal'); Loading
core/themes/starterkit_theme/src/StarterKit.php 0 → 100644 +20 −0 Original line number Diff line number Diff line <?php namespace Drupal\starterkit_theme; use Drupal\Component\Serialization\Yaml; use Drupal\Core\Theme\StarterKitInterface; final class StarterKit implements StarterKitInterface { /** * {@inheritdoc} */ public static function postProcess(string $working_dir, string $machine_name, string $theme_name): void { $info_file = "$working_dir/$machine_name.info.yml"; $info = Yaml::decode(file_get_contents($info_file)); unset($info['hidden']); file_put_contents($info_file, Yaml::encode($info)); } }