Skip to content

Commit

Permalink
Issue 2178 replace code with module from input (#3653)
Browse files Browse the repository at this point in the history
* Replace code getting module from the input with ModuleTrait method

* Add the validator service for the commands, which receiving module as a parameter
  • Loading branch information
LOBsTerr authored and jmolivas committed Jan 8, 2018
1 parent 6c809c5 commit b586b25
Show file tree
Hide file tree
Showing 39 changed files with 138 additions and 257 deletions.
6 changes: 3 additions & 3 deletions config/services/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ services:
- { name: drupal.command }
console.config_export_content_type:
class: Drupal\Console\Command\Config\ExportContentTypeCommand
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager']
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager', '@console.validator']
tags:
- { name: drupal.command }
console.config_export_single:
class: Drupal\Console\Command\Config\ExportSingleCommand
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager','@language_manager']
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager','@language_manager', '@console.validator']
tags:
- { name: drupal.command }
console.config_export_view:
class: Drupal\Console\Command\Config\ExportViewCommand
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager']
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager', '@console.validator']
tags:
- { name: drupal.command }
console.config_import:
Expand Down
10 changes: 5 additions & 5 deletions config/services/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- { name: drupal.command }
console.generate_modulefile:
class: Drupal\Console\Command\Generate\ModuleFileCommand
arguments: ['@console.extension_manager', '@console.modulefile_generator']
arguments: ['@console.extension_manager', '@console.modulefile_generator', '@console.validator']
tags:
- { name: drupal.command }
console.generate_authentication_provider:
Expand All @@ -26,7 +26,7 @@ services:
- { name: drupal.command }
console.generate_help:
class: Drupal\Console\Command\Generate\HelpCommand
arguments: ['@console.help_generator', '@console.site', '@console.extension_manager', '@console.chain_queue']
arguments: ['@console.help_generator', '@console.site', '@console.extension_manager', '@console.chain_queue', '@console.validator']
tags:
- { name: drupal.command }
console.generate_form:
Expand All @@ -36,12 +36,12 @@ services:
- { name: drupal.command }
console.generate_form_alter:
class: Drupal\Console\Command\Generate\FormAlterCommand
arguments: ['@console.extension_manager', '@console.form_alter_generator', '@console.string_converter', '@module_handler', '@plugin.manager.element_info', '@?profiler', '@app.root', '@console.chain_queue']
arguments: ['@console.extension_manager', '@console.form_alter_generator', '@console.string_converter', '@module_handler', '@plugin.manager.element_info', '@?profiler', '@app.root', '@console.chain_queue', '@console.validator']
tags:
- { name: drupal.command }
console.generate_permissions:
class: Drupal\Console\Command\Generate\PermissionCommand
arguments: ['@console.extension_manager', '@console.string_converter', '@console.permission_generator']
arguments: ['@console.extension_manager', '@console.string_converter', '@console.permission_generator', '@console.validator']
tags:
- { name: drupal.command }
console.generate_event_subscriber:
Expand Down Expand Up @@ -166,7 +166,7 @@ services:
- { name: drupal.command }
console.generate_update:
class: Drupal\Console\Command\Generate\UpdateCommand
arguments: ['@console.extension_manager', '@console.update_generator', '@console.site', '@console.chain_queue']
arguments: ['@console.extension_manager', '@console.update_generator', '@console.site', '@console.chain_queue', '@console.validator']
tags:
- { name: drupal.command }
console.generate_pluginblock:
Expand Down
18 changes: 11 additions & 7 deletions src/Command/Config/ExportContentTypeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Drupal\Console\Command\Config;

use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Utils\Validator;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -42,21 +43,29 @@ class ExportContentTypeCommand extends Command

protected $configExport;

/**
* @var Validator
*/
protected $validator;

/**
* ExportContentTypeCommand constructor.
*
* @param EntityTypeManagerInterface $entityTypeManager
* @param CachedStorage $configStorage
* @param Manager $extensionManager
* @param Validator $validator
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
CachedStorage $configStorage,
Manager $extensionManager
Manager $extensionManager,
Validator $validator
) {
$this->entityTypeManager = $entityTypeManager;
$this->configStorage = $configStorage;
$this->extensionManager = $extensionManager;
$this->validator = $validator;
parent::__construct();
}

Expand Down Expand Up @@ -102,12 +111,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
}
$input->setOption('module', $module);
$this->moduleFromInput($io, $input);

// --content-type argument
$contentType = $input->getArgument('content-type');
Expand Down
19 changes: 12 additions & 7 deletions src/Command/Config/ExportSingleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Utils\Validator;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Config\CachedStorage;
use Drupal\Console\Core\Style\DrupalStyle;
Expand Down Expand Up @@ -57,24 +58,32 @@ class ExportSingleCommand extends Command
*/
protected $languageManager;

/**
* @var Validator
*/
protected $validator;

/**
* ExportSingleCommand constructor.
*
* @param EntityTypeManagerInterface $entityTypeManager
* @param CachedStorage $configStorage
* @param Manager $extensionManager
* @param languageManager $languageManager
* @param Validator $validator
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
CachedStorage $configStorage,
Manager $extensionManager,
LanguageManagerInterface $languageManager
LanguageManagerInterface $languageManager,
Validator $validator
) {
$this->entityTypeManager = $entityTypeManager;
$this->configStorage = $configStorage;
$this->extensionManager = $extensionManager;
$this->languageManager = $languageManager;
$this->validator = $validator;
parent::__construct();
}

Expand Down Expand Up @@ -219,12 +228,8 @@ protected function interact(InputInterface $input, OutputInterface $output)
$input->setOption('name', [$name]);
}

$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
}
$input->setOption('module', $module);
// --module option
$this->moduleFromInput($io, $input);

$module = $input->getOption('module');
if ($module) {
Expand Down
17 changes: 10 additions & 7 deletions src/Command/Config/ExportViewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Utils\Validator;
use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Config\CachedStorage;
Expand Down Expand Up @@ -42,6 +43,11 @@ class ExportViewCommand extends Command
*/
protected $extensionManager;

/**
* @var Validator
*/
protected $validator;

/**
* ExportViewCommand constructor.
*
Expand All @@ -52,11 +58,13 @@ class ExportViewCommand extends Command
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
CachedStorage $configStorage,
Manager $extensionManager
Manager $extensionManager,
Validator $validator
) {
$this->entityTypeManager = $entityTypeManager;
$this->configStorage = $configStorage;
$this->extensionManager = $extensionManager;
$this->validator = $validator;
parent::__construct();
}

Expand Down Expand Up @@ -99,12 +107,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
$input->setOption('module', $module);
}
$this->moduleFromInput($io, $input);

// view-id argument
$viewId = $input->getArgument('view-id');
Expand Down
7 changes: 1 addition & 6 deletions src/Command/Generate/AuthenticationProviderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$stringUtils = $this->stringConverter;

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
$input->setOption('module', $module);
}
$this->moduleFromInput($io, $input);

// --class option
$class = $input->getOption('class');
Expand Down
7 changes: 1 addition & 6 deletions src/Command/Generate/CacheContextCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
$input->setOption('module', $module);
}
$this->moduleFromInput($io, $input);

// --cache_context option
$cache_context = $input->getOption('cache-context');
Expand Down
7 changes: 1 addition & 6 deletions src/Command/Generate/ControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
$input->setOption('module', $module);
}
$this->moduleFromInput($io, $input);

// --class option
$class = $input->getOption('class');
Expand Down
7 changes: 1 addition & 6 deletions src/Command/Generate/EntityBundleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
$input->setOption('module', $module);
}
$this->moduleFromInput($io, $input);

// --bundle-name option
$bundleName = $input->getOption('bundle-name');
Expand Down
7 changes: 1 addition & 6 deletions src/Command/Generate/EntityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$utils = $this->stringConverter;

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
$input->setOption('module', $module);
}
$this->moduleFromInput($io, $input);

// --entity-class option
$entityClass = $input->getOption('entity-class');
Expand Down
7 changes: 1 addition & 6 deletions src/Command/Generate/EventSubscriberCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
$input->setOption('module', $module);
}
$this->moduleFromInput($io, $input);

// --service-name option
$name = $input->getOption('name');
Expand Down
20 changes: 8 additions & 12 deletions src/Command/Generate/FormAlterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ class FormAlterCommand extends Command
protected $elementInfoManager;

/**
* @var Validator
*/
* @var Validator
*/
protected $validator;

/**
* @var RouteProviderInterface
*/
* @var RouteProviderInterface
*/
protected $routeProvider;

/**
Expand Down Expand Up @@ -106,7 +106,8 @@ public function __construct(
ElementInfoManager $elementInfoManager,
Profiler $profiler = null,
$appRoot,
ChainQueue $chainQueue
ChainQueue $chainQueue,
Validator $validator
) {
$this->extensionManager = $extensionManager;
$this->generator = $generator;
Expand All @@ -116,6 +117,7 @@ public function __construct(
$this->profiler = $profiler;
$this->appRoot = $appRoot;
$this->chainQueue = $chainQueue;
$this->validator = $validator;
parent::__construct();
}

Expand Down Expand Up @@ -199,13 +201,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
}

$input->setOption('module', $module);
$this->moduleFromInput($io, $input);

// --form-id option
$formId = $input->getOption('form-id');
Expand Down
Loading

0 comments on commit b586b25

Please sign in to comment.