Skip to content

Commit 3bcce31

Browse files
hjuarez20enzolutions
authored andcommitted
[generate:theme] Add --base-theme-regions option (#4111)
* [generate:theme] Add --base-theme-regios option * [generate:theme] Add validation to get default regions
1 parent 22f114d commit 3bcce31

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/Command/Generate/ThemeCommand.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ protected function configure()
159159
InputOption::VALUE_OPTIONAL,
160160
$this->trans('commands.generate.theme.options.base-theme')
161161
)
162+
->addOption(
163+
'base-theme-regions',
164+
null,
165+
InputOption::VALUE_NONE,
166+
$this->trans('commands.generate.theme.options.base-theme-regions')
167+
)
162168
->addOption(
163169
'regions',
164170
null,
@@ -204,6 +210,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
204210
$core = $input->getOption('core');
205211
$package = $input->getOption('package');
206212
$base_theme = $input->getOption('base-theme');
213+
$base_theme_regions = $input->getOption('base-theme-regions');
207214
$global_library = $input->getOption('global-library');
208215
$libraries = $input->getOption('libraries');
209216
$regions = $input->getOption('regions');
@@ -217,6 +224,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
217224
$breakpoints = $this->explodeInlineArray($breakpoints);
218225
}
219226

227+
$base_theme_path = $this->extensionManager->getTheme($base_theme);
228+
220229
$this->generator->generate([
221230
'theme' => $theme,
222231
'machine_name' => $machine_name,
@@ -225,6 +234,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
225234
'description' => $description,
226235
'package' => $package,
227236
'base_theme' => $base_theme,
237+
'base_theme_path' => is_null($base_theme_path) ? false : $base_theme_path->getRealPath(),
238+
'base_theme_regions' => $base_theme_regions,
228239
'global_library' => $global_library,
229240
'libraries' => $libraries,
230241
'regions' => $regions,
@@ -249,12 +260,11 @@ protected function interact(InputInterface $input, OutputInterface $output)
249260
}
250261

251262
if (!$theme) {
252-
$validators = $this->validator;
253263
$theme = $this->getIo()->ask(
254264
$this->trans('commands.generate.theme.questions.theme'),
255265
'',
256-
function ($theme) use ($validators) {
257-
return $validators->validateModuleName($theme);
266+
function ($theme) {
267+
return $this->validator->validateModuleName($theme);
258268
}
259269
);
260270
$input->setOption('theme', $theme);
@@ -272,8 +282,8 @@ function ($theme) use ($validators) {
272282
$machine_name = $this->getIo()->ask(
273283
$this->trans('commands.generate.theme.questions.machine-name'),
274284
$this->stringConverter->createMachineName($theme),
275-
function ($machine_name) use ($validators) {
276-
return $validators->validateMachineName($machine_name);
285+
function ($machine_name) {
286+
return $this->validator->validateMachineName($machine_name);
277287
}
278288
);
279289
$input->setOption('machine-name', $machine_name);

src/Generator/ThemeGenerator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Drupal\Console\Core\Generator\Generator;
1111
use Drupal\Console\Extension\Manager;
12+
use Drupal\Component\Serialization\Yaml;
1213

1314
/**
1415
*
@@ -71,6 +72,12 @@ public function generate(array $parameters)
7172
}
7273
}
7374

75+
if($parameters['base_theme_regions'] && $parameters['base_theme']) {
76+
$defaultRegions = Yaml::decode(file_get_contents($parameters['base_theme_path']));
77+
$parameters['base_theme_regions'] = $defaultRegions['regions'];
78+
$parameters['base_theme_regions_hidden'] = $defaultRegions['regions_hidden'];
79+
}
80+
7481
$themePath = $dir . '/' . $machine_name;
7582

7683
$this->renderFile(

templates/theme/info.yml.twig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@ base theme: {{ base_theme }}
1414
{% if base_theme == 'classy' %}
1515
#Using Classy as a base theme https://www.drupal.org/theme-guide/8/classy
1616
{% endif %}
17+
{% if regions or base_theme_regions is iterable %}
1718

18-
{% if regions %}
1919
regions:
20+
{% if base_theme_regions is iterable %}
21+
{% for key, default_regions in base_theme_regions %}
22+
{{ key }}: {{ default_regions }}
23+
{% endfor %}
24+
{% endif %}
2025
{% for region in regions %}
2126
{{ region.region_machine_name }}: {{ region.region_name }}
2227
{% endfor %}
2328
{% endif %}
29+
{% if base_theme_regions_hidden is defined and base_theme_regions_hidden is not null %}
30+
31+
regions_hidden:
32+
{% for default_regions_hidden in base_theme_regions_hidden %}
33+
- {{ default_regions_hidden }}
34+
{% endfor %}
35+
{% endif %}

0 commit comments

Comments
 (0)