Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[generate:plugin:block] Inject plugin.manager.element_info service #2749

Merged
merged 1 commit into from
Oct 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/services/drupal-console/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ services:
- { name: drupal.command }
console.generate_pluginblock:
class: Drupal\Console\Command\Generate\PluginBlockCommand
arguments: ['@config.factory', '@console.chain_queue', '@console.pluginblock_generator', '@entity_type.manager', '@console.extension_manager', '@console.validator', '@console.string_converter']
arguments: ['@config.factory', '@console.chain_queue', '@console.pluginblock_generator', '@entity_type.manager', '@console.extension_manager', '@console.validator', '@console.string_converter', '@plugin.manager.element_info']
tags:
- { name: drupal.command }
console.generate_command:
class: Drupal\Console\Command\Generate\CommandCommand
arguments: ['@drupal.command_generator', '@console.extension_manager', '@console.validator', '@console.string_converter' ]
arguments: ['@console.command_generator', '@console.extension_manager', '@console.validator', '@console.string_converter' ]
tags:
- { name: drupal.command }
console.generate_ckeditorbutton:
class: Drupal\Console\Command\Generate\PluginCKEditorButtonCommand
arguments: ['@console.chain_queue', '@drupal.command_ckeditorbutton', '@console.extension_manager', '@console.string_converter']
arguments: ['@console.chain_queue', '@console.command_ckeditorbutton', '@console.extension_manager', '@console.string_converter']
tags:
- { name: drupal.command }
console.generate_entitycontent:
Expand Down
8 changes: 6 additions & 2 deletions config/services/drupal-console/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ services:
console.route_subscriber_generator:
class: Drupal\Console\Generator\RouteSubscriberGenerator
arguments: ['@console.extension_manager']
tags:
- { name: drupal.generator }
console.service_generator:
class: Drupal\Console\Generator\ServiceGenerator
arguments: ['@console.extension_manager']
Expand All @@ -152,12 +154,14 @@ services:
console.pluginblock_generator:
class: Drupal\Console\Generator\PluginBlockGenerator
arguments: ['@console.extension_manager']
drupal.command_generator:
tags:
- { name: drupal.generator }
console.command_generator:
class: Drupal\Console\Generator\CommandGenerator
arguments: ['@console.extension_manager', '@console.translator_manager']
tags:
- { name: drupal.generator }
drupal.command_ckeditorbutton:
console.command_ckeditorbutton:
class: Drupal\Console\Generator\PluginCKEditorButtonGenerator
arguments: ['@console.extension_manager']
tags:
Expand Down
62 changes: 43 additions & 19 deletions src/Command/Generate/PluginBlockCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Drupal\Console\Utils\ChainQueue;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;

use Drupal\Core\Render\ElementInfoManagerInterface;

class PluginBlockCommand extends Command
{
Expand All @@ -34,7 +34,6 @@ class PluginBlockCommand extends Command
use ConfirmationTrait;
use ContainerAwareCommandTrait;


/**
* @var ConfigFactory
*/
Expand All @@ -45,35 +44,46 @@ class PluginBlockCommand extends Command
*/
protected $chainQueue;

/** @var PluginBlockGenerator */
/**
* @var PluginBlockGenerator
*/
protected $generator;

/**
* @var EntityTypeManagerInterface
*/
protected $entityTypeManager;

/** @var Manager */
/**
* @var Manager
*/
protected $extensionManager;

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

/**
* @var StringConverter
*/
protected $stringConverter;

/**
* @var ElementInfoManagerInterface
*/
protected $elementInfoManager;

/**
* PluginBlockCommand constructor.
* @param ConfigFactory $configFactory
* @param ChainQueue $chainQueue
* @param PluginBlockGenerator $generator
* @param EntityTypeManagerInterface $entityTypeManager
* @param Manager $extensionManager
* @param Validator $validator
* @param StringConverter $stringConverter
* @param ConfigFactory $configFactory
* @param ChainQueue $chainQueue
* @param PluginBlockGenerator $generator
* @param EntityTypeManagerInterface $entityTypeManager
* @param Manager $extensionManager
* @param Validator $validator
* @param StringConverter $stringConverter
* @param ElementInfoManagerInterface $elementInfoManager
*/
public function __construct(
ConfigFactory $configFactory,
Expand All @@ -82,7 +92,8 @@ public function __construct(
EntityTypeManagerInterface $entityTypeManager,
Manager $extensionManager,
Validator $validator,
StringConverter $stringConverter
StringConverter $stringConverter,
ElementInfoManagerInterface $elementInfoManager
) {
$this->configFactory = $configFactory;
$this->chainQueue = $chainQueue;
Expand All @@ -91,6 +102,7 @@ public function __construct(
$this->extensionManager = $extensionManager;
$this->validator = $validator;
$this->stringConverter = $stringConverter;
$this->elementInfoManager = $elementInfoManager;
parent::__construct();
}

Expand Down Expand Up @@ -176,15 +188,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
// @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices
$build_services = $this->buildServices($services);

$this
->generator
->generate($module, $class_name, $label, $plugin_id, $build_services, $inputs);
$this->generator
->generate(
$module,
$class_name,
$label,
$plugin_id,
$build_services,
$inputs
);

$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);

if ($theme_region) {
// Load block to set theme region
$block = $this->entityTypeManager->getStorage('block')->create(array('id'=> $plugin_id, 'plugin' => $plugin_id, 'theme' => $theme));
$block = $this->entityTypeManager
->getStorage('block')
->create(
[
'id'=> $plugin_id,
'plugin' => $plugin_id,
'theme' => $theme
]
);
$block->setRegion($theme_region);
$block->save();
}
Expand Down Expand Up @@ -213,7 +238,6 @@ protected function interact(InputInterface $input, OutputInterface $output)
'DefaultBlock',
function ($class) {
return $this->validator->validateClassName($class);
return $this->validator->validateClassName($class);
}
);
$input->setOption('class', $class);
Expand Down
5 changes: 0 additions & 5 deletions src/Command/Shared/FormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public function formQuestion(DrupalStyle $io)
'text_format'
];

if (!$this->elementInfoManager) {
$io->writeln('Please inject service plugin.manager.element_info');
return false;
}

foreach ($this->elementInfoManager->getDefinitions() as $definition) {
$type = $definition['id'];
$elementInfo = $this->elementInfoManager->getInfo($type);
Expand Down
7 changes: 3 additions & 4 deletions src/Generator/PluginBlockGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

class PluginBlockGenerator extends Generator
{

/** @var Manager */
/**
* @var Manager
*/
protected $extensionManager;


/**
* PermissionGenerator constructor.
* @param Manager $extensionManager
Expand All @@ -26,7 +26,6 @@ public function __construct(
$this->extensionManager = $extensionManager;
}


/**
* Generator Plugin Block.
*
Expand Down