Skip to content
This repository was archived by the owner on Nov 2, 2024. It is now read-only.

Commit 22aee09

Browse files
committed
Add support for Drupal 7
1 parent 60ef534 commit 22aee09

File tree

1 file changed

+58
-13
lines changed

1 file changed

+58
-13
lines changed

src/DrupalInitCommand.php

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function configure()
3838
new InputOption('license', 'l', InputOption::VALUE_REQUIRED, 'License of package'),
3939
new InputOption('repository', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Add custom repositories, either by URL or using JSON arrays'),
4040
new InputOption('web-dir', 'w', InputOption::VALUE_REQUIRED, 'Specify the docroot (defaults to web)', 'web'),
41+
new InputOption('drupal-7', null, InputOption::VALUE_NONE, 'Use Drupal 7 packagist instead of Drupal 8'),
4142
// new InputOption('extensions', 'm', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Extensions (such as modules or themes) to require with a version constraint, e.g. panels:^4.0'),
4243
// new InputOption('extensions-dev', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Extensions (such as modules or themes) to require for development with a version constraint, e.g. panels:^4.0'),
4344
])
@@ -52,16 +53,39 @@ protected function configure()
5253
// @codingStandardsIgnoreEnd
5354
}
5455

56+
protected function isDrupal7(InputInterface $input)
57+
{
58+
return $input->getOption('drupal-7');
59+
}
60+
5561
protected function getExtraRequires(InputInterface $input)
5662
{
57-
$require = [
58-
'cweagans/composer-patches ^1.6.0',
59-
'hussainweb/drupal-composer-helper ^1.0',
60-
$input->getOption('core'),
61-
'drupal/console ^1.0.1',
62-
'drush/drush ~8.0|^9.0',
63+
$requires = [
64+
'd7' => [
65+
'php >=5.2.5',
66+
'ext-gd *',
67+
'ext-xml *',
68+
'ext-json *',
69+
'ext-openssl *',
70+
'ext-curl *',
71+
'ext-pdo *',
72+
'ext-pdo_mysql *',
73+
'cweagans/composer-patches ^1.6.0',
74+
'hussainweb/drupal-composer-helper ^1.0-beta3',
75+
'drupal-composer/preserve-paths ^0.1',
76+
$input->getOption('core'),
77+
'drupal/composer_autoloader ^1.0',
78+
'drush/drush ~8.0',
79+
],
80+
'd8' => [
81+
'cweagans/composer-patches ^1.6.0',
82+
'hussainweb/drupal-composer-helper ^1.0',
83+
$input->getOption('core'),
84+
'drupal/console ^1.0.1',
85+
'drush/drush ~8.0|^9.0',
86+
],
6387
];
64-
return $require;
88+
return $this->isDrupal7($input) ? $requires['d7'] : $requires['d8'];
6589
}
6690

6791
protected function getExtraRequireDevs(InputInterface $input)
@@ -75,7 +99,7 @@ protected function getExtraRequireDevs(InputInterface $input)
7599
'phpunit/phpunit >=4.8.28 <5',
76100
'symfony/css-selector ~2.8',
77101
];
78-
return $require_dev;
102+
return $this->isDrupal7($input) ? [] : $require_dev;
79103
}
80104

81105
protected function execute(InputInterface $input, OutputInterface $output)
@@ -93,12 +117,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
93117
$status = parent::execute($input, $output);
94118

95119
if (!$status) {
120+
$web_prefix = $input->getOption('web-dir');
121+
96122
// Write extra to composer.json file.
97123
$file = new JsonFile(Factory::getComposerFile());
98124
$options = $file->read();
99125
$options['extra'] = [
100126
'drupal-composer-helper' => [
101-
'web-prefix' => $input->getOption('web-dir'),
127+
'web-prefix' => $web_prefix,
102128
],
103129
'enable-patching' => true,
104130
];
@@ -111,6 +137,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
111137
'optimize-autoloader' => true,
112138
];
113139

140+
if ($this->isDrupal7($input)) {
141+
$options['conflict'] = [
142+
'drupal/core' => '8.*',
143+
];
144+
$options['extra']['drupal-composer-helper']['set-d7-paths'] = true;
145+
$options['extra']['preserve-paths'] = [
146+
$web_prefix . '/sites/all/libraries',
147+
$web_prefix . '/sites/all/modules/custom',
148+
$web_prefix . '/sites/all/modules/features',
149+
$web_prefix . '/sites/all/themes/custom',
150+
$web_prefix . '/sites/all/translations',
151+
$web_prefix . '/sites/default',
152+
];
153+
}
154+
114155
$file->write($options);
115156
}
116157

@@ -131,15 +172,15 @@ private function getRepositories(InputInterface $input)
131172
}
132173
}
133174

134-
// @todo: Implement support for Drupal 7 packagist repos.
175+
$packagist_url = 'https://packages.drupal.org/' . ($this->isDrupal7($input) ? '7' : '8');
135176
$repos[] = RepositoryFactory::createRepo($io, $config, [
136177
'type' => 'composer',
137-
'url' => 'https://packages.drupal.org/8',
178+
'url' => $packagist_url,
138179
]);
139180

140181
// Add our Drupal packagist URL to the repositories so that it appears
141182
// in the composer.json file.
142-
$repositories[] = 'https://packages.drupal.org/8';
183+
$repositories[] = $packagist_url;
143184
$input->setOption('repository', $repositories);
144185

145186
$repos[] = RepositoryFactory::createRepo($io, $config, [
@@ -312,7 +353,11 @@ protected function getCore(InputInterface $input)
312353
{
313354
$io = $this->getIO();
314355

315-
$name_version_pair = $this->normalizeRequirements((array) $input->getOption('core'));
356+
$core = $input->getOption('core');
357+
if ($this->isDrupal7($input) && $core == 'drupal/core') {
358+
$core = 'drupal/drupal';
359+
}
360+
$name_version_pair = $this->normalizeRequirements((array) $core);
316361
$core_package = $name_version_pair[0]['name'];
317362

318363
$core_package = $io->askAndValidate(

0 commit comments

Comments
 (0)