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.

131 lines
3.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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\Component\Serialization\Yaml;
  6. use Drupalfinder\DrupalFinder;
  7. /**
  8. * Class KoalityThemeGenerator.
  9. */
  10. class KoalityThemeGenerator extends Generator {
  11. /**
  12. * @var Manager
  13. */
  14. protected $extensionManager;
  15. /**
  16. * AuthenticationProviderGenerator constructor.
  17. *
  18. * @param Manager $extensionManager
  19. */
  20. public function __construct(
  21. Manager $extensionManager
  22. ) {
  23. $this->extensionManager = $extensionManager;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function generate(array $parameters) {
  29. $dir = $parameters['dir'];
  30. $breakpoints = $parameters['breakpoints'];
  31. $machine_name = $parameters['machine_name'];
  32. $parameters['type'] = 'theme';
  33. $dir = ($dir == '/' ? '' : $dir) . '/' . $machine_name;
  34. if (file_exists($dir)) {
  35. if (!is_dir($dir)) {
  36. throw new \RuntimeException(
  37. sprintf(
  38. 'Unable to generate the bundle as the target directory "%s" exists but is a file.',
  39. realpath($dir)
  40. )
  41. );
  42. }
  43. $files = scandir($dir);
  44. if ($files != ['.', '..']) {
  45. throw new \RuntimeException(
  46. sprintf(
  47. 'Unable to generate the bundle as the target directory "%s" is not empty.',
  48. realpath($dir)
  49. )
  50. );
  51. }
  52. if (!is_writable($dir)) {
  53. throw new \RuntimeException(
  54. sprintf(
  55. 'Unable to generate the bundle as the target directory "%s" is not writable.',
  56. realpath($dir)
  57. )
  58. );
  59. }
  60. }
  61. if ($parameters['base_theme_regions'] && $parameters['base_theme']) {
  62. $defaultRegions = Yaml::decode(file_get_contents($parameters['base_theme_path']));
  63. $parameters['base_theme_regions'] = $defaultRegions['regions'];
  64. $parameters['base_theme_regions_hidden'] = $defaultRegions['regions_hidden'];
  65. }
  66. $themePath = $dir . '/';
  67. // $drupalFinder = new DrupalFinder();
  68. // $drupalFinder->locateRoot();
  69. $module_template_dir = drupal_get_path('module', 'koality_theme') . '/templates/';
  70. $this->addSkeletonDir('/var/www/docroot/' . $module_template_dir);
  71. $test = '';
  72. $this->renderFile(
  73. 'theme/koality-info.yml.twig',
  74. $themePath . $machine_name . '.info.yml',
  75. $parameters
  76. );
  77. $this->renderFile(
  78. 'theme/koality-theme.twig',
  79. $themePath . $machine_name . '.theme',
  80. $parameters
  81. );
  82. $this->renderFile(
  83. 'theme/koality-libraries.yml.twig',
  84. $themePath . $machine_name . '.libraries.yml',
  85. $parameters
  86. );
  87. // scaffold directories
  88. $this->renderFile(
  89. 'theme/gitkeep.twig',
  90. $themePath . 'src/components/.gitkeep'
  91. );
  92. $this->renderFile(
  93. 'theme/gitkeep.twig',
  94. $themePath . 'src/global/.gitkeep'
  95. );
  96. $this->renderFile(
  97. 'theme/gitkeep.twig',
  98. $themePath . 'src/global/base/.gitkeep'
  99. );
  100. $this->renderFile(
  101. 'theme/gitkeep.twig',
  102. $themePath . 'src/global/common/.gitkeep'
  103. );
  104. $this->renderFile(
  105. 'theme/gitkeep.twig',
  106. $themePath . 'src/global/utils.gitkeep'
  107. );
  108. if ($breakpoints) {
  109. $this->renderFile(
  110. 'theme/koality-breakpoints.yml.twig',
  111. $themePath . $machine_name . '.breakpoints.yml',
  112. $parameters
  113. );
  114. }
  115. }
  116. }