本文整理汇总了PHP中Drupal\Console\Style\DrupalStyle::choice方法的典型用法代码示例。如果您正苦于以下问题:PHP DrupalStyle::choice方法的具体用法?PHP DrupalStyle::choice怎么用?PHP DrupalStyle::choice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Console\Style\DrupalStyle
的用法示例。
在下文中一共展示了DrupalStyle::choice方法的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)
{
$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));
}
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$resource_id = $input->getArgument('resource-id');
$rest_resources = $this->getRestResources();
$rest_resources_ids = array_merge(array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled']));
if (!$resource_id) {
$resource_id = $io->choiceNoList($this->trans('commands.rest.enable.arguments.resource-id'), $rest_resources_ids);
}
$this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator());
$input->setArgument('resource-id', $resource_id);
// Calculate states available by resource and generate the question
$resourcePluginManager = $this->getPluginManagerRest();
$plugin = $resourcePluginManager->getInstance(array('id' => $resource_id));
$states = $plugin->availableMethods();
$state = $io->choice($this->trans('commands.rest.enable.arguments.states'), $states);
$io->writeln($this->trans('commands.rest.enable.messages.selected-state') . ' ' . $state);
// Get serializer formats available and generate the question.
$serializedFormats = $this->getSerializerFormats();
$formats = $io->choice($this->trans('commands.rest.enable.messages.formats'), $serializedFormats, 0, true);
$io->writeln($this->trans('commands.rest.enable.messages.selected-formats') . ' ' . implode(', ', $formats));
// Get Authentication Provider and generate the question
$authenticationProviders = $this->getAuthenticationProviders();
$authenticationProvidersSelected = $io->choice($this->trans('commands.rest.enable.messages.authentication-providers'), array_keys($authenticationProviders), 0, true);
$io->writeln($this->trans('commands.rest.enable.messages.selected-authentication-providers') . ' ' . implode(', ', $authenticationProvidersSelected));
$rest_settings = $this->getRestDrupalConfig();
$rest_settings[$resource_id][$state]['supported_formats'] = $formats;
$rest_settings[$resource_id][$state]['supported_auth'] = $authenticationProvidersSelected;
$config = $this->getConfigFactory()->getEditable('rest.settings');
$config->set('resources', $rest_settings);
$config->save();
// Run cache rebuild to enable rest routing
$this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']);
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$resource_id = $input->getArgument('resource-id');
$rest_resources = $this->getRestResources();
$rest_resources_ids = array_merge(array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled']));
if (!$resource_id) {
$resource_id = $io->choiceNoList($this->trans('commands.rest.enable.arguments.resource-id'), $rest_resources_ids);
}
$this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator());
$input->setArgument('resource-id', $resource_id);
// Calculate states available by resource and generate the question
$plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]);
$states = $plugin->availableMethods();
$state = $io->choice($this->trans('commands.rest.enable.arguments.states'), $states);
$io->writeln($this->trans('commands.rest.enable.messages.selected-state') . ' ' . $state);
// Get Authentication Provider and generate the question
$authenticationProviders = $this->authenticationCollector->getSortedProviders();
$authenticationProvidersSelected = $io->choice($this->trans('commands.rest.enable.messages.authentication-providers'), array_keys($authenticationProviders), 0, true);
$io->writeln($this->trans('commands.rest.enable.messages.selected-authentication-providers') . ' ' . implode(', ', $authenticationProvidersSelected));
$rest_settings = $this->getRestDrupalConfig();
$rest_settings[$resource_id][$state]['supported_formats'] = $formats;
$rest_settings[$resource_id][$state]['supported_auth'] = $authenticationProvidersSelected;
$config = $this->configFactory->getEditable('rest.settings');
$config->set('resources', $rest_settings);
$config->save();
return 0;
}
示例5: 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);
}
}
示例6: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
// Check if the constructor passed a value for file.
$file = $input->getOption('file');
if (!$file) {
$files = $this->getChainFiles(true);
$file = $io->choice($this->trans('commands.chain.questions.chain-file'), array_values($files));
}
$file = calculateRealPath($file);
$input->setOption('file', $file);
$chainContent = $this->getFileContents($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);
}
}
示例7: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$entityDefinitionID = $input->getArgument('entity-definition-id');
$entityID = $input->getArgument('entity-id');
if (!$entityDefinitionID) {
$entityTypes = $this->entityTypeRepository->getEntityTypeLabels(true);
$entityType = $io->choice($this->trans('commands.entity.delete.questions.entity-type'), array_keys($entityTypes));
$entityDefinitionID = $io->choice($this->trans('commands.entity.delete.questions.entity-definition-id'), array_keys($entityTypes[$entityType]));
$input->setArgument('entity-definition-id', $entityDefinitionID);
}
if (!$entityID) {
$entityID = $io->ask($this->trans('commands.entity.delete.questions.entity-id'));
$input->setArgument('entity-id', $entityID);
}
}
示例8: 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));
}
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$httpClient = $this->getHttpClientHelper();
$siteName = $input->getArgument('site-name');
$version = $input->getArgument('version');
if ($version) {
$releaseSelected = $version;
} else {
// Getting Module page header and parse to get module Node
$io->info(sprintf($this->trans('commands.site.new.messages.getting-releases')));
// Page for Drupal releases filter by Drupal 8
$projectReleaseSelected = 'https://www.drupal.org/node/3060/release?api_version%5B%5D=7234';
// Parse release module page to get Drupal 8 releases
try {
$html = $httpClient->getHtml($projectReleaseSelected);
} catch (\Exception $e) {
$io->error($e->getMessage());
return;
}
$crawler = new Crawler($html);
$releases = [];
foreach ($crawler->filter('span.file a') as $element) {
if (strpos($element->nodeValue, ".tar.gz") > 0) {
$releaseName = str_replace('.tar.gz', '', str_replace('drupal-', '', $element->nodeValue));
$releases[$releaseName] = $element->nodeValue;
}
}
if (empty($releases)) {
$io->error($this->trans('commands.site.new.messages.no-releases'));
return;
}
$releaseSelected = $io->choice($this->trans('commands.site.new.messages.release'), array_keys($releases));
}
$releaseFilePath = 'http://ftp.drupal.org/files/projects/drupal-' . $releaseSelected . '.tar.gz';
// Destination file to download the release
$destination = tempnam(sys_get_temp_dir(), 'drupal.') . "tar.gz";
try {
// Start the process to download the zip file of release and copy in contrib folter
$io->info(sprintf($this->trans('commands.site.new.messages.downloading'), $releaseSelected));
$httpClient->downloadFile($releaseFilePath, $destination);
$io->info(sprintf($this->trans('commands.site.new.messages.extracting'), $releaseSelected));
$zippy = Zippy::load();
$archive = $zippy->open($destination);
$archive->extract('./');
try {
$filesyStem = new Filesystem();
$filesyStem->rename('./drupal-' . $releaseSelected, './' . $siteName);
} catch (IOExceptionInterface $e) {
$io->error(sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath()));
}
$io->success(sprintf($this->trans('commands.site.new.messages.downloaded'), $releaseSelected, $siteName));
} catch (\Exception $e) {
$io->error($e->getMessage());
return false;
}
return true;
}
示例10: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
global $config_directories;
$io = new DrupalStyle($input, $output);
$directory = $input->getArgument('directory');
if (!$directory) {
$directory = $io->choice($this->trans('commands.config.diff.questions.directories'), array_keys($config_directories), CONFIG_SYNC_DIRECTORY);
$input->setArgument('directory', $config_directories[$directory]);
}
}
示例11: interact
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$configName = $input->getArgument('config-name');
if (!$configName) {
$configFactory = $this->getConfigFactory();
$configNames = $configFactory->listAll();
$configName = $io->choice('Choose a configuration', $configNames);
$input->setArgument('config-name', $configName);
}
}
示例12: releasesQuestion
/**
* @param \Drupal\Console\Style\DrupalStyle $io
* @param $project
* @return string
*/
public function releasesQuestion(DrupalStyle $io, $project)
{
$commandKey = str_replace(':', '.', $this->getName());
$io->comment(sprintf($this->trans('commands.' . $commandKey . '.messages.getting-releases'), implode(',', array($project))));
$releases = $this->getDrupalApi()->getProjectReleases($project, 15);
if (!$releases) {
$io->error(sprintf($this->trans('commands.' . $commandKey . '.messages.no-releases'), implode(',', array($project))));
return null;
}
$version = $io->choice($this->trans('commands.' . $commandKey . '.messages.select-release'), $releases);
return $version;
}
示例13: dbTypeQuestion
/**
* @param DrupalStyle $output
*
* @return mixed
*/
public function dbTypeQuestion(DrupalStyle $output)
{
$databases = $this->getDatabaseTypes();
$dbType = $output->choice($this->trans('commands.migrate.setup.migrations.questions.db-type'), array_column($databases, 'name'));
// find current database type selected to set the proper driver id
foreach ($databases as $dbIndex => $database) {
if ($database['name'] == $dbType) {
$dbType = $dbIndex;
}
}
return $dbType;
}
示例14: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
if (!\Drupal::moduleHandler()->moduleExists('devel')) {
$io->error($this->trans('Devel must be installed'));
return 1;
}
$dumper = $input->getArgument('dumper');
if (!$dumper) {
/* @var string[] $dumpKeys */
$dumpKeys = $this->getDumperKeys();
$dumper = $io->choice($this->trans('Select a Debug Dumper'), $dumpKeys, 'kint', false);
$input->setArgument('dumper', $dumper);
}
}
示例15: interact
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$styles = $input->getArgument('styles');
if (!$styles) {
$image_handler = $this->getService('entity_type.manager')->getStorage('image_style');
$styleList = $image_handler->loadMultiple();
$styleNames = [];
foreach ($styleList as $style) {
$styleNames[] = $style->get('name');
}
$styles = $io->choice($this->trans('commands.image.styles.flush.questions.image-style'), $styleNames, null, true);
$input->setArgument('styles', $styles);
}
}