本文整理汇总了PHP中Drupal\Console\Style\DrupalStyle::ask方法的典型用法代码示例。如果您正苦于以下问题:PHP DrupalStyle::ask方法的具体用法?PHP DrupalStyle::ask怎么用?PHP DrupalStyle::ask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Console\Style\DrupalStyle
的用法示例。
在下文中一共展示了DrupalStyle::ask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: interact
/**
* {@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));
}
}
示例2: interact
/**
* {@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);
}
}
示例3: interact
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);
}
}
示例4: interact
/**
* {@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));
}
}
示例5: interact
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);
}
}
示例6: interact
/**
* {@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);
}
}
示例7: interact
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);
}
}
示例8: interact
/**
* {@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);
}
示例9: interact
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);
}
示例10: interact
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);
}
}
示例11: interact
/**
* {@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));
}
}
示例12: interact
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);
}
}
示例13: interact
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);
}
}
示例14: interact
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);
}
}
示例15: interact
/**
* {@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']);
}
}
}