Пример #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $yes = $input->hasOption('yes') ? $input->getOption('yes') : false;
     // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
     if (!$this->confirmGeneration($io, $yes)) {
         return;
     }
     $module = $this->validator->validateModuleName($input->getOption('module'));
     $modulePath = $this->appRoot . $input->getOption('module-path');
     $modulePath = $this->validator->validateModulePath($modulePath, true);
     $machineName = $this->validator->validateMachineName($input->getOption('machine-name'));
     $description = $input->getOption('description');
     $core = $input->getOption('core');
     $package = $input->getOption('package');
     $moduleFile = $input->getOption('module-file');
     $featuresBundle = $input->getOption('features-bundle');
     $composer = $input->getOption('composer');
     // Modules Dependencies, re-factor and share with other commands
     $dependencies = $this->validator->validateModuleDependencies($input->getOption('dependencies'));
     // Check if all module dependencies are available
     if ($dependencies) {
         $checked_dependencies = $this->checkDependencies($dependencies['success']);
         if (!empty($checked_dependencies['no_modules'])) {
             $io->warning(sprintf($this->trans('commands.generate.module.warnings.module-unavailable'), implode(', ', $checked_dependencies['no_modules'])));
         }
         $dependencies = $dependencies['success'];
     }
     $this->generator->generate($module, $machineName, $modulePath, $description, $core, $package, $moduleFile, $featuresBundle, $composer, $dependencies);
 }
 /**
  * {@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($io);
         $input->setOption('module', $module);
     }
     // --bundle-name option
     $bundleName = $input->getOption('bundle-name');
     if (!$bundleName) {
         $bundleName = $io->ask($this->trans('commands.generate.entity.bundle.questions.bundle-name'), 'default', function ($bundleName) {
             return $this->validator->validateClassName($bundleName);
         });
         $input->setOption('bundle-name', $bundleName);
     }
     // --bundle-title option
     $bundleTitle = $input->getOption('bundle-title');
     if (!$bundleTitle) {
         $bundleTitle = $io->ask($this->trans('commands.generate.entity.bundle.questions.bundle-title'), 'default', function ($bundle_title) {
             return $this->validator->validateBundleTitle($bundle_title);
         });
         $input->setOption('bundle-title', $bundleTitle);
     }
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($io);
         $input->setOption('module', $module);
     }
     $pluginId = $input->getOption('plugin-id');
     if (!$pluginId) {
         $plugins = $this->getPlugins();
         $pluginId = $io->choiceNoList($this->trans('commands.generate.plugin.skeleton.questions.plugin'), $plugins);
         $input->setOption('plugin-id', $pluginId);
     }
     if (array_key_exists($pluginId, $this->pluginGeneratorsImplemented)) {
         $io->warning(sprintf($this->trans('commands.generate.plugin.skeleton.messages.plugin-dont-exist'), $pluginId, $this->pluginGeneratorsImplemented[$pluginId]));
     }
     // --class option
     $class = $input->getOption('class');
     if (!$class) {
         $class = $io->ask($this->trans('commands.generate.plugin.skeleton.options.class'), sprintf('%s%s', 'Default', ucfirst($this->stringConverter->underscoreToCamelCase($pluginId))), function ($class) {
             return $this->validator->validateClassName($class);
         });
         $input->setOption('class', $class);
     }
     // --services option
     // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
     $services = $input->getOption('services');
     if (!$services) {
         $services = $this->servicesQuestion($io);
         $input->setOption('services', $services);
     }
 }
Пример #4
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($io);
         $input->setOption('module', $module);
     }
     // --class option
     $class = $input->getOption('class');
     if (!$class) {
         $class = $io->ask($this->trans('commands.generate.plugin.mail.options.class'), 'HtmlFormatterMail', function ($class) {
             return $this->validator->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->stringConverter->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->stringConverter->camelCaseToUnderscore($class));
         $input->setOption('plugin-id', $pluginId);
     }
     // --services option
     // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
     $services = $this->servicesQuestion($io);
     $input->setOption('services', $services);
 }
Пример #5
0
 protected function validatePostUpdateName($module, $postUpdateName)
 {
     if (!$this->validator->validateSpaces($postUpdateName)) {
         throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.post.update.messages.wrong-post-update-name'), $postUpdateName));
     }
     if ($this->extensionManager->validateModuleFunctionExist($module, $module . '_post_update_' . $postUpdateName, $module . '.post_update.php')) {
         throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.post.update.messages.post-update-name-already-implemented'), $postUpdateName));
     }
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     if (!$this->confirmGeneration($io)) {
         return;
     }
     $profile = $this->validator->validateModuleName($input->getOption('profile'));
     $machine_name = $this->validator->validateMachineName($input->getOption('machine-name'));
     $description = $input->getOption('description');
     $core = $input->getOption('core');
     $distribution = $input->getOption('distribution');
     $profile_path = $this->appRoot . '/profiles';
     // Check if all module dependencies are available.
     $dependencies = $this->validator->validateModuleDependencies($input->getOption('dependencies'));
     if ($dependencies) {
         $checked_dependencies = $this->checkDependencies($dependencies['success']);
         if (!empty($checked_dependencies['no_modules'])) {
             $io->info(sprintf($this->trans('commands.generate.profile.warnings.module-unavailable'), implode(', ', $checked_dependencies['no_modules'])));
         }
         $dependencies = $dependencies['success'];
     }
     $this->generator->generate($profile, $machine_name, $profile_path, $description, $core, $dependencies, $distribution);
 }
Пример #7
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $theme = $this->configFactory->get('system.theme')->get('default');
     $themeRegions = \system_region_list($theme, REGIONS_VISIBLE);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($io);
         $input->setOption('module', $module);
     }
     // --class option
     $class = $input->getOption('class');
     if (!$class) {
         $class = $io->ask($this->trans('commands.generate.plugin.block.options.class'), 'DefaultBlock', function ($class) {
             return $this->validator->validateClassName($class);
             return $this->validator->validateClassName($class);
         });
         $input->setOption('class', $class);
     }
     // --label option
     $label = $input->getOption('label');
     if (!$label) {
         $label = $io->ask($this->trans('commands.generate.plugin.block.options.label'), $this->stringConverter->camelCaseToHuman($class));
         $input->setOption('label', $label);
     }
     // --plugin-id option
     $pluginId = $input->getOption('plugin-id');
     if (!$pluginId) {
         $pluginId = $io->ask($this->trans('commands.generate.plugin.block.options.plugin-id'), $this->stringConverter->camelCaseToUnderscore($class));
         $input->setOption('plugin-id', $pluginId);
     }
     // --theme-region option
     $themeRegion = $input->getOption('theme-region');
     if (!$themeRegion) {
         $themeRegion = $io->choiceNoList($this->trans('commands.generate.plugin.block.options.theme-region'), array_values($themeRegions), null, true);
         $themeRegion = array_search($themeRegion, $themeRegions);
         $input->setOption('theme-region', $themeRegion);
     }
     // --services option
     // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
     $services = $this->servicesQuestion($io);
     $input->setOption('services', $services);
     $output->writeln($this->trans('commands.generate.plugin.block.messages.inputs'));
     // @see Drupal\Console\Command\Shared\FormTrait::formQuestion
     $inputs = $this->formQuestion($io);
     $input->setOption('inputs', $inputs);
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         $module = $this->moduleQuestion($io);
         $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->validator->validateCommandName($class);
         });
         $input->setOption('class', $class);
     }
     // --container-aware option
     $containerAware = $input->getOption('container-aware');
     if (!$containerAware) {
         $containerAware = $io->confirm($this->trans('commands.generate.command.questions.container-aware'), false);
         $input->setOption('container-aware', $containerAware);
     }
     if (!$containerAware) {
         // --services option
         // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
         $services = $this->servicesQuestion($io);
         $input->setOption('services', $services);
     }
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     try {
         $theme = $input->getOption('theme') ? $this->validator->validateModuleName($input->getOption('theme')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
         return;
     }
     if (!$theme) {
         $validators = $this->validator;
         $theme = $io->ask($this->trans('commands.generate.theme.questions.theme'), '', function ($theme) use($validators) {
             return $validators->validateModuleName($theme);
         });
         $input->setOption('theme', $theme);
     }
     try {
         $machine_name = $input->getOption('machine-name') ? $this->validator->validateModule($input->getOption('machine-name')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
         return;
     }
     if (!$machine_name) {
         $machine_name = $io->ask($this->trans('commands.generate.module.questions.machine-name'), $this->stringConverter->createMachineName($theme), function ($machine_name) use($validators) {
             return $validators->validateMachineName($machine_name);
         });
         $input->setOption('machine-name', $machine_name);
     }
     $theme_path = $input->getOption('theme-path');
     if (!$theme_path) {
         $drupalRoot = $this->appRoot;
         $theme_path = $io->ask($this->trans('commands.generate.theme.questions.theme-path'), '/themes/custom', function ($theme_path) use($drupalRoot, $machine_name) {
             $theme_path = ($theme_path[0] != '/' ? '/' : '') . $theme_path;
             $full_path = $drupalRoot . $theme_path . '/' . $machine_name;
             if (file_exists($full_path)) {
                 throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.theme.errors.directory-exists'), $full_path));
             } else {
                 return $theme_path;
             }
         });
         $input->setOption('theme-path', $theme_path);
     }
     $description = $input->getOption('description');
     if (!$description) {
         $description = $io->ask($this->trans('commands.generate.theme.questions.description'), 'My Awesome theme');
         $input->setOption('description', $description);
     }
     $package = $input->getOption('package');
     if (!$package) {
         $package = $io->ask($this->trans('commands.generate.theme.questions.package'), 'Other');
         $input->setOption('package', $package);
     }
     $core = $input->getOption('core');
     if (!$core) {
         $core = $io->ask($this->trans('commands.generate.theme.questions.core'), '8.x');
         $input->setOption('core', $core);
     }
     $base_theme = $input->getOption('base-theme');
     if (!$base_theme) {
         $themes = $this->themeHandler->rebuildThemeData();
         $themes['false'] = '';
         uasort($themes, 'system_sort_modules_by_info_name');
         $base_theme = $io->choiceNoList($this->trans('commands.generate.theme.options.base-theme'), array_keys($themes));
         $input->setOption('base-theme', $base_theme);
     }
     $global_library = $input->getOption('global-library');
     if (!$global_library) {
         $global_library = $io->ask($this->trans('commands.generate.theme.questions.global-library'), 'global-styling');
         $input->setOption('global-library', $global_library);
     }
     // --regions option.
     $regions = $input->getOption('regions');
     if (!$regions) {
         if ($io->confirm($this->trans('commands.generate.theme.questions.regions'), true)) {
             // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion
             $regions = $this->regionQuestion($io);
             $input->setOption('regions', $regions);
         }
     }
     // --breakpoints option.
     $breakpoints = $input->getOption('breakpoints');
     if (!$breakpoints) {
         if ($io->confirm($this->trans('commands.generate.theme.questions.breakpoints'), true)) {
             // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion
             $breakpoints = $this->breakpointQuestion($io);
             $input->setOption('breakpoints', $breakpoints);
         }
     }
 }
 /**
  * {@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($io);
         $input->setOption('module', $module);
     }
     // --class option
     $class = $input->getOption('class');
     if (!$class) {
         $class = $io->ask($this->trans('commands.generate.controller.questions.class'), 'DefaultController', function ($class) {
             return $this->validator->validateClassName($class);
         });
         $input->setOption('class', $class);
     }
     $routes = $input->getOption('routes');
     if (!$routes) {
         while (true) {
             $title = $io->askEmpty($this->trans('commands.generate.controller.questions.title'), function ($title) use($routes) {
                 if ($routes && empty(trim($title))) {
                     return false;
                 }
                 if (!$routes && empty(trim($title))) {
                     throw new \InvalidArgumentException($this->trans('commands.generate.controller.messages.title-empty'));
                 }
                 if (in_array($title, array_column($routes, 'title'))) {
                     throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.controller.messages.title-already-added'), $title));
                 }
                 return $title;
             });
             if ($title === '') {
                 break;
             }
             $method = $io->ask($this->trans('commands.generate.controller.questions.method'), 'hello', function ($method) use($routes) {
                 if (in_array($method, array_column($routes, 'method'))) {
                     throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.controller.messages.method-already-added'), $method));
                 }
                 return $method;
             });
             $path = $io->ask($this->trans('commands.generate.controller.questions.path'), sprintf('/%s/hello/{name}', $module), function ($path) use($routes) {
                 if (count($this->routeProvider->getRoutesByPattern($path)) > 0 || in_array($path, array_column($routes, 'path'))) {
                     throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.controller.messages.path-already-added'), $path));
                 }
                 return $path;
             });
             $classMachineName = $this->stringConverter->camelCaseToMachineName($class);
             $routeName = $module . '.' . $classMachineName . '_' . $method;
             if ($this->routeProvider->getRoutesByNames([$routeName]) || in_array($routeName, $routes)) {
                 $routeName .= '_' . rand(0, 100);
             }
             $routes[] = ['title' => $title, 'name' => $routeName, 'method' => $method, 'path' => $path];
         }
         $input->setOption('routes', $routes);
     }
     // --test option
     $test = $input->getOption('test');
     if (!$test) {
         $test = $io->confirm($this->trans('commands.generate.controller.questions.test'), true);
         $input->setOption('test', $test);
     }
     // --services option
     // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
     $services = $this->servicesQuestion($io);
     $input->setOption('services', $services);
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $validator = $this->validator;
     try {
         $module = $input->getOption('module') ? $this->validator->validateModuleName($input->getOption('module')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
         return;
     }
     if (!$module) {
         $module = $io->ask($this->trans('commands.generate.module.questions.module'), null, function ($module) use($validator) {
             return $validator->validateModuleName($module);
         });
         $input->setOption('module', $module);
     }
     try {
         $machineName = $input->getOption('machine-name') ? $this->validator->validateModuleName($input->getOption('machine-name')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
     }
     if (!$machineName) {
         $machineName = $io->ask($this->trans('commands.generate.module.questions.machine-name'), $this->stringConverter->createMachineName($module), function ($machine_name) use($validator) {
             return $validator->validateMachineName($machine_name);
         });
         $input->setOption('machine-name', $machineName);
     }
     $modulePath = $input->getOption('module-path');
     if (!$modulePath) {
         $drupalRoot = $this->appRoot;
         $modulePath = $io->ask($this->trans('commands.generate.module.questions.module-path'), '/modules/custom', function ($modulePath) use($drupalRoot, $machineName) {
             $modulePath = ($modulePath[0] != '/' ? '/' : '') . $modulePath;
             $fullPath = $drupalRoot . $modulePath . '/' . $machineName;
             if (file_exists($fullPath)) {
                 throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.module.errors.directory-exists'), $fullPath));
             }
             return $modulePath;
         });
     }
     $input->setOption('module-path', $modulePath);
     $description = $input->getOption('description');
     if (!$description) {
         $description = $io->ask($this->trans('commands.generate.module.questions.description'), 'My Awesome Module');
     }
     $input->setOption('description', $description);
     $package = $input->getOption('package');
     if (!$package) {
         $package = $io->ask($this->trans('commands.generate.module.questions.package'), 'Custom');
     }
     $input->setOption('package', $package);
     $core = $input->getOption('core');
     if (!$core) {
         $core = $io->ask($this->trans('commands.generate.module.questions.core'), '8.x', function ($core) {
             // Only allow 8.x and higher as core version.
             if (!preg_match('/^([0-9]+)\\.x$/', $core, $matches) || $matches[1] < 8) {
                 throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.module.errors.invalid-core'), $core));
             }
             return $core;
         });
         $input->setOption('core', $core);
     }
     $moduleFile = $input->getOption('module-file');
     if (!$moduleFile) {
         $moduleFile = $io->confirm($this->trans('commands.generate.module.questions.module-file'), true);
         $input->setOption('module-file', $moduleFile);
     }
     $featuresBundle = $input->getOption('features-bundle');
     if (!$featuresBundle) {
         $featuresSupport = $io->confirm($this->trans('commands.generate.module.questions.features-support'), false);
         if ($featuresSupport) {
             $featuresBundle = $io->ask($this->trans('commands.generate.module.questions.features-bundle'), 'default');
         }
         $input->setOption('features-bundle', $featuresBundle);
     }
     $composer = $input->getOption('composer');
     if (!$composer) {
         $composer = $io->confirm($this->trans('commands.generate.module.questions.composer'), true);
         $input->setOption('composer', $composer);
     }
     $dependencies = $input->getOption('dependencies');
     if (!$dependencies) {
         $addDependencies = $io->confirm($this->trans('commands.generate.module.questions.dependencies'), false);
         if ($addDependencies) {
             $dependencies = $io->ask($this->trans('commands.generate.module.options.dependencies'));
         }
         $input->setOption('dependencies', $dependencies);
     }
     $test = $input->getOption('test');
     if (!$test) {
         $test = $io->confirm($this->trans('commands.generate.module.questions.test'), true);
         $input->setOption('test', $test);
     }
 }