/** * {@inheritdoc} */ 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); } // --bundle-name option $bundleName = $input->getOption('bundle-name'); if (!$bundleName) { $bundleName = $io->ask($this->trans('commands.generate.entity.bundle.questions.bundle-name'), 'default', function ($bundleName) { return $this->validator->validateClassName($bundleName); }); $input->setOption('bundle-name', $bundleName); } // --bundle-title option $bundleTitle = $input->getOption('bundle-title'); if (!$bundleTitle) { $bundleTitle = $io->ask($this->trans('commands.generate.entity.bundle.questions.bundle-title'), 'default', function ($bundle_title) { return $this->validator->validateBundleTitle($bundle_title); }); $input->setOption('bundle-title', $bundleTitle); } }
protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($io); $input->setOption('module', $module); } $pluginId = $input->getOption('plugin-id'); if (!$pluginId) { $plugins = $this->getPlugins(); $pluginId = $io->choiceNoList($this->trans('commands.generate.plugin.skeleton.questions.plugin'), $plugins); $input->setOption('plugin-id', $pluginId); } if (array_key_exists($pluginId, $this->pluginGeneratorsImplemented)) { $io->warning(sprintf($this->trans('commands.generate.plugin.skeleton.messages.plugin-dont-exist'), $pluginId, $this->pluginGeneratorsImplemented[$pluginId])); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $io->ask($this->trans('commands.generate.plugin.skeleton.options.class'), sprintf('%s%s', 'Default', ucfirst($this->stringConverter->underscoreToCamelCase($pluginId))), function ($class) { return $this->validator->validateClassName($class); }); $input->setOption('class', $class); } // --services option // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion $services = $input->getOption('services'); if (!$services) { $services = $this->servicesQuestion($io); $input->setOption('services', $services); } }
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); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $io->ask($this->trans('commands.generate.plugin.mail.options.class'), 'HtmlFormatterMail', 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.mail.options.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.mail.options.plugin-id'), $this->stringConverter->camelCaseToUnderscore($class)); $input->setOption('plugin-id', $pluginId); } // --services option // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion $services = $this->servicesQuestion($io); $input->setOption('services', $services); }
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.options.class'), 'DefaultBlock', function ($class) { return $this->validator->validateClassName($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.options.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.options.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.options.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); }
/** * {@inheritdoc} */ 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); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $io->ask($this->trans('commands.generate.controller.questions.class'), 'DefaultController', function ($class) { return $this->validator->validateClassName($class); }); $input->setOption('class', $class); } $routes = $input->getOption('routes'); if (!$routes) { while (true) { $title = $io->askEmpty($this->trans('commands.generate.controller.questions.title'), function ($title) use($routes) { if ($routes && empty(trim($title))) { return false; } if (!$routes && empty(trim($title))) { throw new \InvalidArgumentException($this->trans('commands.generate.controller.messages.title-empty')); } if (in_array($title, array_column($routes, 'title'))) { throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.controller.messages.title-already-added'), $title)); } return $title; }); if ($title === '') { break; } $method = $io->ask($this->trans('commands.generate.controller.questions.method'), 'hello', function ($method) use($routes) { if (in_array($method, array_column($routes, 'method'))) { throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.controller.messages.method-already-added'), $method)); } return $method; }); $path = $io->ask($this->trans('commands.generate.controller.questions.path'), sprintf('/%s/hello/{name}', $module), function ($path) use($routes) { if (count($this->routeProvider->getRoutesByPattern($path)) > 0 || in_array($path, array_column($routes, 'path'))) { throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.controller.messages.path-already-added'), $path)); } return $path; }); $classMachineName = $this->stringConverter->camelCaseToMachineName($class); $routeName = $module . '.' . $classMachineName . '_' . $method; if ($this->routeProvider->getRoutesByNames([$routeName]) || in_array($routeName, $routes)) { $routeName .= '_' . rand(0, 100); } $routes[] = ['title' => $title, 'name' => $routeName, 'method' => $method, 'path' => $path]; } $input->setOption('routes', $routes); } // --test option $test = $input->getOption('test'); if (!$test) { $test = $io->confirm($this->trans('commands.generate.controller.questions.test'), true); $input->setOption('test', $test); } // --services option // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion $services = $this->servicesQuestion($io); $input->setOption('services', $services); }