/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new ConsoleIO($input, $output); $this->welcomeMessage($io); $title = $io->askAndValidate('Post title', function ($answer) { return Validators::validatePostTitle($answer); }, false, $input->getOption('title')); $input->setOption('title', $title); $layout = $io->ask('Post layout', $input->getOption('layout')); $input->setOption('layout', $layout); $defaultDate = $input->getOption('date'); if (empty($defaultDate) === true) { $defaultDate = $this->getDateFormated(); } $date = $io->ask('Post date', $defaultDate); $input->setOption('date', $date); if ($io->askConfirmation('Do you want to use tags?', empty($input->getOption('tags')) === false)) { $tags = $io->ask('Comma separated list of post tags', $input->getOption('tags')); $input->setOption('tags', $tags); } if ($io->askConfirmation('Do you want to use categories?', empty($input->getOption('categories')) === false)) { $categories = $io->ask('Comma separated list of post categories', $input->getOption('categories')); $input->setOption('categories', $categories); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output, $dialog); } $input->setOption('module', $module); // --command $name = $input->getOption('name'); if (!$name) { $name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.command.questions.name'), $module . ':default'), $module . ':default'); } $input->setOption('name', $name); // --class-name option $class = $input->getOption('class'); if (!$class) { $class = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.command.questions.class'), 'DefaultCommand'), function ($class) { return $this->getValidator()->validateCommandName($class); }, false, 'DefaultCommand', null); $input->setOption('class', $class); } // --container option $containerAware = $input->getOption('container-aware'); if (!$containerAware && $dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.generate.command.questions.container-aware'), 'yes', '?'), true)) { $containerAware = true; } $input->setOption('container-aware', $containerAware); }
protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output, $dialog); } $input->setOption('module', $module); // --class-name option $class_name = $input->getOption('class-name'); if (!$class_name) { $class_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.class-name'), 'ExamplePlugin'), 'ExamplePlugin'); } $input->setOption('class-name', $class_name); $default_machine_name = $this->getStringUtils()->camelCaseToUnderscore($class_name); // --machine-name option $machine_name = $input->getOption('machine-name'); if (!$machine_name) { $machine_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.machine-name'), $default_machine_name), $default_machine_name); } $input->setOption('machine-name', $machine_name); $default_label = $this->getStringUtils()->camelCaseToHuman($class_name); // --label option $label = $input->getOption('label'); if (!$label) { $label = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.label'), $default_label), $default_label); } $input->setOption('label', $label); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output); $input->setOption('module', $module); } // view-id argument $viewId = $input->getArgument('view-id'); if (!$viewId) { $entityManager = $this->getEntityManager(); $views = $entityManager->getStorage('view')->loadMultiple(); $viewList = []; foreach ($views as $view) { $viewList[$view->get('id')] = $view->get('label'); } $viewId = $output->choiceNoList($this->trans('commands.views.export.questions.view'), $viewList); $input->setArgument('view-id', $viewId); } $optionalConfig = $input->getOption('optional-config'); if (!$optionalConfig) { $optionalConfig = $output->confirm($this->trans('commands.config.export.view.questions.optional-config'), true); $input->setOption('optional-config', $optionalConfig); } $includeModuleDependencies = $input->getOption('include-module-dependencies'); if (!$includeModuleDependencies) { $includeModuleDependencies = $output->confirm($this->trans('commands.config.export.view.questions.include-module-dependencies'), true); $input->setOption('include-module-dependencies', $includeModuleDependencies); } }
/** * {@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\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output); $input->setOption('module', $module); } // --name $name = $input->getOption('name'); if (!$name) { $name = $io->ask($this->trans('commands.generate.command.questions.name'), sprintf('%s:default', $module)); $input->setOption('name', $name); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $io->ask($this->trans('commands.generate.command.questions.class'), 'DefaultCommand', function ($class) { return $this->getValidator()->validateCommandName($class); }); $input->setOption('class', $class); } // --container-aware option $containerAware = $input->getOption('container-aware'); if (!$containerAware) { $io->confirm($this->trans('commands.generate.command.questions.container-aware'), true); } $input->setOption('container-aware', $containerAware); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $configOptions = []; $connection = $input->getArgument('connection'); if (false === strpos($connection, ':')) { //treat it as connection name $configOptions['propel']['reverse']['connection'] = $connection; if (!$input->getOption('database-name')) { $input->setOption('database-name', $connection); } } else { //probably a dsn $configOptions += $this->connectionToProperties('reverseconnection=' . $connection, 'reverse'); $configOptions['propel']['reverse']['parserClass'] = sprintf('\\Propel\\Generator\\Reverse\\%sSchemaParser', ucfirst($configOptions['propel']['database']['connections']['reverseconnection']['adapter'])); if (!$input->getOption('database-name')) { $input->setOption('database-name', self::DEFAULT_DATABASE_NAME); } } $generatorConfig = $this->getGeneratorConfig($configOptions, $input); $this->createDirectory($input->getOption('output-dir')); $manager = new ReverseManager(new XmlDumper()); $manager->setGeneratorConfig($generatorConfig); $manager->setLoggerClosure(function ($message) use($input, $output) { if ($input->getOption('verbose')) { $output->writeln($message); } }); $manager->setWorkingDirectory($input->getOption('output-dir')); $manager->setDatabaseName($input->getOption('database-name')); $manager->setSchemaName($input->getOption('schema-name')); if (true === $manager->reverse()) { $output->writeln('<info>Schema reverse engineering finished.</info>'); } }
protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output, $dialog); } $input->setOption('module', $module); // --class-name option $class_name = $input->getOption('class-name'); if (!$class_name) { $class_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.yaml.options.class-name'), 'ExamplePlugin'), 'ExamplePlugin'); } $input->setOption('class-name', $class_name); $default_plugin_name = $this->getStringUtils()->camelCaseToUnderscore($class_name); // --plugin-name option $plugin_name = $input->getOption('plugin-name'); if (!$plugin_name) { $plugin_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.yaml.options.plugin-name'), $default_plugin_name), $default_plugin_name); } $input->setOption('plugin-name', $plugin_name); $default_file_name = strtr($plugin_name, '_-', '..'); // --plugin-file-name option $plugin_file_name = $input->getOption('plugin-file-name'); if (!$plugin_file_name) { $plugin_file_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.yaml.options.plugin-file-name'), $default_file_name), $default_file_name); } $input->setOption('plugin-file-name', $plugin_file_name); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $contentTypes = $input->getArgument('content-types'); if (!$contentTypes) { $bundles = $this->getDrupalApi()->getBundles(); $contentTypes = $io->choice($this->trans('commands.create.nodes.questions.content-type'), array_values($bundles), null, true); $contentTypes = array_map(function ($contentType) use($bundles) { return array_search($contentType, $bundles); }, $contentTypes); $input->setArgument('content-types', $contentTypes); } $limit = $input->getOption('limit'); if (!$limit) { $limit = $io->ask($this->trans('commands.create.nodes.questions.limit'), 25); $input->setOption('limit', $limit); } $titleWords = $input->getOption('title-words'); if (!$titleWords) { $titleWords = $io->ask($this->trans('commands.create.nodes.questions.title-words'), 5); $input->setOption('title-words', $titleWords); } $timeRange = $input->getOption('time-range'); if (!$timeRange) { $timeRanges = $this->getTimeRange(); $timeRange = $io->choice($this->trans('commands.create.nodes.questions.time-range'), array_values($timeRanges)); $input->setOption('time-range', array_search($timeRange, $timeRanges)); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); $utils = $this->getStringUtils(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output, $dialog); } $input->setOption('module', $module); // --entity-class option $entity_class = $input->getOption('entity-class'); if (!$entity_class) { $entity_class = 'DefaultEntity'; $entity_class = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.entity.questions.entity-class'), $entity_class), function ($entity_class) { return $this->validateSpaces($entity_class); }, false, $entity_class, null); } $input->setOption('entity-class', $entity_class); $machine_name = $utils->camelCaseToMachineName($entity_class); // --entity-name option $entity_name = $input->getOption('entity-name'); if (!$entity_name) { $entity_name = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.entity.questions.entity-name'), $machine_name), function ($machine_name) { return $this->validateMachineName($machine_name); }, false, $machine_name, null); } $input->setOption('entity-name', $entity_name); }
/** * Applies parameters that are defined in the extra section of composer.json. * * If the Input object already has a value for the argument or parameter then the value in composer is ignored. * * @param Command $command * @param InputInterface $input * * @return $this * @throws MysqlVersionControlException */ public function applyComposerParams(Command $command, InputInterface $input) { $params = $this->getComposerParams($input->getArgument("env")); $definition = $command->getDefinition(); foreach ($this->filterComposerParams($params, $definition) as $param => $value) { if (0 === strpos($param, "--")) { // option $option = substr($param, 2); $Option = $definition->getOption($option); if (!$Option->acceptValue() && false === $input->getOption($option)) { $input->setOption($option, null); } elseif ($Option->acceptValue() && $Option->getDefault() === $input->getOption($option)) { if ($Option->isArray()) { $input->setOption($option, is_array($value) ? $value : [$value]); } elseif (is_array($value)) { throw new MysqlVersionControlException("The '{$option}' option does not accept arrays. Check your composer.json"); } else { $input->setOption($option, $value); } } } else { // argument $argument = $definition->getArgument($param); if ($argument->getDefault() === $input->getArgument($param)) { $input->setArgument($param, $value); } } } return $this; }
public function interact(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Welcome to the Symfony2 controller generator'); // namespace $output->writeln(array('', 'Every page, and even sections of a page, are rendered by a <comment>controller</comment>.', 'This command helps you generate them easily.', '', 'First, you need to give the controller name you want to generate.', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>', '')); $bundleNames = array_keys($this->getContainer()->get('kernel')->getBundles()); while (true) { $controller = $questionHelper->askAndValidate($output, $questionHelper->getQuestion('Controller name', $input->getOption('controller')), array('Oliorga\\GeneratorBundle\\Command\\Validators', 'validateControllerName'), false, $input->getOption('controller'), $bundleNames); list($bundle, $controller) = $this->parseShortcutNotation($controller); try { $b = $this->getContainer()->get('kernel')->getBundle($bundle); if (!file_exists($b->getPath() . '/Controller/' . $controller . 'Controller.php')) { break; } $output->writeln(sprintf('<bg=red>Controller "%s:%s" already exists.</>', $bundle, $controller)); } catch (\Exception $e) { $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle)); } } $input->setOption('controller', $bundle . ':' . $controller); // routing format $routeFormat = 'annotation'; $input->setOption('route-format', $routeFormat); // templating format $templateFormat = 'twig'; $input->setOption('template-format', $templateFormat); // actions $input->setOption('actions', $this->addActions($input, $output, $questionHelper)); // summary $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg-white', true), '', sprintf('You are going to generate a "<info>%s:%s</info>" controller', $bundle, $controller), sprintf('using the "<info>%s</info>" format for the routing and the "<info>%s</info>" format', $routeFormat, $templateFormat), 'for templating')); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $commandKey = str_replace(':', '.', $this->commandName); $utils = $this->getStringHelper(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($io); $input->setOption('module', $module); } // --entity-class option $entityClass = $input->getOption('entity-class'); if (!$entityClass) { $entityClass = $io->ask($this->trans('commands.' . $commandKey . '.questions.entity-class'), 'DefaultEntity', function ($entityClass) { return $this->validateSpaces($entityClass); }); $input->setOption('entity-class', $entityClass); } // --entity-name option $entityName = $input->getOption('entity-name'); if (!$entityName) { $entityName = $io->ask($this->trans('commands.' . $commandKey . '.questions.entity-name'), $utils->camelCaseToMachineName($entityClass), function ($entityName) { return $this->validateMachineName($entityName); }); $input->setOption('entity-name', $entityName); } // --label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask($this->trans('commands.' . $commandKey . '.questions.label'), $utils->camelCaseToHuman($entityClass)); $input->setOption('label', $label); } }
protected function interact(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output); $input->setOption('module', $module); } // --class option $class_name = $input->getOption('class'); if (!$class_name) { $class_name = $output->ask($this->trans('commands.generate.plugin.views.field.questions.class'), 'CustomViewsField'); } $input->setOption('class', $class_name); // --title option $title = $input->getOption('title'); if (!$title) { $title = $output->ask($this->trans('commands.generate.plugin.views.field.questions.title'), $this->getStringHelper()->camelCaseToHuman($class_name)); $input->setOption('title', $title); } // --description option $description = $input->getOption('description'); if (!$description) { $description = $output->ask($this->trans('commands.generate.plugin.views.field.questions.description'), $this->trans('commands.generate.plugin.views.field.questions.description_default')); $input->setOption('description', $description); } }
protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); $dialog->writeSection($output, 'Welcome to the Symfony2 admin generator'); $output->writeln('<comment>Create controllers for a generator module</comment>'); $generator = $dialog->askAndValidate($output, $dialog->getQuestion('Generator to use (doctrine, doctrine_odm, propel)', $input->getOption('generator')), function ($generator) { if (!in_array($generator, array('doctrine', 'doctrine_odm', 'propel'))) { throw new \RuntimeException('Generator to use have to be doctrine, doctrine_odm or propel'); } return $generator; }, false, $input->getOption('generator')); $input->setOption('generator', $generator); $namespace = $dialog->askAndValidate($output, $dialog->getQuestion('Bundle namespace', $input->getOption('namespace')), array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleNamespace'), false, $input->getOption('namespace')); $input->setOption('namespace', $namespace); // bundle name $bundle = $input->getOption('bundle-name') ?: strtr($namespace, array('\\Bundle\\' => '', '\\' => '')); $output->writeln(array('', 'In your code, a bundle is often referenced by its name. It can be the', 'concatenation of all namespace parts but it\'s really up to you to come', 'up with a unique name (a good practice is to start with the vendor name).', 'Based on the namespace, we suggest <comment>' . $bundle . '</comment>.', '')); $bundle = $dialog->askAndValidate($output, $dialog->getQuestion('Bundle name', $bundle), array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleName'), false, $bundle); $input->setOption('bundle-name', $bundle); // target dir $dir = $input->getOption('dir') ?: dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/src'; $output->writeln(array('', 'The bundle can be generated anywhere. The suggested default directory uses', 'the standard conventions.', '')); $dir = $dialog->askAndValidate($output, $dialog->getQuestion('Target directory', $dir), function ($dir) use($bundle, $namespace) { return Validators::validateTargetDir($dir, $bundle, $namespace); }, false, $dir); $input->setOption('dir', $dir); // prefix $prefix = $dialog->askAndValidate($output, $dialog->getQuestion('Prefix of yaml', $input->getOption('prefix')), function ($prefix) { if (!preg_match('/([a-z]+)/i', $prefix)) { throw new \RuntimeException('Prefix have to be a simple word'); } return $prefix; }, false, $input->getOption('prefix')); $input->setOption('prefix', $prefix); }
protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); $moduleHandler = $this->getModuleHandler(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output, $dialog); } $input->setOption('module', $module); // --class-name option $form_id = $input->getOption('form-id'); if (!$form_id) { $forms = []; if ($moduleHandler->moduleExists('webprofiler')) { $output->writeln('[-] <info>' . $this->trans('commands.generate.form.alter.messages.loading-forms') . '</info>'); $forms = $this->getWebprofilerForms(); } $form_id = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.form.alter.options.form-id'), current(array_keys($forms))), function ($form) { return $form; }, false, '', array_combine(array_keys($forms), array_keys($forms))); } $input->setOption('form-id', $form_id); $output->writeln($this->trans('commands.generate.form.alter.messages.inputs')); // @see Drupal\Console\Command\FormTrait::formQuestion $form = $this->formQuestion($output, $dialog); $input->setOption('inputs', $form); }
protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $this->getDrupalHelper()->loadLegacyFile('/core/includes/update.inc'); $this->getDrupalHelper()->loadLegacyFile('/core/includes/schema.inc'); $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($io); $input->setOption('module', $module); } $lastUpdateSchema = $this->getLastUpdate($module); $nextUpdateSchema = $lastUpdateSchema ? $lastUpdateSchema + 1 : 8001; $updateNumber = $input->getOption('update-n'); if (!$updateNumber) { $updateNumber = $io->ask($this->trans('commands.generate.update.questions.update-n'), $nextUpdateSchema, function ($updateNumber) use($lastUpdateSchema) { if (!is_numeric($updateNumber)) { throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.update.messages.wrong-update-n'), $updateNumber)); } else { if ($updateNumber <= $lastUpdateSchema) { throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.update.messages.wrong-update-n'), $updateNumber)); } return $updateNumber; } }); $input->setOption('update-n', $updateNumber); } }
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($output); $input->setOption('module', $module); } // --class option $class_name = $input->getOption('class'); if (!$class_name) { $class_name = $io->ask($this->trans('commands.generate.plugin.imageeffect.questions.class'), 'DefaultImageEffect'); $input->setOption('class', $class_name); } // --label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask($this->trans('commands.generate.plugin.imageeffect.questions.label'), $this->getStringHelper()->camelCaseToHuman($class_name)); $input->setOption('label', $label); } // --plugin-id option $plugin_id = $input->getOption('plugin-id'); if (!$plugin_id) { $plugin_id = $io->ask($this->trans('commands.generate.plugin.imageeffect.questions.plugin-id'), $this->getStringHelper()->camelCaseToUnderscore($class_name)); $input->setOption('plugin-id', $plugin_id); } // --description option $description = $input->getOption('description'); if (!$description) { $description = $io->ask($this->trans('commands.generate.plugin.imageeffect.questions.description'), 'My Image Effect'); $input->setOption('description', $description); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output, $dialog); } $input->setOption('module', $module); // --content type argument $content_type = $input->getArgument('content_type'); if (!$content_type) { $entity_manager = $this->getEntityManager(); $bundles_entities = $entity_manager->getStorage('node_type')->loadMultiple(); $bundles = array(); foreach ($bundles_entities as $entity) { $bundles[$entity->id()] = $entity->label(); } $content_type = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.config.export.content.type.questions.content_type'), ''), function ($bundle) use($bundles) { if (!in_array($bundle, array_values($bundles))) { throw new \InvalidArgumentException(sprintf('Content type "%s" is invalid.', $bundle)); } return array_search($bundle, $bundles); }, false, '', $bundles); $optionalConfig = $input->getOption('optional-config'); if (!$optionalConfig) { $optionalConfig = $dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.config.export.content.type.questions.optional-config'), 'yes', '?'), true); } $input->setOption('optional-config', $optionalConfig); } $input->setArgument('content_type', $content_type); }
/** * {@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\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($io); } $input->setOption('module', $module); // --content-type argument $contentType = $input->getArgument('content-type'); if (!$contentType) { $entityTypeManager = $this->getService('entity_type.manager'); $bundles_entities = $entityTypeManager->getStorage('node_type')->loadMultiple(); $bundles = array(); foreach ($bundles_entities as $entity) { $bundles[$entity->id()] = $entity->label(); } $contentType = $io->choice($this->trans('commands.config.export.content.type.questions.content-type'), $bundles); } $input->setArgument('content-type', $contentType); $optionalConfig = $input->getOption('optional-config'); if (!$optionalConfig) { $optionalConfig = $io->confirm($this->trans('commands.config.export.content.type.questions.optional-config'), true); } $input->setOption('optional-config', $optionalConfig); }
/** * {@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\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->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->getValidator()->validateBundleTitle($bundle_title); }); $input->setOption('bundle-title', $bundleTitle); } }
protected function interact(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output); $input->setOption('module', $module); } // --class option $class_name = $input->getOption('class'); if (!$class_name) { $class_name = $output->ask($this->trans('commands.generate.plugin.fieldwidget.questions.class'), 'ExampleFieldWidget'); $input->setOption('class', $class_name); } // --plugin label option $label = $input->getOption('label'); if (!$label) { $label = $output->ask($this->trans('commands.generate.plugin.fieldwidget.questions.label'), $this->getStringHelper()->camelCaseToHuman($class_name)); $input->setOption('label', $label); } // --plugin-id option $plugin_id = $input->getOption('plugin-id'); if (!$plugin_id) { $plugin_id = $output->ask($this->trans('commands.generate.plugin.fieldwidget.questions.plugin-id'), $this->getStringHelper()->camelCaseToUnderscore($class_name)); $input->setOption('plugin-id', $plugin_id); } // --field-type option $field_type = $input->getOption('field-type'); if (!$field_type) { $field_type = $output->ask($this->trans('commands.generate.plugin.fieldwidget.questions.field-type')); $input->setOption('field-type', $field_type); } }
protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); $stringUtils = $this->getStringUtils(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output, $dialog); } $input->setOption('module', $module); // --class-name option $class_name = $input->getOption('class-name'); if (!$class_name) { $class_name = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.authentication.provider.options.class-name'), 'DefaultAuthenticationProvider'), function ($value) use($stringUtils) { if (!strlen(trim($value))) { throw new \Exception('The Class name can not be empty'); } return $stringUtils->humanToCamelCase($value); }, false, 'DefaultAuthenticationProvider'); } // --provider-id option $provider_id = $input->getOption('provider-id'); if (!$provider_id) { $provider_id = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.authentication.provider.options.provider-id'), $stringUtils->camelCaseToUnderscore($class_name)), function ($value) use($stringUtils) { if (!strlen(trim($value))) { throw new \Exception('The Class name can not be empty'); } return $stringUtils->camelCaseToUnderscore($value); }, false, $stringUtils->camelCaseToUnderscore($class_name)); } $input->setOption('class-name', $class_name); $input->setOption('provider-id', $provider_id); }
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_name = $input->getOption('class'); if (!$class_name) { $class_name = $io->ask($this->trans('commands.generate.plugin.type.yaml.options.class'), 'ExamplePlugin'); $input->setOption('class', $class_name); } // --plugin-name option $plugin_name = $input->getOption('plugin-name'); if (!$plugin_name) { $plugin_name = $io->ask($this->trans('commands.generate.plugin.type.yaml.options.plugin-name'), $this->stringConverter->camelCaseToUnderscore($class_name)); $input->setOption('plugin-name', $plugin_name); } // --plugin-file-name option $plugin_file_name = $input->getOption('plugin-file-name'); if (!$plugin_file_name) { $plugin_file_name = $io->ask($this->trans('commands.generate.plugin.type.yaml.options.plugin-file-name'), strtr($plugin_name, '_-', '..')); $input->setOption('plugin-file-name', $plugin_file_name); } }
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->getStringHelper()->underscoreToCamelCase($pluginId))), function ($class) { return $this->validateClassName($class); }); $input->setOption('class', $class); } // --services option // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion $services = $input->getOption('services'); if (!$services) { $services = $this->servicesQuestion($output); $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\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output); $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->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->getStringHelper()->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->getStringHelper()->camelCaseToUnderscore($class)); $input->setOption('plugin-id', $pluginId); } // --services option // @see Drupal\Console\Command\ServicesTrait::servicesQuestion $services = $this->servicesQuestion($output); $input->setOption('services', $services); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $nodeId = $input->getArgument('node-id'); if (!$nodeId) { $nodeId = $io->ask($this->trans('commands.create.comments.questions.node-id')); $input->setArgument('node-id', $nodeId); } $limit = $input->getOption('limit'); if (!$limit) { $limit = $io->ask($this->trans('commands.create.comments.questions.limit'), 25); $input->setOption('limit', $limit); } $titleWords = $input->getOption('title-words'); if (!$titleWords) { $titleWords = $io->ask($this->trans('commands.create.comments.questions.title-words'), 5); $input->setOption('title-words', $titleWords); } $timeRange = $input->getOption('time-range'); if (!$timeRange) { $timeRanges = $this->getTimeRange(); $timeRange = $io->choice($this->trans('commands.create.comments.questions.time-range'), array_values($timeRanges)); $input->setOption('time-range', array_search($timeRange, $timeRanges)); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $rids = $input->getArgument('roles'); if (!$rids) { $roles = $this->drupalApi->getRoles(); $rids = $io->choice($this->trans('commands.create.users.questions.roles'), array_values($roles), null, true); $rids = array_map(function ($role) use($roles) { return array_search($role, $roles); }, $rids); $input->setArgument('roles', $rids); } $limit = $input->getOption('limit'); if (!$limit) { $limit = $io->ask($this->trans('commands.create.users.questions.limit'), 10); $input->setOption('limit', $limit); } $password = $input->getOption('password'); if (!$password) { $password = $io->ask($this->trans('commands.create.users.questions.password'), 5); $input->setOption('password', $password); } $timeRange = $input->getOption('time-range'); if (!$timeRange) { $timeRanges = $this->getTimeRange(); $timeRange = $io->choice($this->trans('commands.create.nodes.questions.time-range'), array_values($timeRanges)); $input->setOption('time-range', array_search($timeRange, $timeRanges)); } }
protected function interact(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $stringUtils = $this->getStringHelper(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output); $input->setOption('module', $module); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $output->ask($this->trans('commands.generate.authentication.provider.options.class'), 'DefaultAuthenticationProvider', function ($value) use($stringUtils) { if (!strlen(trim($value))) { throw new \Exception('The Class name can not be empty'); } return $stringUtils->humanToCamelCase($value); }); $input->setOption('class', $class); } // --provider-id option $provider_id = $input->getOption('provider-id'); if (!$provider_id) { $provider_id = $output->ask($this->trans('commands.generate.authentication.provider.options.provider-id'), $stringUtils->camelCaseToUnderscore($class), function ($value) use($stringUtils) { if (!strlen(trim($value))) { throw new \Exception('The Class name can not be empty'); } return $stringUtils->camelCaseToUnderscore($value); }); $input->setOption('provider-id', $provider_id); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($output, $dialog); } $input->setOption('module', $module); // --bundle-name option $bundle_name = $input->getOption('bundle-name'); if (!$bundle_name) { $bundle_name = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.contenttype.questions.bundle-name'), 'default'), function ($bundle_name) { return $this->validateClassName($bundle_name); }, false, 'default', null); } $input->setOption('bundle-name', $bundle_name); // --bundle-title option $bundle_title = $input->getOption('bundle-title'); if (!$bundle_title) { $bundle_title = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.contenttype.questions.bundle-title'), 'default'), function ($bundle_title) { return $this->validateClassName($bundle_title); }, false, 'default', null); } $input->setOption('bundle-title', $bundle_title); }
public function interact(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); $dialog->writeSection($output, 'Welcome to the Redking CRUD Rest generator'); $bundleNames = array_keys($this->getContainer()->get('kernel')->getBundles()); while (true) { $document = $dialog->askAndValidate($output, $dialog->getQuestion('The Document shortcut name', $input->getOption('document')), array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName'), false, $input->getOption('document')); list($bundle, $document) = $this->parseShortcutNotation($document); try { $b = $this->getContainer()->get('kernel')->getBundle($bundle); if (file_exists($b->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php')) { break; } $output->writeln(sprintf('<bg=red>Document "%s:%s" does not exists</>.', $bundle, $document)); } catch (\Exception $e) { $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle)); } } $input->setOption('document', $bundle . ':' . $document); if ($input->getOption('bundle') == '') { $input->setOption('bundle', $bundle); } while (true) { $bundle = $dialog->askAndValidate($output, $dialog->getQuestion('The Bundle where the generation takes place', $input->getOption('bundle')), array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleName'), false, $input->getOption('bundle')); try { $b = $this->getContainer()->get('kernel')->getBundle($bundle); break; } catch (\Exception $e) { $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle)); } } $input->setOption('document', $bundle . ':' . $document); }