|
@@ -3,6 +3,7 @@ declare(strict_types = 1);
|
|
|
|
|
|
namespace Fgm\Drupal\Composer;
|
|
|
|
|
|
+use Drupal\Component\Utility\NestedArray;
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
use Symfony\Component\Console\Input\InputDefinition;
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
@@ -56,16 +57,10 @@ EOT
|
|
|
*/
|
|
|
public function execute(InputInterface $input, OutputInterface $output)
|
|
|
{
|
|
|
- $file = $input->getArgument(static::ARG_FILE);
|
|
|
- $conf = $this->getBuilderConfig();
|
|
|
- $templateName = $conf['templates'][$file] ?? '';
|
|
|
- if (empty($templateName)) {
|
|
|
- $output->writeln(sprintf(
|
|
|
- 'Could not build file %s: no such template in composer.json extra section',
|
|
|
- $file
|
|
|
- ));
|
|
|
- return 1;
|
|
|
- }
|
|
|
+ [$templateName, $err] = $this->validateTemplateName($input, $output);
|
|
|
+ if ($err) {
|
|
|
+ return 1;
|
|
|
+ };
|
|
|
|
|
|
$settingsPath = $this->getSettingsPath();
|
|
|
$templatePath = "${settingsPath}/${templateName}";
|
|
@@ -102,11 +97,17 @@ EOT
|
|
|
$wrapper = $twig->load($templateName);
|
|
|
foreach ($params['sites'] as $name => $siteParams) {
|
|
|
foreach (['build', 'run'] as $stage) {
|
|
|
+ $stageSettings = NestedArray::mergeDeepArray([
|
|
|
+ $siteParams['settings']['both'] ?? [],
|
|
|
+ $siteParams['settings'][$stage] ?? []
|
|
|
+ ], true);
|
|
|
+ $stageParams = $siteParams;
|
|
|
+ $stageParams['settings'] = $stageSettings;
|
|
|
$context = [
|
|
|
'instance' => $params['instance'],
|
|
|
'name' => $name,
|
|
|
'stage' => $stage,
|
|
|
- 'site' => $siteParams,
|
|
|
+ 'site' => $stageParams,
|
|
|
];
|
|
|
$error = $this->render($wrapper, $context, $output);
|
|
|
if ($error) {
|
|
@@ -140,4 +141,26 @@ EOT
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param \Symfony\Component\Console\Input\InputInterface $input
|
|
|
+ * @param \Symfony\Component\Console\Output\OutputInterface $output
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * - string Template name
|
|
|
+ * - int Error
|
|
|
+ */
|
|
|
+ protected function validateTemplateName(InputInterface $input, OutputInterface $output): array {
|
|
|
+ $file = $input->getArgument(static::ARG_FILE);
|
|
|
+ $conf = $this->getBuilderConfig();
|
|
|
+ $templateName = $conf['templates'][$file] ?? '';
|
|
|
+ if (empty($templateName)) {
|
|
|
+ $output->writeln(sprintf(
|
|
|
+ 'Could not build file %s: no such template in composer.json extra section',
|
|
|
+ $file
|
|
|
+ ));
|
|
|
+ return ["", 1];
|
|
|
+ }
|
|
|
+ return [$templateName, 0];
|
|
|
+ }
|
|
|
}
|