test Drupal site working on Koality Theme Builder
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.6 KiB

4 years ago
  1. <?php
  2. namespace Drupal\koality_theme\Generator;
  3. use Drupal\Console\Core\Generator\Generator;
  4. use Drupal\Console\Extension\Manager;
  5. use Drupal\Console\Generator\AuthenticationProviderGenerator;
  6. use Drupal\Component\Serialization\Yaml;
  7. /**
  8. * Class KoalityThemeGenerator.
  9. *
  10. * @package Drupal\Console\Generator
  11. */
  12. class KoalityThemeGenerator extends Generator {
  13. /**
  14. * @var Manager
  15. */
  16. protected $extensionManager;
  17. /**
  18. * AuthenticationProviderGenerator constructor.
  19. *
  20. * @param Manager $extensionManager
  21. */
  22. public function __construct(
  23. Manager $extensionManager
  24. ) {
  25. $this->extensionManager = $extensionManager;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function generate(array $parameters) {
  31. $dir = $parameters['dir'];
  32. $breakpoints = $parameters['breakpoints'];
  33. $libraries = $parameters['libraries'];
  34. $machine_name = $parameters['machine_name'];
  35. $parameters['type'] = 'theme';
  36. $dir = ($dir == '/' ? '' : $dir) . '/' . $machine_name;
  37. if (file_exists($dir)) {
  38. if (!is_dir($dir)) {
  39. throw new \RuntimeException(
  40. sprintf(
  41. 'Unable to generate the bundle as the target directory "%s" exists but is a file.',
  42. realpath($dir)
  43. )
  44. );
  45. }
  46. $files = scandir($dir);
  47. if ($files != ['.', '..']) {
  48. throw new \RuntimeException(
  49. sprintf(
  50. 'Unable to generate the bundle as the target directory "%s" is not empty.',
  51. realpath($dir)
  52. )
  53. );
  54. }
  55. if (!is_writable($dir)) {
  56. throw new \RuntimeException(
  57. sprintf(
  58. 'Unable to generate the bundle as the target directory "%s" is not writable.',
  59. realpath($dir)
  60. )
  61. );
  62. }
  63. }
  64. if ($parameters['base_theme_regions'] && $parameters['base_theme']) {
  65. $defaultRegions = Yaml::decode(file_get_contents($parameters['base_theme_path']));
  66. $parameters['base_theme_regions'] = $defaultRegions['regions'];
  67. $parameters['base_theme_regions_hidden'] = $defaultRegions['regions_hidden'];
  68. }
  69. $themePath = $dir . '/' . $machine_name;
  70. $this->renderFile(
  71. 'theme/info.yml.twig',
  72. $themePath . '.info.yml',
  73. $parameters
  74. );
  75. $this->renderFile(
  76. 'theme/theme.twig',
  77. $themePath . '.theme',
  78. $parameters
  79. );
  80. $this->renderFile(
  81. 'theme/libraries.yml.twig',
  82. $themePath . '.libraries.yml',
  83. $parameters
  84. );
  85. if ($breakpoints) {
  86. $this->renderFile(
  87. 'theme/breakpoints.yml.twig',
  88. $themePath . '.breakpoints.yml',
  89. $parameters
  90. );
  91. }
  92. }
  93. }