/** * {@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) { $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 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']); }
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; }
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); // 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); } }
/** * {@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); } }
/** * {@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 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; }
/** * {@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]); } }
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); } }
/** * @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; }
/** * @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; }
/** * {@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); } }
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); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); //Without devel we will not get very far $d = $this->getModuleHandler()->moduleExists('devel'); if (!$d) { $io->error($this->trans('Devel must be installed')); } $name = $input->getArgument('dumper'); if (!$name) { /* @var string[] $dumpKeys */ $dumpKeys = $this->getDumperKeys(); $name = $io->choice($this->trans('Select a Debug Dumper'), $dumpKeys, 'kint', false); $input->setArgument('dumper', $name); } }
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->choice($this->trans('commands.rest.disable.arguments.resource-id'), $rest_resources_ids); } $this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator()); $input->setArgument('resource-id', $resource_id); $rest_settings = $this->getRestDrupalConfig(); unset($rest_settings[$resource_id]); $config = $this->getConfigFactory()->getEditable('rest.settings'); $config->set('resources', $rest_settings); $config->save(); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $userId = $input->getOption('user-id'); if (!$userId) { $userId = $io->askEmpty($this->trans('commands.user.delete.questions.user-id'), null); $input->setOption('user-id', $userId); } $roles = $input->getOption('roles'); if (!$userId && !$roles) { $systemRoles = $this->drupalApi->getRoles(false, false, false); $roles = $io->choice($this->trans('commands.user.delete.questions.roles'), array_values($systemRoles), null, true); $roles = array_map(function ($role) use($systemRoles) { return array_search($role, $systemRoles); }, $roles); $input->setOption('roles', $roles); } }
protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $fieldTypePluginManager = $this->getService('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_name = $input->getOption('class'); if (!$class_name) { $class_name = $io->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 = $io->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 = $io->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) { // 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; } } $field_type = $io->choice($this->trans('commands.generate.plugin.fieldwidget.questions.field-type'), $field_type_options); $input->setOption('field-type', $field_type); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $modules = $input->getArgument('module'); $latest = $input->getOption('latest'); $path = $input->getOption('path'); $composer = $input->getOption('composer'); $unstable = true; if ($composer) { foreach ($modules as $module) { if (!$latest) { $versions = $this->getApplication()->getDrupalApi()->getPackagistModuleReleases($module, 10, $unstable); if (!$versions) { $io->error(sprintf($this->trans('commands.module.download.messages.no-releases'), $module)); return 1; } else { $version = $io->choice($this->trans('commands.site.new.questions.composer-release'), $versions); } } else { $versions = $this->getApplication()->getDrupalApi()->getPackagistModuleReleases($module, 10, $unstable); if (!$versions) { $io->error(sprintf($this->trans('commands.module.download.messages.no-releases'), $module)); return 1; } else { $version = current($this->getApplication()->getDrupalApi()->getPackagistModuleReleases($module, 1, $unstable)); } } $this->setComposerRepositories("default"); $command = sprintf('composer require drupal/%s:%s', $module, $version); $shellProcess = $this->get('shell_process'); if ($shellProcess->exec($command)) { $io->success(sprintf($this->trans('commands.module.download.messages.composer'), $module)); } } } else { $this->downloadModules($io, $modules, $latest, $path); } return true; }
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->choice($this->trans('commands.rest.disable.arguments.resource-id'), $rest_resources_ids); } $this->validateRestResource($resource_id, $rest_resources_ids, $this->translator); $resources = \Drupal::service('entity_type.manager')->getStorage('rest_resource_config')->loadMultiple(); if ($resources[$this->getResourceKey($resource_id)]) { $routeBuilder = \Drupal::service('router.builder'); $resources[$this->getResourceKey($resource_id)]->delete(); // Rebuild routing cache. $routeBuilder->rebuild(); $io->success(sprintf($this->trans('commands.rest.disable.messages.success'), $resource_id)); return true; } $message = sprintf($this->trans('commands.rest.disable.messages.already-disabled'), $resource_id); $io->info($message); return true; }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $vocabularies = $input->getArgument('vocabularies'); if (!$vocabularies) { $vocabularies = $this->getApplication()->getDrupalApi()->getVocabularies(); $vids = $io->choice($this->trans('commands.create.terms.questions.vocabularies'), array_values($vocabularies), null, true); $vids = array_map(function ($vid) use($vocabularies) { return array_search($vid, $vocabularies); }, $vids); $input->setArgument('vocabularies', $vids); } $limit = $input->getOption('limit'); if (!$limit) { $limit = $io->ask($this->trans('commands.create.terms.questions.limit'), 25); $input->setOption('limit', $limit); } $nameWords = $input->getOption('name-words'); if (!$nameWords) { $nameWords = $io->ask($this->trans('commands.create.terms.questions.name-words'), 5); $input->setOption('name-words', $nameWords); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); // profile option $profile = $input->getArgument('profile'); if (!$profile) { $profiles = $this->getProfiles(); $profile = $io->choice($this->trans('commands.site.install.questions.profile'), array_values($profiles)); $input->setArgument('profile', array_search($profile, $profiles)); } // --langcode option $langcode = $input->getOption('langcode'); if (!$langcode) { $languages = $this->getLanguages(); $defaultLanguage = $this->getDefaultLanguage(); $langcode = $io->choiceNoList($this->trans('commands.site.install.questions.langcode'), $languages, $languages[$defaultLanguage]); $input->setOption('langcode', $langcode); } // Use default database setting if is available $database = Database::getConnectionInfo(); if (empty($database['default'])) { // --db-type option $dbType = $input->getOption('db-type'); if (!$dbType) { $dbType = $this->dbTypeQuestion($io); $input->setOption('db-type', $dbType); } // --db-file option $dbFile = $input->getOption('db-file'); if ($dbType == 'sqlite' && !$dbFile) { $dbFile = $this->dbFileQuestion($io); $input->setOption('db-file', $dbFile); } else { // --db-host option $dbHost = $input->getOption('db-host'); if (!$dbHost) { $dbHost = $this->dbHostQuestion($io); $input->setOption('db-host', $dbHost); } // --db-name option $dbName = $input->getOption('db-name'); if (!$dbName) { $dbName = $this->dbNameQuestion($io); $input->setOption('db-name', $dbName); } // --db-user option $dbUser = $input->getOption('db-user'); if (!$dbUser) { $dbUser = $this->dbUserQuestion($io); $input->setOption('db-user', $dbUser); } // --db-pass option $dbPass = $input->getOption('db-pass'); if (!$dbPass) { $dbPass = $this->dbPassQuestion($io); $input->setOption('db-pass', $dbPass); } // --db-port prefix $dbPort = $input->getOption('db-port'); if (!$dbPort) { $dbPort = $this->dbPortQuestion($io); $input->setOption('db-port', $dbPort); } } // --db-prefix $dbPrefix = $input->getOption('db-prefix'); if (!$dbPrefix) { $dbPrefix = $this->dbPrefixQuestion($io); $input->setOption('db-prefix', $dbPrefix); } } else { $input->setOption('db-type', $database['default']['driver']); $input->setOption('db-host', $database['default']['host']); $input->setOption('db-name', $database['default']['database']); $input->setOption('db-user', $database['default']['username']); $input->setOption('db-pass', $database['default']['password']); $input->setOption('db-port', $database['default']['port']); $input->setOption('db-prefix', $database['default']['prefix']['default']); $io->info(sprintf($this->trans('commands.site.install.messages.using-current-database'), $database['default']['driver'], $database['default']['database'], $database['default']['username'])); } // --site-name option $site_name = $input->getOption('site-name'); if (!$site_name) { $site_name = $io->ask($this->trans('commands.site.install.questions.site-name'), 'Drupal 8 Site Install'); $input->setOption('site-name', $site_name); } // --site-mail option $site_mail = $input->getOption('site-mail'); if (!$site_mail) { $site_mail = $io->ask($this->trans('commands.site.install.questions.site-mail'), '*****@*****.**'); $input->setOption('site-mail', $site_mail); } // --account-name option $account_name = $input->getOption('account-name'); if (!$account_name) { $account_name = $io->ask($this->trans('commands.site.install.questions.account-name'), 'admin'); $input->setOption('account-name', $account_name); } // --account-mail option $account_mail = $input->getOption('account-mail'); if (!$account_mail) { $account_mail = $io->ask($this->trans('commands.site.install.questions.account-mail'), '*****@*****.**'); $input->setOption('account-mail', $account_mail); } // --account-pass option $account_pass = $input->getOption('account-pass'); if (!$account_pass) { $account_pass = $io->askHidden($this->trans('commands.site.install.questions.account-pass')); $input->setOption('account-pass', $account_pass); } }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); // --profile option $profile = $input->getArgument('profile'); if (!$profile) { $profiles = $this->extensionManager->discoverProfiles()->showCore()->showNoCore()->showInstalled()->showUninstalled()->getList(true); $profiles = array_filter($profiles, function ($profile) { return strpos($profile, 'testing') !== 0; }); $profile = $io->choice($this->trans('commands.site.install.questions.profile'), $profiles); $input->setArgument('profile', $profile); } // // --langcode option $langcode = $input->getOption('langcode'); if (!$langcode) { $languages = $this->site->getStandardLanguages(); $defaultLanguage = $this->configurationManager->getConfiguration()->get('application.language'); $langcode = $io->choiceNoList($this->trans('commands.site.install.questions.langcode'), $languages, $languages[$defaultLanguage]); $input->setOption('langcode', $langcode); } // Use default database setting if is available $database = Database::getConnectionInfo(); if (empty($database['default'])) { // --db-type option $dbType = $input->getOption('db-type'); if (!$dbType) { $databases = $this->site->getDatabaseTypes(); $dbType = $io->choice($this->trans('commands.migrate.setup.questions.db-type'), array_column($databases, 'name')); foreach ($databases as $dbIndex => $database) { if ($database['name'] == $dbType) { $dbType = $dbIndex; } } $input->setOption('db-type', $dbType); } if ($dbType === 'sqlite') { // --db-file option $dbFile = $input->getOption('db-file'); if (!$dbFile) { $dbFile = $io->ask($this->trans('commands.migrate.execute.questions.db-file'), 'sites/default/files/.ht.sqlite'); $input->setOption('db-file', $dbFile); } } else { // --db-host option $dbHost = $input->getOption('db-host'); if (!$dbHost) { $dbHost = $this->dbHostQuestion($io); $input->setOption('db-host', $dbHost); } // --db-name option $dbName = $input->getOption('db-name'); if (!$dbName) { $dbName = $this->dbNameQuestion($io); $input->setOption('db-name', $dbName); } // --db-user option $dbUser = $input->getOption('db-user'); if (!$dbUser) { $dbUser = $this->dbUserQuestion($io); $input->setOption('db-user', $dbUser); } // --db-pass option $dbPass = $input->getOption('db-pass'); if (!$dbPass) { $dbPass = $this->dbPassQuestion($io); $input->setOption('db-pass', $dbPass); } // --db-port prefix $dbPort = $input->getOption('db-port'); if (!$dbPort) { $dbPort = $this->dbPortQuestion($io); $input->setOption('db-port', $dbPort); } } // --db-prefix $dbPrefix = $input->getOption('db-prefix'); if (!$dbPrefix) { $dbPrefix = $this->dbPrefixQuestion($io); $input->setOption('db-prefix', $dbPrefix); } } else { $input->setOption('db-type', $database['default']['driver']); $input->setOption('db-host', $database['default']['host']); $input->setOption('db-name', $database['default']['database']); $input->setOption('db-user', $database['default']['username']); $input->setOption('db-pass', $database['default']['password']); $input->setOption('db-port', $database['default']['port']); $input->setOption('db-prefix', $database['default']['prefix']['default']); $io->info(sprintf($this->trans('commands.site.install.messages.using-current-database'), $database['default']['driver'], $database['default']['database'], $database['default']['username'])); } // --site-name option $siteName = $input->getOption('site-name'); if (!$siteName) { $siteName = $io->ask($this->trans('commands.site.install.questions.site-name'), 'Drupal 8 Site Install'); $input->setOption('site-name', $siteName); } // --site-mail option $siteMail = $input->getOption('site-mail'); if (!$siteMail) { $siteMail = $io->ask($this->trans('commands.site.install.questions.site-mail'), '*****@*****.**'); $input->setOption('site-mail', $siteMail); } // --account-name option $accountName = $input->getOption('account-name'); if (!$accountName) { $accountName = $io->ask($this->trans('commands.site.install.questions.account-name'), 'admin'); $input->setOption('account-name', $accountName); } // --account-pass option $accountPass = $input->getOption('account-pass'); if (!$accountPass) { $accountPass = $io->askHidden($this->trans('commands.site.install.questions.account-pass')); $input->setOption('account-pass', $accountPass); } // --account-mail option $accountMail = $input->getOption('account-mail'); if (!$accountMail) { $accountMail = $io->ask($this->trans('commands.site.install.questions.account-mail'), $siteMail); $input->setOption('account-mail', $accountMail); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $modules = $input->getArgument('module'); $latest = $input->getOption('latest'); $path = $input->getOption('path'); $composer = $input->getOption('composer'); $unstable = true; if ($composer) { foreach ($modules as $module) { if (!$latest) { $versions = $this->drupalApi->getPackagistModuleReleases($module, 10, $unstable); if (!$versions) { $io->error(sprintf($this->trans('commands.module.download.messages.no-releases'), $module)); return 1; } else { $version = $io->choice($this->trans('commands.site.new.questions.composer-release'), $versions); } } else { $versions = $this->drupalApi->getPackagistModuleReleases($module, 10, $unstable); if (!$versions) { $io->error(sprintf($this->trans('commands.module.download.messages.no-releases'), $module)); return 1; } else { $version = current($this->drupalApi->getPackagistModuleReleases($module, 1, $unstable)); } } // Register composer repository $command = "composer config repositories.drupal composer https://packagist.drupal-composer.org"; $this->shellProcess->exec($command, $this->root); $command = sprintf('composer require drupal/%s:%s --prefer-dist --optimize-autoloader --sort-packages --update-no-dev', $module, $version); if ($this->shellProcess->exec($command, $this->root)) { $io->success(sprintf($this->trans('commands.module.download.messages.composer'), $module)); } } } else { $this->downloadModules($io, $modules, $latest, $path); } return true; }
/** * @param DrupalStyle $io * * @return mixed */ public function dbDriverTypeQuestion(DrupalStyle $io) { $databases = $this->getDatabaseDrivers(); $dbType = $io->choice($this->trans('commands.migrate.setup.questions.db-type'), array_keys($databases)); return $dbType; }
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->translator); $input->setArgument('resource-id', $resource_id); // Calculate states available by resource and generate the question. $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]); $methods = $plugin->availableMethods(); $method = $io->choice($this->trans('commands.rest.enable.arguments.methods'), $methods); $io->writeln($this->trans('commands.rest.enable.messages.selected-method') . ' ' . $method); $format = $io->choice($this->trans('commands.rest.enable.arguments.formats'), $this->formats); $io->writeln($this->trans('commands.rest.enable.messages.selected-format') . ' ' . $format); // 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)); $format_resource_id = str_replace(':', '.', $resource_id); $config = $this->entityManager->getStorage('rest_resource_config')->load($format_resource_id); if (!$config) { $config = $this->entityManager->getStorage('rest_resource_config')->create(['id' => $format_resource_id, 'granularity' => RestResourceConfigInterface::METHOD_GRANULARITY, 'configuration' => []]); } $configuration = $config->get('configuration') ?: []; $configuration[$method] = ['supported_formats' => [$format], 'supported_auth' => $authenticationProvidersSelected]; $config->set('configuration', $configuration); $config->save(); $message = sprintf($this->trans('commands.rest.enable.messages.success'), $resource_id); $io->info($message); return true; }
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_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) { $states = array('GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'); $plugin_states = $io->choice($this->trans('commands.generate.plugin.rest.resource.questions.plugin-states'), $states, null, true); $input->setOption('plugin-states', $plugin_states); } }
/** * @param \Drupal\Console\Style\DrupalStyle $io * @param string $project * @param bool $latest * @param bool $stable * @return string */ public function releasesQuestion(DrupalStyle $io, $project, $latest = false, $stable = false) { $commandKey = str_replace(':', '.', $this->getName()); $io->comment(sprintf($this->trans('commands.' . $commandKey . '.messages.getting-releases'), implode(',', array($project)))); $releases = $this->drupalApi->getProjectReleases($this->httpClient, $project, $latest ? 1 : 15, $stable); if (!$releases) { $io->error(sprintf($this->trans('commands.' . $commandKey . '.messages.no-releases'), implode(',', array($project)))); return null; } if ($latest) { return $releases[0]; } $version = $io->choice($this->trans('commands.' . $commandKey . '.messages.select-release'), $releases); return $version; }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $username = $input->getArgument('username'); while (!$username) { $username = $io->askEmpty($this->trans('commands.user.create.questions.username'), null); } $input->setArgument('username', $username); $password = $input->getArgument('password'); if (!$password) { $password = $io->askEmpty($this->trans('commands.user.create.questions.password'), null); } $input->setArgument('password', $password); $roles = $input->getOption('roles'); if (!$roles) { $systemRoles = $this->drupalApi->getRoles(false, false, false); $roles = $io->choice($this->trans('commands.user.create.questions.roles'), array_values($systemRoles), null, true); $roles = array_map(function ($role) use($systemRoles) { return array_search($role, $systemRoles); }, $roles); $input->setOption('roles', $roles); } $email = $input->getOption('email'); if (!$email) { $email = $io->askEmpty($this->trans('commands.user.create.questions.email'), null); } $input->setOption('email', $email); $status = $input->getOption('status'); if (!$status) { $status = $io->choice($this->trans('commands.user.create.questions.status'), [0, 1], 1); } $input->setOption('status', $status); }