Skip to content
Permalink
Browse files

[generate:theme] Add --base-theme-regions option (#4111)

* [generate:theme] Add --base-theme-regios option

* [generate:theme] Add validation to get default regions
  • Loading branch information...
harold20 authored and enzolutions committed Jul 15, 2019
1 parent 22f114d commit 3bcce31018ea61f6f83f090c598835669f8e7e5a
Showing with 35 additions and 6 deletions.
  1. +15 −5 src/Command/Generate/ThemeCommand.php
  2. +7 −0 src/Generator/ThemeGenerator.php
  3. +13 −1 templates/theme/info.yml.twig
@@ -159,6 +159,12 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.theme.options.base-theme')
)
->addOption(
'base-theme-regions',
null,
InputOption::VALUE_NONE,
$this->trans('commands.generate.theme.options.base-theme-regions')
)
->addOption(
'regions',
null,
@@ -204,6 +210,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$core = $input->getOption('core');
$package = $input->getOption('package');
$base_theme = $input->getOption('base-theme');
$base_theme_regions = $input->getOption('base-theme-regions');
$global_library = $input->getOption('global-library');
$libraries = $input->getOption('libraries');
$regions = $input->getOption('regions');
@@ -217,6 +224,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$breakpoints = $this->explodeInlineArray($breakpoints);
}
$base_theme_path = $this->extensionManager->getTheme($base_theme);
$this->generator->generate([
'theme' => $theme,
'machine_name' => $machine_name,
@@ -225,6 +234,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
'description' => $description,
'package' => $package,
'base_theme' => $base_theme,
'base_theme_path' => is_null($base_theme_path) ? false : $base_theme_path->getRealPath(),
'base_theme_regions' => $base_theme_regions,
'global_library' => $global_library,
'libraries' => $libraries,
'regions' => $regions,
@@ -249,12 +260,11 @@ protected function interact(InputInterface $input, OutputInterface $output)
}
if (!$theme) {
$validators = $this->validator;
$theme = $this->getIo()->ask(
$this->trans('commands.generate.theme.questions.theme'),
'',
function ($theme) use ($validators) {
return $validators->validateModuleName($theme);
function ($theme) {
return $this->validator->validateModuleName($theme);
}
);
$input->setOption('theme', $theme);
@@ -272,8 +282,8 @@ function ($theme) use ($validators) {
$machine_name = $this->getIo()->ask(
$this->trans('commands.generate.theme.questions.machine-name'),
$this->stringConverter->createMachineName($theme),
function ($machine_name) use ($validators) {
return $validators->validateMachineName($machine_name);
function ($machine_name) {
return $this->validator->validateMachineName($machine_name);
}
);
$input->setOption('machine-name', $machine_name);
@@ -9,6 +9,7 @@
use Drupal\Console\Core\Generator\Generator;
use Drupal\Console\Extension\Manager;
use Drupal\Component\Serialization\Yaml;
/**
*
@@ -71,6 +72,12 @@ public function generate(array $parameters)
}
}
if($parameters['base_theme_regions'] && $parameters['base_theme']) {
$defaultRegions = Yaml::decode(file_get_contents($parameters['base_theme_path']));
$parameters['base_theme_regions'] = $defaultRegions['regions'];
$parameters['base_theme_regions_hidden'] = $defaultRegions['regions_hidden'];
}
$themePath = $dir . '/' . $machine_name;
$this->renderFile(
@@ -14,10 +14,22 @@ base theme: {{ base_theme }}
{% if base_theme == 'classy' %}
#Using Classy as a base theme https://www.drupal.org/theme-guide/8/classy
{% endif %}
{% if regions or base_theme_regions is iterable %}

{% if regions %}
regions:
{% if base_theme_regions is iterable %}
{% for key, default_regions in base_theme_regions %}
{{ key }}: {{ default_regions }}
{% endfor %}
{% endif %}
{% for region in regions %}
{{ region.region_machine_name }}: {{ region.region_name }}
{% endfor %}
{% endif %}
{% if base_theme_regions_hidden is defined and base_theme_regions_hidden is not null %}

regions_hidden:
{% for default_regions_hidden in base_theme_regions_hidden %}
- {{ default_regions_hidden }}
{% endfor %}
{% endif %}

0 comments on commit 3bcce31

Please sign in to comment.
You can’t perform that action at this time.