/** * {@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) { $output = new DrupalStyle($input, $output); $user = $input->getArgument('user'); if (!$user) { $user = $output->ask($this->trans('commands.user.password.reset.questions.user'), '', function ($uid) { $uid = (int) $uid; if (is_int($uid) && $uid > 0) { return $uid; } else { throw new \InvalidArgumentException(sprintf($this->trans('commands.user.password.reset.questions.invalid-uid'), $uid)); } }); $input->setArgument('user', $user); } $password = $input->getArgument('password'); if (!$password) { $password = $output->ask($this->trans('commands.user.password.hash.questions.password'), '', function ($pass) { if (!empty($pass)) { return $pass; } else { throw new \InvalidArgumentException(sprintf($this->trans('commands.user.password.hash.questions.invalid-pass'), $pass)); } }); $input->setArgument('password', $password); } }
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_name = $input->getOption('class'); if (!$class_name) { $class_name = $io->ask($this->trans('commands.generate.plugin.type.annotation.options.class'), 'ExamplePlugin'); $input->setOption('class', $class_name); } // --machine-name option $machine_name = $input->getOption('machine-name'); if (!$machine_name) { $machine_name = $io->ask($this->trans('commands.generate.plugin.type.annotation.options.machine-name'), $this->getStringHelper()->camelCaseToUnderscore($class_name)); $input->setOption('machine-name', $machine_name); } // --label option $label = $input->getOption('label'); if (!$label) { $label = $output->ask($this->trans('commands.generate.plugin.type.annotation.options.label'), $this->getStringHelper()->camelCaseToHuman($class_name)); $input->setOption('label', $label); } }
/** * {@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)); } }
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) { $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); } // --name option $name = $input->getOption('name'); if (!$name) { $name = $io->ask($this->trans('commands.generate.twig.extension.questions.twig-extension'), $module . '.twig.extension'); $input->setOption('name', $name); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $io->ask($this->trans('commands.common.options.class'), 'DefaultTwigExtension'); $input->setOption('class', $class); } // --services option $services = $input->getOption('services'); if (!$services) { // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion $services = $this->servicesQuestion($output); $input->setOption('services', $services); } }
protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $stringUtils = $this->getStringHelper(); // --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 = $input->getOption('class'); if (!$class) { $class = $io->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 = $io->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) { $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); }
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); }
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.views.field.questions.class'), 'CustomViewsField'); } $input->setOption('class', $class_name); // --title option $title = $input->getOption('title'); if (!$title) { $title = $io->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 = $io->ask($this->trans('commands.generate.plugin.views.field.questions.description'), $this->trans('commands.generate.plugin.views.field.questions.description_default')); $input->setOption('description', $description); } }
/** * {@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) { $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.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->getStringHelper()->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 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 = $io->ask($this->trans('commands.generate.plugin.ckeditorbutton.questions.class'), 'DefaultCKEditorButton'); $input->setOption('class', $class_name); } // --label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask($this->trans('commands.generate.plugin.ckeditorbutton.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.ckeditorbutton.questions.plugin-id'), $this->getStringHelper()->camelCaseToLowerCase($label)); $input->setOption('plugin-id', $plugin_id); } // --button-name option $button_name = $input->getOption('button-name'); if (!$button_name) { $button_name = $io->ask($this->trans('commands.generate.plugin.ckeditorbutton.questions.button-name'), $this->getStringHelper()->anyCaseToUcFirst($plugin_id)); $input->setOption('button-name', $button_name); } }
protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $entity_manager = $this->getEntityManager(); $entity_types = $entity_manager->getEntityTypeLabels(true); // --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.condition.questions.class'), 'ExampleCondition'); $input->setOption('class', $class); } // --plugin label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask($this->trans('commands.generate.plugin.condition.questions.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.condition.questions.plugin-id'), $this->getStringHelper()->camelCaseToUnderscore($class)); $input->setOption('plugin-id', $pluginId); } $context_definition_id = $input->getOption('context-definition-id'); if (!$context_definition_id) { $context_type = array('language' => 'Language', "entity" => "Entity"); $context_type_sel = $io->choice($this->trans('commands.generate.plugin.condition.questions.context-type'), array_values($context_type)); $context_type_sel = array_search($context_type_sel, $context_type); if ($context_type_sel == 'language') { $context_definition_id = $context_type_sel; $context_definition_id_value = ucfirst($context_type_sel); } else { $content_entity_types_sel = $io->choice($this->trans('commands.generate.plugin.condition.questions.context-entity-type'), array_keys($entity_types)); $contextDefinitionIdList = $entity_types[$content_entity_types_sel]; $context_definition_id_sel = $io->choice($this->trans('commands.generate.plugin.condition.questions.context-definition-id'), array_values($contextDefinitionIdList)); $context_definition_id_value = array_search($context_definition_id_sel, $contextDefinitionIdList); $context_definition_id = 'entity:' . $context_definition_id_value; } $input->setOption('context-definition-id', $context_definition_id); } $context_definition_label = $input->getOption('context-definition-label'); if (!$context_definition_label) { $context_definition_label = $io->ask($this->trans('commands.generate.plugin.condition.questions.context-definition-label'), $context_definition_id_value ?: null); $input->setOption('context-definition-label', $context_definition_label); } $context_definition_required = $input->getOption('context-definition-required'); if (empty($context_definition_required)) { $context_definition_required = $io->confirm($this->trans('commands.generate.plugin.condition.questions.context-definition-required'), true); $input->setOption('context-definition-required', $context_definition_required); } }
/** * {@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); } // --class option $className = $input->getOption('class'); if (!$className) { $className = $io->ask($this->trans('commands.generate.form.questions.class'), 'DefaultForm'); $input->setOption('class', $className); } // --form-id option $formId = $input->getOption('form-id'); if (!$formId) { $formId = $io->ask($this->trans('commands.generate.form.questions.form-id'), $this->getStringHelper()->camelCaseToMachineName($className)); $input->setOption('form-id', $formId); } // --services option // @see use Drupal\Console\Command\ServicesTrait::servicesQuestion $services = $this->servicesQuestion($output); $input->setOption('services', $services); // --inputs option $inputs = $input->getOption('inputs'); if (!$inputs) { // @see \Drupal\Console\Command\FormTrait::formQuestion $inputs = $this->formQuestion($output); $input->setOption('inputs', $inputs); } // --routing option for ConfigFormBase if ($this->formType == 'ConfigFormBase') { $routing = $input->getOption('routing'); if (!$routing) { $routing = $io->confirm($this->trans('commands.generate.form.questions.routing'), true); $input->setOption('routing', $routing); } } // --link option for links.menu if ($this->formType == 'ConfigFormBase') { $menu_options = $this->menuQuestion($output, $className); $menu_link_gen = $input->getOption('menu_link_gen'); $menu_link_title = $input->getOption('menu_link_title'); $menu_parent = $input->getOption('menu_parent'); $menu_link_desc = $input->getOption('menu_link_desc'); if (!$menu_link_gen || !$menu_link_title || !$menu_parent || !$menu_link_desc) { $input->setOption('menu_link_gen', $menu_options['menu_link_gen']); $input->setOption('menu_link_title', $menu_options['menu_link_title']); $input->setOption('menu_parent', $menu_options['menu_parent']); $input->setOption('menu_link_desc', $menu_options['menu_link_desc']); } } }
protected function interact(InputInterface $input, OutputInterface $output) { $io = 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_name = $input->getOption('class'); if (!$class_name) { $class_name = $io->ask($this->trans('commands.generate.plugin.rest.resource.questions.class'), 'DefaultRestResource', function ($class_name) use($stringUtils) { if (!strlen(trim($class_name))) { throw new \Exception('The Class name can not be empty'); } return $stringUtils->humanToCamelCase($class_name); }); $input->setOption('class', $class_name); } // --plugin-id option $plugin_id = $input->getOption('plugin-id'); if (!$plugin_id) { $plugin_id = $io->ask($this->trans('commands.generate.plugin.rest.resource.questions.plugin-id'), $stringUtils->camelCaseToUnderscore($class_name)); $input->setOption('plugin-id', $plugin_id); } // --plugin-label option $plugin_label = $input->getOption('plugin-label'); if (!$plugin_label) { $plugin_label = $io->ask($this->trans('commands.generate.plugin.rest.resource.questions.plugin-label'), $this->getStringHelper()->camelCaseToHuman($class_name)); $input->setOption('plugin-label', $plugin_label); } // --plugin-url option $plugin_url = $input->getOption('plugin-url'); if (!$plugin_url) { $plugin_url = $io->ask($this->trans('commands.generate.plugin.rest.resource.questions.plugin-url')); $input->setOption('plugin-url', $plugin_url); } // --plugin-states option $plugin_states = $input->getOption('plugin-states'); if (!$plugin_states) { $questionHelper = $this->getQuestionHelper(); $states = array('GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'); $question = new ChoiceQuestion($this->trans('commands.generate.plugin.rest.resource.questions.plugin-states'), $states, '0'); $question->setMultiselect(true); $plugin_states = $questionHelper->ask($input, $output, $question); $io->info($this->trans('commands.generate.plugin.rest.resource.messages.selected-states') . ' ' . implode(', ', $plugin_states)); $input->setOption('plugin-states', $plugin_states); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $directory = $input->getArgument('directory'); if (!$directory) { $directory = $io->ask($this->trans('commands.site.import.local.questions.directory'), getcwd()); $input->setArgument('directory', $directory); } $name = $input->getArgument('name'); if (!$name) { $name = $io->ask($this->trans('commands.site.import.local.questions.name')); $input->setArgument('name', $name); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $limit = $input->getOption('limit'); if (!$limit) { $limit = $io->ask($this->trans('commands.create.vocabularies.questions.limit'), 10); $input->setOption('limit', $limit); } $nameWords = $input->getOption('name-words'); if (!$nameWords) { $nameWords = $io->ask($this->trans('commands.create.vocabularies.questions.name-words'), 5); $input->setOption('name-words', $nameWords); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $uid = $input->getArgument('uid'); // Check if $uid argument is already set. if (!$uid) { while (true) { // Request $uid argument. $uid = $io->ask($this->trans('commands.user.login.clear.attempts.questions.uid'), 1, function ($uid) use($io) { $message = !is_numeric($uid) ? $this->trans('commands.user.login.clear.attempts.questions.numeric-uid') : false; // Check if $uid is upper than zero. if (!$message && $uid <= 0) { $message = $this->trans('commands.user.login.clear.attempts.questions.invalid-uid'); } // Check if message was defined. if ($message) { $io->error($message); return false; } // Return a valid $uid. return (int) $uid; }); if ($uid) { break; } } $input->setArgument('uid', $uid); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $file = $input->getOption('file'); $fileUtil = $this->getApplication()->getContainerHelper()->get('file_util'); if (!$file) { $files = $this->getChainFiles(true); $file = $io->choice($this->trans('commands.chain.questions.chain-file'), array_values($files)); } $file = $fileUtil->calculateRealPath($file); $input->setOption('file', $file); $chainContent = file_get_contents($file); $placeholder = $input->getOption('placeholder'); $inlinePlaceHolders = $this->extractInlinePlaceHolders($chainContent); if (!$placeholder && $inlinePlaceHolders) { foreach ($inlinePlaceHolders as $key => $inlinePlaceHolder) { $inlinePlaceHolderDefault = ''; if (strpos($inlinePlaceHolder, '|') > 0) { $placeholderParts = explode('|', $inlinePlaceHolder); $inlinePlaceHolder = $placeholderParts[0]; $inlinePlaceHolderDefault = $placeholderParts[1]; $inlinePlaceHolders[$key] = $inlinePlaceHolder; } $placeholder[] = sprintf('%s:%s', $inlinePlaceHolder, $io->ask(sprintf('Enter placeholder value for <comment>%s</comment>', $inlinePlaceHolder), $inlinePlaceHolderDefault)); } $input->setOption('placeholder', $placeholder); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $name = $input->getArgument('name'); $configFactory = $this->getDrupalService('config.factory'); $names = $configFactory->listAll(); if ($name) { if (!in_array($name, $names)) { $io->warning(sprintf($this->trans('commands.config.override.messages.invalid-name'), $name)); $name = null; } } if (!$name) { $name = $io->choiceNoList($this->trans('commands.config.override.questions.name'), $names); $input->setArgument('name', $name); } $key = $input->getArgument('key'); if (!$key) { $configStorage = $this->getDrupalService('config.storage'); if ($configStorage->exists($name)) { $configuration = $configStorage->read($name); } $key = $io->choiceNoList($this->trans('commands.config.override.questions.key'), array_keys($configuration)); $input->setArgument('key', $key); } $value = $input->getArgument('value'); if (!$value) { $value = $io->ask($this->trans('commands.config.override.questions.value')); $input->setArgument('value', $value); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $passwords = $input->getArgument('password'); if (!$passwords) { $passwords = []; while (true) { $password = $io->ask($this->trans('commands.user.password.hash.questions.password'), '', function ($pass) use($passwords, $io) { if (!empty($pass) || count($passwords) >= 1) { if ($pass == '') { return true; } return $pass; } else { $io->error(sprintf($this->trans('commands.user.password.hash.questions.invalid-pass'), $pass)); return false; } }); if ($password && !is_string($password)) { break; } if (is_string($password)) { $passwords[] = $password; } } $input->setArgument('password', $passwords); } }
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_name = $input->getOption('class'); if (!$class_name) { $class_name = $io->ask($this->trans('commands.generate.plugin.fieldtype.questions.class'), 'ExampleFieldType'); $input->setOption('class', $class_name); } // --label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask($this->trans('commands.generate.plugin.fieldtype.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.fieldtype.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.fieldtype.questions.description'), 'My Field Type'); $input->setOption('description', $description); } // --default-widget option $default_widget = $input->getOption('default-widget'); if (!$default_widget) { $default_widget = $io->askEmpty($this->trans('commands.generate.plugin.fieldtype.questions.default-widget')); $input->setOption('default-widget', $default_widget); } // --default-formatter option $default_formatter = $input->getOption('default-formatter'); if (!$default_formatter) { $default_formatter = $io->askEmpty($this->trans('commands.generate.plugin.fieldtype.questions.default-formatter')); $input->setOption('default-formatter', $default_formatter); } }
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.rulesaction.options.class'), 'DefaultAction'); $input->setOption('class', $class_name); } // --label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask($this->trans('commands.generate.plugin.rulesaction.options.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.rulesaction.options.plugin-id'), $this->getStringHelper()->camelCaseToUnderscore($class_name)); $input->setOption('plugin-id', $plugin_id); } // --type option $type = $input->getOption('type'); if (!$type) { $type = $io->ask($this->trans('commands.generate.plugin.rulesaction.options.type'), 'user'); $input->setOption('type', $type); } // --category option $category = $input->getOption('category'); if (!$category) { $category = $io->ask($this->trans('commands.generate.plugin.rulesaction.options.category'), $this->getStringHelper()->camelCaseToUnderscore($class_name)); $input->setOption('category', $category); } // --context option $context = $input->getOption('context'); if (!$context) { $context = $io->ask($this->trans('commands.generate.plugin.rulesaction.options.context'), $this->getStringHelper()->camelCaseToUnderscore($class_name)); $input->setOption('context', $context); } }
/** * @param DrupalStyle $io * * @return mixed */ public function regionQuestion(DrupalStyle $io) { $validators = $this->validator; $regions = []; while (true) { $regionName = $io->ask($this->trans('commands.generate.theme.questions.region-name'), 'Content'); $regionMachineName = $this->stringConverter->createMachineName($regionName); $regionMachineName = $io->ask($this->trans('commands.generate.theme.questions.region-machine-name'), $regionMachineName, function ($regionMachineName) use($validators) { return $validators->validateMachineName($regionMachineName); }); array_push($regions, ['region_name' => $regionName, 'region_machine_name' => $regionMachineName]); if (!$io->confirm($this->trans('commands.generate.theme.questions.region-add'), true)) { break; } } return $regions; }
protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $fieldTypePluginManager = $this->hasGetService('plugin.manager.field.field_type'); // --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.fieldformatter.questions.class'), 'ExampleFieldFormatter'); $input->setOption('class', $class); } // --plugin label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask($this->trans('commands.generate.plugin.fieldformatter.questions.label'), $this->getStringHelper()->camelCaseToHuman($class)); $input->setOption('label', $label); } // --name option $plugin_id = $input->getOption('plugin-id'); if (!$plugin_id) { $plugin_id = $io->ask($this->trans('commands.generate.plugin.fieldformatter.questions.plugin-id'), $this->getStringHelper()->camelCaseToUnderscore($class)); $input->setOption('plugin-id', $plugin_id); } // --field type option $field_type = $input->getOption('field-type'); if (!$field_type) { // Gather valid field types. $field_type_options = array(); foreach ($fieldTypePluginManager->getGroupedDefinitions($fieldTypePluginManager->getUiDefinitions()) as $category => $field_types) { foreach ($field_types as $name => $field_type) { $field_type_options[] = $name; } } $questionHelper = $this->getQuestionHelper(); $question = new ChoiceQuestion($this->trans('commands.generate.plugin.fieldwidget.questions.field-type'), $field_type_options, 0); $field_type = $questionHelper->ask($input, $output, $question); $input->setOption('field-type', $field_type); } }
/** * @param \Drupal\Console\Style\DrupalStyle $io * @param string $className The form class name * @return string * @throws \Exception */ public function menuQuestion(DrupalStyle $io, $className) { if ($io->confirm($this->trans('commands.generate.form.questions.menu_link_gen'), true)) { // now we need to ask them where to gen the form // get the route $menu_options = ['menu_link_gen' => true]; $menu_link_title = $io->ask($menu_link_title = $this->trans('commands.generate.form.questions.menu_link_title'), $className); $menuLinkFile = sprintf('%s/core/modules/system/system.links.menu.yml', $this->getSite()->getSiteRoot()); $config = $this->getApplication()->getConfig(); $menuLinkContent = $config->getFileContents($menuLinkFile); $menu_parent = $io->choiceNoList($menu_parent = $this->trans('commands.generate.form.questions.menu_parent'), array_keys($menuLinkContent), 'system.admin_config_system'); $menu_link_desc = $io->ask($menu_link_desc = $this->trans('commands.generate.form.questions.menu_link_desc'), 'A description for the menu entry'); $menu_options['menu_link_title'] = $menu_link_title; $menu_options['menu_parent'] = $menu_parent; $menu_options['menu_link_desc'] = $menu_link_desc; return $menu_options; } }
/** * @param DrupalStyle $output * * @return mixed */ public function permissionQuestion(DrupalStyle $output) { $permissions = []; $boolOrNone = ['true', 'false', 'none']; while (true) { $permission = $output->ask($this->trans('commands.generate.permission.questions.permission'), 'access content'); $title = $output->ask($this->trans('commands.generate.permission.questions.title'), 'Access content'); $description = $output->ask($this->trans('commands.generate.permission.questions.description'), 'Allow access to my content'); $restrictAccess = $output->choiceNoList($this->trans('commands.generate.permission.questions.restrict-access'), $boolOrNone, 'none'); $permission = $this->stringConverter->camelCaseToLowerCase($permission); $title = $this->stringConverter->anyCaseToUcFirst($title); array_push($permissions, ['permission' => $permission, 'title' => $title, 'description' => $description, 'restrict_access' => $restrictAccess]); if (!$output->confirm($this->trans('commands.generate.permission.questions.add'), true)) { break; } } return $permissions; }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); // Check if $uid argument is already set. if (!($uid = $input->getArgument('uid'))) { // Request $uid argument. $uid = $output->ask($this->trans('commands.user.login.clear.attempts.questions.uid'), 1, $this->validateQuestionsUid($uid)); $input->setArgument('uid', $uid); } }
/** * {@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($output); $input->setOption('module', $module); } //--name option $name = $input->getOption('name'); if (!$name) { $name = $io->ask($this->trans('commands.generate.service.questions.service-name'), $module . '.default'); $input->setOption('name', $name); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $io->ask($this->trans('commands.generate.service.questions.class'), 'DefaultService'); $input->setOption('class', $class); } // --interface option $interface = $input->getOption('interface'); if (!$interface) { $interface = $io->confirm($this->trans('commands.generate.service.questions.interface'), true); $input->setOption('interface', $interface); } // --services option $services = $input->getOption('services'); if (!$services) { // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion $services = $this->servicesQuestion($output); $input->setOption('services', $services); } // --path_service option $path_service = $input->getOption('path_service'); if (!$path_service) { $path_service = $io->ask($this->trans('commands.generate.service.questions.path'), '/modules/custom/' . $module . '/src/'); $input->setOption('path_service', $path_service); } }