use Drupal\Console\Core\Command\Shared\CommandTrait;
use Drupal\Console\Core\Utils\StringConverter;
use Drupal\Console\Utils\DrupalApi;
-use GuzzleHttp\Client;
-use Drupal\Console\Utils\Site;
-use GuzzleHttp\Exception\ClientException;
class ModuleCommand extends Command
{
use CommandTrait;
/**
- * @var ModuleGenerator
-*/
+ * @var ModuleGenerator
+ */
protected $generator;
/**
- * @var Validator
-*/
+ * @var Validator
+ */
protected $validator;
/**
*/
protected $drupalApi;
- /**
- * @var Client
- */
- protected $httpClient;
-
- /**
- * @var Site
- */
- protected $site;
-
/**
* @var string
*/
* @param $appRoot
* @param StringConverter $stringConverter
* @param DrupalApi $drupalApi
- * @param Client $httpClient
- * @param Site $site
* @param $twigtemplate
*/
public function __construct(
$appRoot,
StringConverter $stringConverter,
DrupalApi $drupalApi,
- Client $httpClient,
- Site $site,
$twigtemplate = null
) {
$this->generator = $generator;
$this->appRoot = $appRoot;
$this->stringConverter = $stringConverter;
$this->drupalApi = $drupalApi;
- $this->httpClient = $httpClient;
- $this->site = $site;
$this->twigtemplate = $twigtemplate;
parent::__construct();
}
->setHelp($this->trans('commands.generate.module.help'))
->addOption(
'module',
- '',
+ null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.module.options.module')
)
->addOption(
'machine-name',
- '',
+ null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.module.options.machine-name')
)
->addOption(
'module-path',
- '',
+ null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.module.options.module-path')
)
->addOption(
'description',
- '',
+ null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.module.options.description')
)
->addOption(
'core',
- '',
+ null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.module.options.core')
)
->addOption(
'package',
- '',
+ null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.module.options.package')
)
->addOption(
'module-file',
- '',
+ null,
InputOption::VALUE_NONE,
$this->trans('commands.generate.module.options.module-file')
)
->addOption(
'features-bundle',
- '',
+ null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.module.options.features-bundle')
)
->addOption(
'composer',
- '',
+ null,
InputOption::VALUE_NONE,
$this->trans('commands.generate.module.options.composer')
)
->addOption(
'dependencies',
- '',
+ null,
InputOption::VALUE_OPTIONAL,
- $this->trans('commands.generate.module.options.dependencies')
+ $this->trans('commands.generate.module.options.dependencies'),
+ ''
)
->addOption(
'test',
- '',
+ null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.module.options.test')
)
->addOption(
'twigtemplate',
- '',
+ null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.module.options.twigtemplate')
);
// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
if (!$this->confirmGeneration($io, $yes)) {
- return;
+ return 1;
}
$module = $this->validator->validateModuleName($input->getOption('module'));
$moduleFile = $input->getOption('module-file');
$featuresBundle = $input->getOption('features-bundle');
$composer = $input->getOption('composer');
+ $dependencies = $this->validator->validateExtensions(
+ $input->getOption('dependencies'),
+ 'module',
+ $io
+ );
$test = $input->getOption('test');
- $twigtemplate = $input->getOption('twigtemplate');
-
- // Modules Dependencies, re-factor and share with other commands
- $dependencies = $this->validator->validateModuleDependencies($input->getOption('dependencies'));
- // Check if all module dependencies are available
- if ($dependencies) {
- $checked_dependencies = $this->checkDependencies($dependencies['success'], $io);
- if (!empty($checked_dependencies['no_modules'])) {
- $io->warning(
- sprintf(
- $this->trans('commands.generate.module.warnings.module-unavailable'),
- implode(', ', $checked_dependencies['no_modules'])
- )
- );
- }
- $dependencies = $dependencies['success'];
- }
+ $twigTemplate = $input->getOption('twigtemplate');
$this->generator->generate(
$module,
$composer,
$dependencies,
$test,
- $twigtemplate
+ $twigTemplate
);
- }
-
- /**
- * @param array $dependencies
- * @return array
- */
- private function checkDependencies(array $dependencies, DrupalStyle $io)
- {
- $this->site->loadLegacyFile('/core/modules/system/system.module');
- $localModules = [];
-
- $modules = system_rebuild_module_data();
- foreach ($modules as $module_id => $module) {
- array_push($localModules, basename($module->subpath));
- }
-
- $checkDependencies = [
- 'local_modules' => [],
- 'drupal_modules' => [],
- 'no_modules' => [],
- ];
-
- foreach ($dependencies as $module) {
- if (in_array($module, $localModules)) {
- $checkDependencies['local_modules'][] = $module;
- } else {
- try {
- $response = $this->httpClient->head('https://www.drupal.org/project/' . $module);
- $header_link = explode(';', $response->getHeader('link'));
- if (empty($header_link[0])) {
- $checkDependencies['no_modules'][] = $module;
- } else {
- $checkDependencies['drupal_modules'][] = $module;
- }
- } catch (ClientException $e) {
- $checkDependencies['no_modules'][] = $module;
- }
- }
- }
- return $checkDependencies;
+ return 0;
}
/**
} catch (\Exception $error) {
$io->error($error->getMessage());
- return;
+ return 1;
}
if (!$module) {