use Drupal\Console\Extension\Manager;
use Drupal\Console\Core\Utils\StringConverter;
use Drupal\Console\Utils\Validator;
-use Drupal\Console\Utils\Site;
-use GuzzleHttp\Client;
/**
* Class ProfileCommand
use CommandTrait;
/**
- * @var Manager
-*/
+ * @var Manager
+ */
protected $extensionManager;
/**
- * @var ProfileGenerator
-*/
+ * @var ProfileGenerator
+ */
protected $generator;
/**
protected $stringConverter;
/**
- * @var Validator
-*/
- protected $validator;
-
- /**
- * @var Site
+ * @var Validator
*/
- protected $site;
-
- /**
- * @var Client
- */
- protected $httpClient;
+ protected $validator;
/**
* ProfileCommand constructor.
* @param StringConverter $stringConverter
* @param Validator $validator
* @param $appRoot
- * @param Site $site
- * @param Client $httpClient
*/
public function __construct(
Manager $extensionManager,
ProfileGenerator $generator,
StringConverter $stringConverter,
Validator $validator,
- $appRoot,
- Site $site,
- Client $httpClient
+ $appRoot
) {
$this->extensionManager = $extensionManager;
$this->generator = $generator;
$this->stringConverter = $stringConverter;
$this->validator = $validator;
$this->appRoot = $appRoot;
- $this->site = $site;
- $this->httpClient = $httpClient;
parent::__construct();
}
->setHelp($this->trans('commands.generate.profile.help'))
->addOption(
'profile',
- '',
+ null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.profile.options.profile')
)
->addOption(
'machine-name',
- '',
+ null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.profile.options.machine-name')
)
->addOption(
'description',
- '',
+ null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.profile.options.description')
)
->addOption(
'core',
- '',
+ null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.profile.options.core')
)
->addOption(
'dependencies',
- false,
+ null,
InputOption::VALUE_OPTIONAL,
- $this->trans('commands.generate.profile.options.dependencies')
+ $this->trans('commands.generate.profile.options.dependencies'),
+ ''
+ )
+ ->addOption(
+ 'themes',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ $this->trans('commands.generate.profile.options.themes'),
+ ''
)
->addOption(
'distribution',
- false,
+ null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.profile.options.distribution')
);
$io = new DrupalStyle($input, $output);
if (!$this->confirmGeneration($io)) {
- return;
+ return 1;
}
$profile = $this->validator->validateModuleName($input->getOption('profile'));
$machine_name = $this->validator->validateMachineName($input->getOption('machine-name'));
$description = $input->getOption('description');
$core = $input->getOption('core');
+ $dependencies = $this->validator->validateExtensions($input->getOption('dependencies'), 'module', $io);
+ $themes = $this->validator->validateExtensions($input->getOption('themes'), 'theme', $io);
$distribution = $input->getOption('distribution');
$profile_path = $this->appRoot . '/profiles';
- // Check if all module dependencies are available.
- $dependencies = $this->validator->validateModuleDependencies($input->getOption('dependencies'));
- if ($dependencies) {
- $checked_dependencies = $this->checkDependencies($dependencies['success']);
- if (!empty($checked_dependencies['no_modules'])) {
- $io->info(
- sprintf(
- $this->trans('commands.generate.profile.warnings.module-unavailable'),
- implode(', ', $checked_dependencies['no_modules'])
- )
- );
- }
- $dependencies = $dependencies['success'];
- }
-
$this->generator->generate(
$profile,
$machine_name,
$description,
$core,
$dependencies,
+ $themes,
$distribution
);
}
- /**
- * @param array $dependencies
- * @return array
- */
- private function checkDependencies(array $dependencies)
- {
- $this->site->loadLegacyFile('/core/modules/system/system.module');
- $local_modules = [];
-
- $modules = system_rebuild_module_data();
- foreach ($modules as $module_id => $module) {
- array_push($local_modules, basename($module->subpath));
- }
-
- $checked_dependencies = [
- 'local_modules' => [],
- 'drupal_modules' => [],
- 'no_modules' => [],
- ];
-
- foreach ($dependencies as $module) {
- if (in_array($module, $local_modules)) {
- $checked_dependencies['local_modules'][] = $module;
- } else {
- $response = $this->httpClient->head('https://www.drupal.org/project/' . $module);
- $header_link = explode(';', $response->getHeader('link'));
- if (empty($header_link[0])) {
- $checked_dependencies['no_modules'][] = $module;
- } else {
- $checked_dependencies['drupal_modules'][] = $module;
- }
- }
- }
-
- return $checked_dependencies;
- }
-
/**
* {@inheritdoc}
*/
} catch (\Exception $error) {
$io->error($error->getMessage());
- return;
+ return 1;
}
if (!$profile) {
} catch (\Exception $error) {
$io->error($error->getMessage());
- return;
+ return 1;
}
if (!$machine_name) {