X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FPluginBlockCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FPluginBlockCommand.php;h=c32e4ea9dc3d39f011b74e7dc18afdc11695f0d6;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Generate/PluginBlockCommand.php b/vendor/drupal/console/src/Command/Generate/PluginBlockCommand.php new file mode 100644 index 000000000..c32e4ea9d --- /dev/null +++ b/vendor/drupal/console/src/Command/Generate/PluginBlockCommand.php @@ -0,0 +1,291 @@ +configFactory = $configFactory; + $this->chainQueue = $chainQueue; + $this->generator = $generator; + $this->entityTypeManager = $entityTypeManager; + $this->extensionManager = $extensionManager; + $this->validator = $validator; + $this->stringConverter = $stringConverter; + $this->elementInfoManager = $elementInfoManager; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:block') + ->setDescription($this->trans('commands.generate.plugin.block.description')) + ->setHelp($this->trans('commands.generate.plugin.block.help')) + ->addOption('module', '', InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.class') + ) + ->addOption( + 'label', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.label') + ) + ->addOption( + 'plugin-id', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.plugin-id') + ) + ->addOption( + 'theme-region', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.theme-region') + ) + ->addOption( + 'inputs', + '', + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.inputs') + ) + ->addOption( + 'services', + '', + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $services = $input->getOption('services'); + $theme_region = $input->getOption('theme-region'); + $inputs = $input->getOption('inputs'); + + $theme = $this->configFactory->get('system.theme')->get('default'); + $themeRegions = \system_region_list($theme, REGIONS_VISIBLE); + + if (!empty($theme_region) && !isset($themeRegions[$theme_region])) { + $io->error( + sprintf( + $this->trans('commands.generate.plugin.block.messages.invalid-theme-region'), + $theme_region + ) + ); + + return 1; + } + + // @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->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + if ($theme_region) { + $block = $this->entityTypeManager + ->getStorage('block') + ->create( + [ + 'id'=> $plugin_id, + 'plugin' => $plugin_id, + 'theme' => $theme + ] + ); + $block->setRegion($theme_region); + $block->save(); + } + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $theme = $this->configFactory->get('system.theme')->get('default'); + $themeRegions = \system_region_list($theme, REGIONS_VISIBLE); + + // --module option + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + // --class option + $class = $input->getOption('class'); + if (!$class) { + $class = $io->ask( + $this->trans('commands.generate.plugin.block.questions.class'), + 'DefaultBlock', + function ($class) { + return $this->validator->validateClassName($class); + } + ); + $input->setOption('class', $class); + } + + // --label option + $label = $input->getOption('label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.generate.plugin.block.questions.label'), + $this->stringConverter->camelCaseToHuman($class) + ); + $input->setOption('label', $label); + } + + // --plugin-id option + $pluginId = $input->getOption('plugin-id'); + if (!$pluginId) { + $pluginId = $io->ask( + $this->trans('commands.generate.plugin.block.questions.plugin-id'), + $this->stringConverter->camelCaseToUnderscore($class) + ); + $input->setOption('plugin-id', $pluginId); + } + + // --theme-region option + $themeRegion = $input->getOption('theme-region'); + if (!$themeRegion) { + $themeRegion = $io->choiceNoList( + $this->trans('commands.generate.plugin.block.questions.theme-region'), + array_values($themeRegions), + null, + true + ); + $themeRegion = array_search($themeRegion, $themeRegions); + $input->setOption('theme-region', $themeRegion); + } + + // --services option + // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion + $services = $this->servicesQuestion($io); + $input->setOption('services', $services); + + $output->writeln($this->trans('commands.generate.plugin.block.messages.inputs')); + + // @see Drupal\Console\Command\Shared\FormTrait::formQuestion + $inputs = $this->formQuestion($io); + $input->setOption('inputs', $inputs); + } +}