From f9d0fa290adf24a5d3f5410669766800f2be9609 Mon Sep 17 00:00:00 2001 From: enzo - Eduardo Garcia Date: Wed, 12 Jul 2017 08:45:24 +1000 Subject: [PATCH 1/2] Removed generate commands and generators --- config/services/database.yml | 6 + config/services/generate.yml | 247 ----------- config/services/generator.yml | 244 ----------- .../AuthenticationProviderCommand.php | 158 ------- src/Command/Generate/BreakPointCommand.php | 172 -------- src/Command/Generate/CacheContextCommand.php | 174 -------- src/Command/Generate/CommandCommand.php | 224 ---------- .../Generate/ConfigFormBaseCommand.php | 91 ---- src/Command/Generate/ControllerCommand.php | 320 -------------- src/Command/Generate/EntityBundleCommand.php | 151 ------- src/Command/Generate/EntityCommand.php | 176 -------- src/Command/Generate/EntityConfigCommand.php | 101 ----- src/Command/Generate/EntityContentCommand.php | 174 -------- .../Generate/EventSubscriberCommand.php | 197 --------- src/Command/Generate/FormAlterCommand.php | 324 -------------- src/Command/Generate/FormBaseCommand.php | 18 - src/Command/Generate/FormCommand.php | 330 -------------- src/Command/Generate/HelpCommand.php | 148 ------- src/Command/Generate/ModuleCommand.php | 409 ------------------ src/Command/Generate/ModuleFileCommand.php | 115 ----- src/Command/Generate/PermissionCommand.php | 122 ------ src/Command/Generate/PluginBlockCommand.php | 292 ------------- .../Generate/PluginCKEditorButtonCommand.php | 207 --------- .../Generate/PluginConditionCommand.php | 253 ----------- src/Command/Generate/PluginFieldCommand.php | 346 --------------- .../Generate/PluginFieldFormatterCommand.php | 205 --------- .../Generate/PluginFieldTypeCommand.php | 221 ---------- .../Generate/PluginFieldWidgetCommand.php | 210 --------- .../Generate/PluginImageEffectCommand.php | 185 -------- .../Generate/PluginImageFormatterCommand.php | 172 -------- src/Command/Generate/PluginMailCommand.php | 198 --------- .../Generate/PluginMigrateProcessCommand.php | 147 ------- .../Generate/PluginMigrateSourceCommand.php | 267 ------------ .../Generate/PluginRestResourceCommand.php | 225 ---------- .../Generate/PluginRulesActionCommand.php | 220 ---------- .../Generate/PluginSkeletonCommand.php | 384 ---------------- .../Generate/PluginTypeAnnotationCommand.php | 153 ------- .../Generate/PluginTypeYamlCommand.php | 154 ------- .../Generate/PluginViewsFieldCommand.php | 185 -------- src/Command/Generate/PostUpdateCommand.php | 198 --------- src/Command/Generate/ProfileCommand.php | 270 ------------ .../Generate/RouteSubscriberCommand.php | 158 ------- src/Command/Generate/ServiceCommand.php | 244 ----------- src/Command/Generate/ThemeCommand.php | 383 ---------------- src/Command/Generate/TwigExtensionCommand.php | 192 -------- src/Command/Generate/UpdateCommand.php | 199 --------- .../AuthenticationProviderGenerator.php | 75 ---- src/Generator/BreakPointGenerator.php | 61 --- src/Generator/CacheContextGenerator.php | 64 --- src/Generator/CommandGenerator.php | 94 ---- src/Generator/ControllerGenerator.php | 62 --- src/Generator/EntityBundleGenerator.php | 86 ---- src/Generator/EntityConfigGenerator.php | 109 ----- src/Generator/EntityContentGenerator.php | 291 ------------- src/Generator/EventSubscriberGenerator.php | 66 --- src/Generator/FormAlterGenerator.php | 57 --- src/Generator/FormGenerator.php | 114 ----- src/Generator/HelpGenerator.php | 54 --- src/Generator/ModuleFileGenerator.php | 53 --- src/Generator/ModuleGenerator.php | 188 -------- src/Generator/PermissionGenerator.php | 60 --- src/Generator/PluginBlockGenerator.php | 89 ---- .../PluginCKEditorButtonGenerator.php | 57 --- src/Generator/PluginConditionGenerator.php | 66 --- .../PluginFieldFormatterGenerator.php | 51 --- src/Generator/PluginFieldTypeGenerator.php | 55 --- src/Generator/PluginFieldWidgetGenerator.php | 51 --- src/Generator/PluginImageEffectGenerator.php | 51 --- .../PluginImageFormatterGenerator.php | 50 --- src/Generator/PluginMailGenerator.php | 51 --- .../PluginMigrateProcessGenerator.php | 52 --- .../PluginMigrateSourceGenerator.php | 60 --- src/Generator/PluginRestResourceGenerator.php | 59 --- src/Generator/PluginRulesActionGenerator.php | 65 --- src/Generator/PluginSkeletonGenerator.php | 61 --- .../PluginTypeAnnotationGenerator.php | 85 ---- src/Generator/PluginTypeYamlGenerator.php | 74 ---- src/Generator/PluginViewsFieldGenerator.php | 62 --- src/Generator/PostUpdateGenerator.php | 54 --- src/Generator/ProfileGenerator.php | 83 ---- src/Generator/RouteSubscriberGenerator.php | 62 --- src/Generator/ServiceGenerator.php | 102 ----- src/Generator/ThemeGenerator.php | 118 ----- src/Generator/TwigExtensionGenerator.php | 69 --- src/Generator/UpdateGenerator.php | 55 --- 85 files changed, 6 insertions(+), 12579 deletions(-) delete mode 100644 config/services/generate.yml delete mode 100644 config/services/generator.yml delete mode 100644 src/Command/Generate/AuthenticationProviderCommand.php delete mode 100644 src/Command/Generate/BreakPointCommand.php delete mode 100644 src/Command/Generate/CacheContextCommand.php delete mode 100644 src/Command/Generate/CommandCommand.php delete mode 100644 src/Command/Generate/ConfigFormBaseCommand.php delete mode 100644 src/Command/Generate/ControllerCommand.php delete mode 100644 src/Command/Generate/EntityBundleCommand.php delete mode 100644 src/Command/Generate/EntityCommand.php delete mode 100644 src/Command/Generate/EntityConfigCommand.php delete mode 100644 src/Command/Generate/EntityContentCommand.php delete mode 100644 src/Command/Generate/EventSubscriberCommand.php delete mode 100644 src/Command/Generate/FormAlterCommand.php delete mode 100644 src/Command/Generate/FormBaseCommand.php delete mode 100644 src/Command/Generate/FormCommand.php delete mode 100644 src/Command/Generate/HelpCommand.php delete mode 100644 src/Command/Generate/ModuleCommand.php delete mode 100644 src/Command/Generate/ModuleFileCommand.php delete mode 100644 src/Command/Generate/PermissionCommand.php delete mode 100644 src/Command/Generate/PluginBlockCommand.php delete mode 100644 src/Command/Generate/PluginCKEditorButtonCommand.php delete mode 100644 src/Command/Generate/PluginConditionCommand.php delete mode 100644 src/Command/Generate/PluginFieldCommand.php delete mode 100644 src/Command/Generate/PluginFieldFormatterCommand.php delete mode 100644 src/Command/Generate/PluginFieldTypeCommand.php delete mode 100644 src/Command/Generate/PluginFieldWidgetCommand.php delete mode 100644 src/Command/Generate/PluginImageEffectCommand.php delete mode 100644 src/Command/Generate/PluginImageFormatterCommand.php delete mode 100644 src/Command/Generate/PluginMailCommand.php delete mode 100644 src/Command/Generate/PluginMigrateProcessCommand.php delete mode 100644 src/Command/Generate/PluginMigrateSourceCommand.php delete mode 100644 src/Command/Generate/PluginRestResourceCommand.php delete mode 100644 src/Command/Generate/PluginRulesActionCommand.php delete mode 100644 src/Command/Generate/PluginSkeletonCommand.php delete mode 100644 src/Command/Generate/PluginTypeAnnotationCommand.php delete mode 100644 src/Command/Generate/PluginTypeYamlCommand.php delete mode 100644 src/Command/Generate/PluginViewsFieldCommand.php delete mode 100644 src/Command/Generate/PostUpdateCommand.php delete mode 100644 src/Command/Generate/ProfileCommand.php delete mode 100644 src/Command/Generate/RouteSubscriberCommand.php delete mode 100644 src/Command/Generate/ServiceCommand.php delete mode 100644 src/Command/Generate/ThemeCommand.php delete mode 100644 src/Command/Generate/TwigExtensionCommand.php delete mode 100644 src/Command/Generate/UpdateCommand.php delete mode 100644 src/Generator/AuthenticationProviderGenerator.php delete mode 100644 src/Generator/BreakPointGenerator.php delete mode 100644 src/Generator/CacheContextGenerator.php delete mode 100644 src/Generator/CommandGenerator.php delete mode 100644 src/Generator/ControllerGenerator.php delete mode 100644 src/Generator/EntityBundleGenerator.php delete mode 100644 src/Generator/EntityConfigGenerator.php delete mode 100644 src/Generator/EntityContentGenerator.php delete mode 100644 src/Generator/EventSubscriberGenerator.php delete mode 100644 src/Generator/FormAlterGenerator.php delete mode 100644 src/Generator/FormGenerator.php delete mode 100644 src/Generator/HelpGenerator.php delete mode 100644 src/Generator/ModuleFileGenerator.php delete mode 100644 src/Generator/ModuleGenerator.php delete mode 100644 src/Generator/PermissionGenerator.php delete mode 100644 src/Generator/PluginBlockGenerator.php delete mode 100644 src/Generator/PluginCKEditorButtonGenerator.php delete mode 100644 src/Generator/PluginConditionGenerator.php delete mode 100644 src/Generator/PluginFieldFormatterGenerator.php delete mode 100644 src/Generator/PluginFieldTypeGenerator.php delete mode 100644 src/Generator/PluginFieldWidgetGenerator.php delete mode 100644 src/Generator/PluginImageEffectGenerator.php delete mode 100644 src/Generator/PluginImageFormatterGenerator.php delete mode 100644 src/Generator/PluginMailGenerator.php delete mode 100644 src/Generator/PluginMigrateProcessGenerator.php delete mode 100644 src/Generator/PluginMigrateSourceGenerator.php delete mode 100644 src/Generator/PluginRestResourceGenerator.php delete mode 100644 src/Generator/PluginRulesActionGenerator.php delete mode 100644 src/Generator/PluginSkeletonGenerator.php delete mode 100644 src/Generator/PluginTypeAnnotationGenerator.php delete mode 100644 src/Generator/PluginTypeYamlGenerator.php delete mode 100644 src/Generator/PluginViewsFieldGenerator.php delete mode 100644 src/Generator/PostUpdateGenerator.php delete mode 100644 src/Generator/ProfileGenerator.php delete mode 100644 src/Generator/RouteSubscriberGenerator.php delete mode 100644 src/Generator/ServiceGenerator.php delete mode 100644 src/Generator/ThemeGenerator.php delete mode 100644 src/Generator/TwigExtensionGenerator.php delete mode 100644 src/Generator/UpdateGenerator.php diff --git a/config/services/database.yml b/config/services/database.yml index 573eda99c..2a4f2eb74 100644 --- a/config/services/database.yml +++ b/config/services/database.yml @@ -1,4 +1,10 @@ services: + console.database_settings_generator: + class: Drupal\Console\Generator\DatabaseSettingsGenerator + arguments: ['@kernel'] + tags: + - { name: drupal.generator } + lazy: true console.database_add: class: Drupal\Console\Command\Database\AddCommand arguments: ['@console.database_settings_generator'] diff --git a/config/services/generate.yml b/config/services/generate.yml deleted file mode 100644 index 35b47fa17..000000000 --- a/config/services/generate.yml +++ /dev/null @@ -1,247 +0,0 @@ -services: - console.generate_module: - class: Drupal\Console\Command\Generate\ModuleCommand - arguments: ['@console.module_generator', '@console.validator', '@app.root', '@console.string_converter', '@console.drupal_api'] - tags: - - { name: drupal.command } - lazy: true - console.generate_modulefile: - class: Drupal\Console\Command\Generate\ModuleFileCommand - arguments: ['@console.extension_manager', '@console.modulefile_generator'] - tags: - - { name: drupal.command } - lazy: true - console.generate_authentication_provider: - class: Drupal\Console\Command\Generate\AuthenticationProviderCommand - arguments: ['@console.extension_manager', '@console.authentication_provider_generator', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_controller: - class: Drupal\Console\Command\Generate\ControllerCommand - arguments: ['@console.extension_manager', '@console.controller_generator', '@console.string_converter', '@console.validator', '@router.route_provider', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_breakpoint: - class: Drupal\Console\Command\Generate\BreakPointCommand - arguments: ['@console.breakpoint_generator', '@app.root', '@theme_handler', '@console.validator', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_help: - class: Drupal\Console\Command\Generate\HelpCommand - arguments: ['@console.help_generator', '@console.site', '@console.extension_manager', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_form: - class: Drupal\Console\Command\Generate\FormBaseCommand - arguments: ['@console.extension_manager', '@console.form_generator', '@console.chain_queue', '@console.string_converter', '@plugin.manager.element_info', '@router.route_provider'] - tags: - - { name: drupal.command } - lazy: true - console.generate_form_alter: - class: Drupal\Console\Command\Generate\FormAlterCommand - arguments: ['@console.extension_manager', '@console.form_alter_generator', '@console.string_converter', '@module_handler', '@plugin.manager.element_info', '@?profiler', '@app.root', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_permissions: - class: Drupal\Console\Command\Generate\PermissionCommand - arguments: ['@console.extension_manager', '@console.string_converter', '@console.permission_generator'] - tags: - - { name: drupal.command } - lazy: true - console.generate_event_subscriber: - class: Drupal\Console\Command\Generate\EventSubscriberCommand - arguments: ['@console.extension_manager', '@console.event_subscriber_generator', '@console.string_converter', '@event_dispatcher', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_form_config: - class: Drupal\Console\Command\Generate\ConfigFormBaseCommand - arguments: ['@console.extension_manager', '@console.form_generator', '@console.string_converter', '@router.route_provider', '@plugin.manager.element_info', '@app.root', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_type_annotation: - class: Drupal\Console\Command\Generate\PluginTypeAnnotationCommand - arguments: ['@console.extension_manager', '@console.plugin_type_annotation_generator', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_condition: - class: Drupal\Console\Command\Generate\PluginConditionCommand - arguments: ['@console.extension_manager', '@console.plugin_condition_generator', '@console.chain_queue', '@entity_type.repository', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_field: - class: Drupal\Console\Command\Generate\PluginFieldCommand - arguments: ['@console.extension_manager','@console.string_converter', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_field_formatter: - class: Drupal\Console\Command\Generate\PluginFieldFormatterCommand - arguments: ['@console.extension_manager', '@console.plugin_field_formatter_generator','@console.string_converter', '@plugin.manager.field.field_type', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_field_type: - class: Drupal\Console\Command\Generate\PluginFieldTypeCommand - arguments: ['@console.extension_manager', '@console.plugin_field_type_generator','@console.string_converter', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_field_widget: - class: Drupal\Console\Command\Generate\PluginFieldWidgetCommand - arguments: ['@console.extension_manager', '@console.plugin_field_widget_generator','@console.string_converter', '@plugin.manager.field.field_type', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_image_effect: - class: Drupal\Console\Command\Generate\PluginImageEffectCommand - arguments: ['@console.extension_manager', '@console.plugin_image_effect_generator','@console.string_converter', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_image_formatter: - class: Drupal\Console\Command\Generate\PluginImageFormatterCommand - arguments: ['@console.extension_manager', '@console.plugin_image_formatter_generator','@console.string_converter', '@console.validator', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_mail: - class: Drupal\Console\Command\Generate\PluginMailCommand - arguments: ['@console.extension_manager', '@console.plugin_mail_generator','@console.string_converter', '@console.validator', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_migrate_source: - class: Drupal\Console\Command\Generate\PluginMigrateSourceCommand - arguments: ['@config.factory', '@console.chain_queue', '@console.plugin_migrate_source_generator', '@entity_type.manager', '@console.extension_manager', '@console.validator', '@console.string_converter', '@plugin.manager.element_info'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_migrate_process: - class: Drupal\Console\Command\Generate\PluginMigrateProcessCommand - arguments: [ '@console.plugin_migrate_process_generator', '@console.chain_queue', '@console.extension_manager', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_rest_resource: - class: Drupal\Console\Command\Generate\PluginRestResourceCommand - arguments: ['@console.extension_manager', '@console.plugin_rest_resource_generator','@console.string_converter', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_rules_action: - class: Drupal\Console\Command\Generate\PluginRulesActionCommand - arguments: ['@console.extension_manager', '@console.plugin_rules_action_generator','@console.string_converter', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_skeleton: - class: Drupal\Console\Command\Generate\PluginSkeletonCommand - arguments: ['@console.extension_manager', '@console.plugin_skeleton_generator','@console.string_converter', '@console.validator', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_type_yaml: - class: Drupal\Console\Command\Generate\PluginTypeYamlCommand - arguments: ['@console.extension_manager', '@console.plugin_type_yaml_generator','@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_plugin_views_field: - class: Drupal\Console\Command\Generate\PluginViewsFieldCommand - arguments: ['@console.extension_manager', '@console.plugin_views_field_generator', '@console.site','@console.string_converter','@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_post_update: - class: Drupal\Console\Command\Generate\PostUpdateCommand - arguments: ['@console.extension_manager', '@console.post_update_generator', '@console.site', '@console.validator','@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_profile: - class: Drupal\Console\Command\Generate\ProfileCommand - arguments: ['@console.extension_manager', '@console.profile_generator', '@console.string_converter', '@console.validator', '@app.root'] - tags: - - { name: drupal.command } - lazy: true - console.generate_route_subscriber: - class: Drupal\Console\Command\Generate\RouteSubscriberCommand - arguments: ['@console.extension_manager', '@console.route_subscriber_generator', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_service: - class: Drupal\Console\Command\Generate\ServiceCommand - arguments: ['@console.extension_manager', '@console.service_generator', '@console.string_converter', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_theme: - class: Drupal\Console\Command\Generate\ThemeCommand - arguments: ['@console.extension_manager', '@console.theme_generator', '@console.validator', '@app.root', '@theme_handler', '@console.site', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_twig_extension: - class: Drupal\Console\Command\Generate\TwigExtensionCommand - arguments: ['@console.extension_manager', '@console.twig_extension_generator', '@console.site', '@console.string_converter', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_update: - class: Drupal\Console\Command\Generate\UpdateCommand - arguments: ['@console.extension_manager', '@console.update_generator', '@console.site', '@console.chain_queue'] - tags: - - { name: drupal.command } - lazy: true - console.generate_pluginblock: - class: Drupal\Console\Command\Generate\PluginBlockCommand - arguments: ['@config.factory', '@console.chain_queue', '@console.pluginblock_generator', '@entity_type.manager', '@console.extension_manager', '@console.validator', '@console.string_converter', '@plugin.manager.element_info'] - tags: - - { name: drupal.command } - lazy: true - console.generate_command: - class: Drupal\Console\Command\Generate\CommandCommand - arguments: ['@console.command_generator', '@console.extension_manager', '@console.validator', '@console.string_converter', '@console.site'] - tags: - - { name: drupal.command } - lazy: true - console.generate_ckeditorbutton: - class: Drupal\Console\Command\Generate\PluginCKEditorButtonCommand - arguments: ['@console.chain_queue', '@console.command_ckeditorbutton', '@console.extension_manager', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_entitycontent: - class: Drupal\Console\Command\Generate\EntityContentCommand - arguments: ['@console.chain_queue', '@console.entitycontent_generator', '@console.string_converter', '@console.extension_manager', '@console.validator'] - tags: - - { name: drupal.command } - lazy: true - console.generate_entitybundle: - class: Drupal\Console\Command\Generate\EntityBundleCommand - arguments: ['@console.validator', '@console.entitybundle_generator', '@console.extension_manager'] - tags: - - { name: drupal.command } - lazy: true - console.generate_entityconfig: - class: Drupal\Console\Command\Generate\EntityConfigCommand - arguments: ['@console.extension_manager', '@console.entityconfig_generator', '@console.validator', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true - console.generate_cache_context: - class: Drupal\Console\Command\Generate\CacheContextCommand - arguments: [ '@console.cache_context_generator', '@console.chain_queue', '@console.extension_manager', '@console.string_converter'] - tags: - - { name: drupal.command } - lazy: true diff --git a/config/services/generator.yml b/config/services/generator.yml deleted file mode 100644 index aa2b56c7d..000000000 --- a/config/services/generator.yml +++ /dev/null @@ -1,244 +0,0 @@ -services: - console.module_generator: - class: Drupal\Console\Generator\ModuleGenerator - tags: - - { name: drupal.generator } - lazy: true - console.modulefile_generator: - class: Drupal\Console\Generator\ModuleFileGenerator - tags: - - { name: drupal.generator } - lazy: true - console.authentication_provider_generator: - class: Drupal\Console\Generator\AuthenticationProviderGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.help_generator: - class: Drupal\Console\Generator\HelpGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.controller_generator: - class: Drupal\Console\Generator\ControllerGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.breakpoint_generator: - class: Drupal\Console\Generator\BreakPointGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.form_alter_generator: - class: Drupal\Console\Generator\FormAlterGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.permission_generator: - class: Drupal\Console\Generator\PermissionGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.event_subscriber_generator: - class: Drupal\Console\Generator\EventSubscriberGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.form_generator: - class: Drupal\Console\Generator\FormGenerator - arguments: ['@console.extension_manager', '@console.string_converter'] - tags: - - { name: drupal.generator } - lazy: true - console.profile_generator: - class: Drupal\Console\Generator\ProfileGenerator - tags: - - { name: drupal.generator } - lazy: true - console.post_update_generator: - class: Drupal\Console\Generator\PostUpdateGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_condition_generator: - class: Drupal\Console\Generator\PluginConditionGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_field_generator: - class: Drupal\Console\Generator\PluginFieldFormatterGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_field_formatter_generator: - class: Drupal\Console\Generator\PluginFieldFormatterGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_field_type_generator: - class: Drupal\Console\Generator\PluginFieldTypeGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_field_widget_generator: - class: Drupal\Console\Generator\PluginFieldWidgetGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_image_effect_generator: - class: Drupal\Console\Generator\PluginImageEffectGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_image_formatter_generator: - class: Drupal\Console\Generator\PluginImageFormatterGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_mail_generator: - class: Drupal\Console\Generator\PluginMailGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_migrate_source_generator: - class: Drupal\Console\Generator\PluginMigrateSourceGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_migrate_process_generator: - class: Drupal\Console\Generator\PluginMigrateProcessGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_rest_resource_generator: - class: Drupal\Console\Generator\PluginRestResourceGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_rules_action_generator: - class: Drupal\Console\Generator\PluginRulesActionGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_skeleton_generator: - class: Drupal\Console\Generator\PluginSkeletonGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_views_field_generator: - class: Drupal\Console\Generator\PluginViewsFieldGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_type_annotation_generator: - class: Drupal\Console\Generator\PluginTypeAnnotationGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.plugin_type_yaml_generator: - class: Drupal\Console\Generator\PluginTypeYamlGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.route_subscriber_generator: - class: Drupal\Console\Generator\RouteSubscriberGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.service_generator: - class: Drupal\Console\Generator\ServiceGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.theme_generator: - class: Drupal\Console\Generator\ThemeGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.twig_extension_generator: - class: Drupal\Console\Generator\TwigExtensionGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.update_generator: - class: Drupal\Console\Generator\UpdateGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.pluginblock_generator: - class: Drupal\Console\Generator\PluginBlockGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.command_generator: - class: Drupal\Console\Generator\CommandGenerator - arguments: ['@console.extension_manager', '@console.translator_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.command_ckeditorbutton: - class: Drupal\Console\Generator\PluginCKEditorButtonGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.database_settings_generator: - class: Drupal\Console\Generator\DatabaseSettingsGenerator - arguments: ['@kernel'] - tags: - - { name: drupal.generator } - lazy: true - console.entitycontent_generator: - class: Drupal\Console\Generator\EntityContentGenerator - arguments: ['@console.extension_manager', '@console.site', '@console.renderer'] - tags: - - { name: drupal.generator } - lazy: true - console.entitybundle_generator: - class: Drupal\Console\Generator\EntityBundleGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.entityconfig_generator: - class: Drupal\Console\Generator\EntityConfigGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true - console.cache_context_generator: - class: Drupal\Console\Generator\CacheContextGenerator - arguments: ['@console.extension_manager'] - tags: - - { name: drupal.generator } - lazy: true diff --git a/src/Command/Generate/AuthenticationProviderCommand.php b/src/Command/Generate/AuthenticationProviderCommand.php deleted file mode 100644 index 8e6e2a027..000000000 --- a/src/Command/Generate/AuthenticationProviderCommand.php +++ /dev/null @@ -1,158 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:authentication:provider') - ->setDescription($this->trans('commands.generate.authentication.provider.description')) - ->setHelp($this->trans('commands.generate.authentication.provider.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.authentication.provider.options.class') - ) - ->addOption( - 'provider-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.authentication.provider.options.provider-id') - ) - ->setAliases(['gap']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class = $input->getOption('class'); - $provider_id = $input->getOption('provider-id'); - - $this->generator->generate($module, $class, $provider_id); - - return 0; - } - - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $stringUtils = $this->stringConverter; - - // --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.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); - } - } -} diff --git a/src/Command/Generate/BreakPointCommand.php b/src/Command/Generate/BreakPointCommand.php deleted file mode 100644 index bb53df8ef..000000000 --- a/src/Command/Generate/BreakPointCommand.php +++ /dev/null @@ -1,172 +0,0 @@ -generator = $generator; - $this->appRoot = $appRoot; - $this->themeHandler = $themeHandler; - $this->validator = $validator; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:breakpoint') - ->setDescription($this->trans('commands.generate.breakpoint.description')) - ->setHelp($this->trans('commands.generate.breakpoint.help')) - ->addOption( - 'theme', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.breakpoint.options.theme') - ) - ->addOption( - 'breakpoints', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.breakpoint.options.breakpoints') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $validators = $this->validator; - // we must to ensure theme exist - $machine_name = $validators->validateMachineName($input->getOption('theme')); - $theme_path = $drupal_root . $input->getOption('theme'); - $breakpoints = $input->getOption('breakpoints'); - - $this->generator->generate( - $theme_path, - $breakpoints, - $machine_name - ); - - return 0; - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $drupalRoot = $this->appRoot; - - // --base-theme option. - $base_theme = $input->getOption('theme'); - - if (!$base_theme) { - $themeHandler = $this->themeHandler; - $themes = $themeHandler->rebuildThemeData(); - $themes['classy'] =''; - - uasort($themes, 'system_sort_modules_by_info_name'); - - $base_theme = $io->choiceNoList( - $this->trans('commands.generate.breakpoint.questions.theme'), - array_keys($themes) - ); - $input->setOption('theme', $base_theme); - } - - // --breakpoints option. - $breakpoints = $input->getOption('breakpoints'); - if (!$breakpoints) { - $breakpoints = $this->breakpointQuestion($io); - $input->setOption('breakpoints', $breakpoints); - } - } -} diff --git a/src/Command/Generate/CacheContextCommand.php b/src/Command/Generate/CacheContextCommand.php deleted file mode 100644 index 5ca9c0137..000000000 --- a/src/Command/Generate/CacheContextCommand.php +++ /dev/null @@ -1,174 +0,0 @@ -generator = $generator; - $this->chainQueue = $chainQueue; - $this->extensionManager = $extensionManager; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:cache:context') - ->setDescription($this->trans('commands.generate.cache.context.description')) - ->setHelp($this->trans('commands.generate.cache.context.description')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module')) - ->addOption( - 'cache-context', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.cache.context.questions.name') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.cache.context.questions.class') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $cache_context = $input->getOption('cache-context'); - $class = $input->getOption('class'); - $services = $input->getOption('services'); - - // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices - $buildServices = $this->buildServices($services); - - $this->generator->generate($module, $cache_context, $class, $buildServices); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); - } - - /** - * {@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); - } - - // --cache_context option - $cache_context = $input->getOption('cache-context'); - if (!$cache_context) { - $cache_context = $io->ask( - $this->trans('commands.generate.cache.context.questions.name'), - sprintf('%s', $module) - ); - $input->setOption('cache-context', $cache_context); - } - - // --class option - $class = $input->getOption('class'); - if (!$class) { - $class = $io->ask( - $this->trans('commands.generate.cache.context.questions.class'), - 'DefaultCacheContext' - ); - $input->setOption('class', $class); - } - - // --services option - $services = $input->getOption('services'); - if (!$services) { - // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion - $services = $this->servicesQuestion($io); - $input->setOption('services', $services); - } - } -} diff --git a/src/Command/Generate/CommandCommand.php b/src/Command/Generate/CommandCommand.php deleted file mode 100644 index 3b1901329..000000000 --- a/src/Command/Generate/CommandCommand.php +++ /dev/null @@ -1,224 +0,0 @@ -generator = $generator; - $this->extensionManager = $extensionManager; - $this->validator = $validator; - $this->stringConverter = $stringConverter; - $this->site = $site; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:command') - ->setDescription($this->trans('commands.generate.command.description')) - ->setHelp($this->trans('commands.generate.command.help')) - ->addOption( - 'extension', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.extension') - ) - ->addOption( - 'extension-type', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.extension-type') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.command.options.class') - ) - ->addOption( - 'name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.command.options.name') - ) - ->addOption( - 'container-aware', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.command.options.container-aware') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ) - ->setAliases(['gcm']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $extension = $input->getOption('extension'); - $extensionType = $input->getOption('extension-type'); - $class = $input->getOption('class'); - $name = $input->getOption('name'); - $containerAware = $input->getOption('container-aware'); - $services = $input->getOption('services'); - $yes = $input->hasOption('yes')?$input->getOption('yes'):false; - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io, $yes)) { - return 1; - } - - // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices - $build_services = $this->buildServices($services); - - $this->generator->generate( - $extension, - $extensionType, - $name, - $class, - $containerAware, - $build_services - ); - - $this->site->removeCachedServicesFile(); - - return 0; - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $extension = $input->getOption('extension'); - if (!$extension) { - $extension = $this->extensionQuestion($io, true, true); - $input->setOption('extension', $extension->getName()); - $input->setOption('extension-type', $extension->getType()); - } - - $extensionType = $input->getOption('extension-type'); - if (!$extensionType) { - $extensionType = $this->extensionTypeQuestion($io); - $input->setOption('extension-type', $extensionType); - } - - $name = $input->getOption('name'); - if (!$name) { - $name = $io->ask( - $this->trans('commands.generate.command.questions.name'), - sprintf('%s:default', $extension->getName()) - ); - $input->setOption('name', $name); - } - - $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); - } - - $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) { - // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion - $services = $this->servicesQuestion($io); - $input->setOption('services', $services); - } - } -} diff --git a/src/Command/Generate/ConfigFormBaseCommand.php b/src/Command/Generate/ConfigFormBaseCommand.php deleted file mode 100644 index 736180c1c..000000000 --- a/src/Command/Generate/ConfigFormBaseCommand.php +++ /dev/null @@ -1,91 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->routeProvider = $routeProvider; - $this->elementInfoManager = $elementInfoManager; - $this->appRoot = $appRoot; - $this->chainQueue = $chainQueue; - parent::__construct($extensionManager, $generator, $chainQueue, $stringConverter, $elementInfoManager, $routeProvider); - } - - protected function configure() - { - $this->setFormType('ConfigFormBase'); - $this->setCommandName('generate:form:config'); - $this->setAliases(['gfc']); - parent::configure(); - } -} diff --git a/src/Command/Generate/ControllerCommand.php b/src/Command/Generate/ControllerCommand.php deleted file mode 100644 index 0a0a08f14..000000000 --- a/src/Command/Generate/ControllerCommand.php +++ /dev/null @@ -1,320 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->validator = $validator; - $this->routeProvider = $routeProvider; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:controller') - ->setDescription($this->trans('commands.generate.controller.description')) - ->setHelp($this->trans('commands.generate.controller.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.controller.options.class') - ) - ->addOption( - 'routes', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.generate.controller.options.routes') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ) - ->addOption( - 'test', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.controller.options.test') - ) - ->setAliases(['gcn']); - } - - /** - * {@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 1; - } - - $module = $input->getOption('module'); - $class = $input->getOption('class'); - $routes = $input->getOption('routes'); - $test = $input->getOption('test'); - $services = $input->getOption('services'); - - $routes = $this->inlineValueAsArray($routes); - $input->setOption('routes', $routes); - - // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices - $build_services = $this->buildServices($services); - - //$this->generator->setLearning($learning); - $this->generator->generate( - $module, - $class, - $routes, - $test, - $build_services - ); - - // Run cache rebuild to see changes in Web UI - $this->chainQueue->addCommand('router:rebuild', []); - - return 0; - } - - /** - * {@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/'.($method!='hello'?$method:'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); - } - - /** - * @return \Drupal\Console\Generator\ControllerGenerator - */ - protected function createGenerator() - { - return new ControllerGenerator(); - } -} diff --git a/src/Command/Generate/EntityBundleCommand.php b/src/Command/Generate/EntityBundleCommand.php deleted file mode 100644 index 2a9ef6897..000000000 --- a/src/Command/Generate/EntityBundleCommand.php +++ /dev/null @@ -1,151 +0,0 @@ -validator = $validator; - $this->generator = $generator; - $this->extensionManager = $extensionManager; - parent::__construct(); - } - - - protected function configure() - { - $this - ->setName('generate:entity:bundle') - ->setDescription($this->trans('commands.generate.entity.bundle.description')) - ->setHelp($this->trans('commands.generate.entity.bundle.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'bundle-name', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.entity.bundle.options.bundle-name') - ) - ->addOption( - 'bundle-title', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.entity.bundle.options.bundle-title') - ) - ->setAliases(['geb']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $bundleName = $input->getOption('bundle-name'); - $bundleTitle = $input->getOption('bundle-title'); - - $generator = $this->generator; - //TODO: - // $generator->setLearning($learning); - $generator->generate($module, $bundleName, $bundleTitle); - - return 0; - } - - /** - * {@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); - } - } -} diff --git a/src/Command/Generate/EntityCommand.php b/src/Command/Generate/EntityCommand.php deleted file mode 100644 index d5869edc7..000000000 --- a/src/Command/Generate/EntityCommand.php +++ /dev/null @@ -1,176 +0,0 @@ -entityType = $entityType; - } - - /** - * @param $commandName - */ - protected function setCommandName($commandName) - { - $this->commandName = $commandName; - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $commandKey = str_replace(':', '.', $this->commandName); - - $this - ->setName($this->commandName) - ->setDescription( - sprintf( - $this->trans('commands.'.$commandKey.'.description'), - $this->entityType - ) - ) - ->setHelp( - sprintf( - $this->trans('commands.'.$commandKey.'.help'), - $this->commandName, - $this->entityType - ) - ) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'entity-class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.'.$commandKey.'.options.entity-class') - ) - ->addOption( - 'entity-name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.'.$commandKey.'.options.entity-name') - ) - ->addOption( - 'base-path', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.' . $commandKey . '.options.base-path') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.'.$commandKey.'.options.label') - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - // Operations defined in EntityConfigCommand and EntityContentCommand. - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $commandKey = str_replace(':', '.', $this->commandName); - $utils = $this->stringConverter; - - // --module option - $module = $input->getOption('module'); - if (!$module) { - // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion - $module = $this->moduleQuestion($io); - $input->setOption('module', $module); - } - - // --entity-class option - $entityClass = $input->getOption('entity-class'); - if (!$entityClass) { - $entityClass = $io->ask( - $this->trans('commands.'.$commandKey.'.questions.entity-class'), - 'DefaultEntity', - function ($entityClass) { - return $this->validator->validateSpaces($entityClass); - } - ); - - $input->setOption('entity-class', $entityClass); - } - - // --entity-name option - $entityName = $input->getOption('entity-name'); - if (!$entityName) { - $entityName = $io->ask( - $this->trans('commands.'.$commandKey.'.questions.entity-name'), - $utils->camelCaseToMachineName($entityClass), - function ($entityName) { - return $this->validator->validateMachineName($entityName); - } - ); - $input->setOption('entity-name', $entityName); - } - - // --label option - $label = $input->getOption('label'); - if (!$label) { - $label = $io->ask( - $this->trans('commands.'.$commandKey.'.questions.label'), - $utils->camelCaseToHuman($entityClass) - ); - $input->setOption('label', $label); - } - - // --base-path option - $base_path = $input->getOption('base-path'); - if (!$base_path) { - $base_path = $this->getDefaultBasePath(); - } - $base_path = $io->ask( - $this->trans('commands.'.$commandKey.'.questions.base-path'), - $base_path - ); - if (substr($base_path, 0, 1) !== '/') { - // Base path must start with a leading '/'. - $base_path = '/' . $base_path; - } - $input->setOption('base-path', $base_path); - } - - /** - * Gets default base path. - * - * @return string - * Default base path. - */ - protected function getDefaultBasePath() - { - return '/admin/structure'; - } -} diff --git a/src/Command/Generate/EntityConfigCommand.php b/src/Command/Generate/EntityConfigCommand.php deleted file mode 100644 index 0f77e100a..000000000 --- a/src/Command/Generate/EntityConfigCommand.php +++ /dev/null @@ -1,101 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->validator = $validator; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - - protected function configure() - { - $this->setEntityType('EntityConfig'); - $this->setCommandName('generate:entity:config'); - parent::configure(); - - $this->addOption( - 'bundle-of', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.entity.config.options.bundle-of') - ) - ->setAliases(['gecg']); - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - parent::interact($input, $output); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $module = $input->getOption('module'); - $entity_class = $input->getOption('entity-class'); - $entity_name = $input->getOption('entity-name'); - $label = $input->getOption('label'); - $bundle_of = $input->getOption('bundle-of'); - $base_path = $input->getOption('base-path'); - - $this - ->generator - ->generate($module, $entity_name, $entity_class, $label, $base_path, $bundle_of); - } -} diff --git a/src/Command/Generate/EntityContentCommand.php b/src/Command/Generate/EntityContentCommand.php deleted file mode 100644 index b664450e2..000000000 --- a/src/Command/Generate/EntityContentCommand.php +++ /dev/null @@ -1,174 +0,0 @@ -chainQueue = $chainQueue; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->extensionManager = $extensionManager; - $this->validator = $validator; - parent::__construct(); - } - - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this->setEntityType('EntityContent'); - $this->setCommandName('generate:entity:content'); - parent::configure(); - - $this->addOption( - 'has-bundles', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.entity.content.options.has-bundles') - ); - - $this->addOption( - 'is-translatable', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.entity.content.options.is-translatable') - ); - - $this->addOption( - 'revisionable', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.entity.content.options.revisionable') - ) - ->setAliases(['gect']); - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - parent::interact($input, $output); - $io = new DrupalStyle($input, $output); - - // --bundle-of option - $bundle_of = $input->getOption('has-bundles'); - if (!$bundle_of) { - $bundle_of = $io->confirm( - $this->trans('commands.generate.entity.content.questions.has-bundles'), - false - ); - $input->setOption('has-bundles', $bundle_of); - } - - // --is-translatable option - $is_translatable = $io->confirm( - $this->trans('commands.generate.entity.content.questions.is-translatable'), - true - ); - $input->setOption('is-translatable', $is_translatable); - - // --revisionable option - $revisionable = $io->confirm( - $this->trans('commands.generate.entity.content.questions.revisionable'), - true - ); - $input->setOption('revisionable', $revisionable); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $module = $input->getOption('module'); - $entity_class = $input->getOption('entity-class'); - $entity_name = $input->getOption('entity-name'); - $label = $input->getOption('label'); - $has_bundles = $input->getOption('has-bundles'); - $base_path = $input->getOption('base-path'); - $learning = $input->hasOption('learning')?$input->getOption('learning'):false; - $bundle_entity_name = $has_bundles ? $entity_name . '_type' : null; - $is_translatable = $input->hasOption('is-translatable') ? $input->getOption('is-translatable') : true; - $revisionable = $input->hasOption('revisionable') ? $input->getOption('revisionable') : false; - - $io = new DrupalStyle($input, $output); - $generator = $this->generator; - - $generator->setIo($io); - //@TODO: - //$generator->setLearning($learning); - - $generator->generate($module, $entity_name, $entity_class, $label, $base_path, $is_translatable, $bundle_entity_name, $revisionable); - - if ($has_bundles) { - $this->chainQueue->addCommand( - 'generate:entity:config', [ - '--module' => $module, - '--entity-class' => $entity_class . 'Type', - '--entity-name' => $entity_name . '_type', - '--label' => $label . ' type', - '--bundle-of' => $entity_name - ] - ); - } - } -} diff --git a/src/Command/Generate/EventSubscriberCommand.php b/src/Command/Generate/EventSubscriberCommand.php deleted file mode 100644 index b4f8b29fb..000000000 --- a/src/Command/Generate/EventSubscriberCommand.php +++ /dev/null @@ -1,197 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->eventDispatcher = $eventDispatcher; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:event:subscriber') - ->setDescription($this->trans('commands.generate.event.subscriber.description')) - ->setHelp($this->trans('commands.generate.event.subscriber.description')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'name', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.service.options.name') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.service.options.class') - ) - ->addOption( - 'events', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.events') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ) - ->setAliases(['ges']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $name = $input->getOption('name'); - $class = $input->getOption('class'); - $events = $input->getOption('events'); - $services = $input->getOption('services'); - - // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices - $buildServices = $this->buildServices($services); - - $this->generator->generate($module, $name, $class, $events, $buildServices); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); - } - - /** - * {@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); - } - - // --service-name option - $name = $input->getOption('name'); - if (!$name) { - $name = $io->ask( - $this->trans('commands.generate.service.questions.service-name'), - sprintf('%s.default', $module) - ); - $input->setOption('name', $name); - } - - // --class option - $class = $input->getOption('class'); - if (!$class) { - $class = $io->ask( - $this->trans('commands.generate.event.subscriber.questions.class'), - 'DefaultSubscriber' - ); - $input->setOption('class', $class); - } - - // --events option - $events = $input->getOption('events'); - if (!$events) { - // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion - $events = $this->eventsQuestion($io); - $input->setOption('events', $events); - } - - // --services option - $services = $input->getOption('services'); - if (!$services) { - // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion - $services = $this->servicesQuestion($io); - $input->setOption('services', $services); - } - } -} diff --git a/src/Command/Generate/FormAlterCommand.php b/src/Command/Generate/FormAlterCommand.php deleted file mode 100644 index 4c3d876f7..000000000 --- a/src/Command/Generate/FormAlterCommand.php +++ /dev/null @@ -1,324 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->moduleHandler = $moduleHandler; - $this->elementInfoManager = $elementInfoManager; - $this->profiler = $profiler; - $this->appRoot = $appRoot; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected $metadata = [ - 'class' => [], - 'method'=> [], - 'file'=> [], - 'unset' => [] - ]; - - protected function configure() - { - $this - ->setName('generate:form:alter') - ->setDescription( - $this->trans('commands.generate.form.alter.description') - ) - ->setHelp($this->trans('commands.generate.form.alter.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'form-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.form.alter.options.form-id') - ) - ->addOption( - 'inputs', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.inputs') - ) - ->setAliases(['gfa']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $formId = $input->getOption('form-id'); - $inputs = $input->getOption('inputs'); - - $function = $module . '_form_' .$formId . '_alter'; - - if ($this->extensionManager->validateModuleFunctionExist($module, $function)) { - throw new \Exception( - sprintf( - $this->trans('commands.generate.form.alter.messages.help-already-implemented'), - $module - ) - ); - } - - //validate if input is an array - if (!is_array($inputs[0])) { - $inputs= $this->explodeInlineArray($inputs); - } - - $this - ->generator - ->generate($module, $formId, $inputs, $this->metadata); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 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); - - // --form-id option - $formId = $input->getOption('form-id'); - if (!$formId) { - $forms = []; - // Get form ids from webprofiler - if ($this->moduleHandler->moduleExists('webprofiler')) { - $io->info( - $this->trans('commands.generate.form.alter.messages.loading-forms') - ); - $forms = $this->getWebprofilerForms(); - } - - if (!empty($forms)) { - $formId = $io->choiceNoList( - $this->trans('commands.generate.form.alter.options.form-id'), - array_keys($forms) - ); - } - } - - if ($this->moduleHandler->moduleExists('webprofiler') && isset($forms[$formId])) { - $this->metadata['class'] = $forms[$formId]['class']['class']; - $this->metadata['method'] = $forms[$formId]['class']['method']; - $this->metadata['file'] = str_replace( - $this->appRoot, - '', - $forms[$formId]['class']['file'] - ); - - foreach ($forms[$formId]['form'] as $itemKey => $item) { - if ($item['#type'] == 'hidden') { - unset($forms[$formId]['form'][$itemKey]); - } - } - - unset($forms[$formId]['form']['form_build_id']); - unset($forms[$formId]['form']['form_token']); - unset($forms[$formId]['form']['form_id']); - unset($forms[$formId]['form']['actions']); - - $formItems = array_keys($forms[$formId]['form']); - - $formItemsToHide = $io->choice( - $this->trans('commands.generate.form.alter.messages.hide-form-elements'), - $formItems, - null, - true - ); - - $this->metadata['unset'] = array_filter(array_map('trim', $formItemsToHide)); - } - - $input->setOption('form-id', $formId); - - // @see Drupal\Console\Command\Shared\FormTrait::formQuestion - $inputs = $input->getOption('inputs'); - - if (empty($inputs)) { - $io->writeln($this->trans('commands.generate.form.alter.messages.inputs')); - $inputs = $this->formQuestion($io); - } else { - $inputs= $this->explodeInlineArray($inputs); - } - - $input->setOption('inputs', $inputs); - } - - /** - * @{@inheritdoc} - */ - public function explodeInlineArray($inlineInputs) - { - $inputs = []; - foreach ($inlineInputs as $inlineInput) { - $explodeInput = explode(" ", $inlineInput); - $parameters = []; - foreach ($explodeInput as $inlineParameter) { - list($key, $value) = explode(":", $inlineParameter); - if (!empty($value)) { - $parameters[$key] = $value; - } - } - $inputs[] = $parameters; - } - - return $inputs; - } - - protected function createGenerator() - { - return new FormAlterGenerator(); - } - - public function getWebprofilerForms() - { - $tokens = $this->profiler->find(null, null, 1000, null, '', ''); - $forms = []; - foreach ($tokens as $token) { - $token = [$token['token']]; - $profile = $this->profiler->loadProfile($token); - $formCollector = $profile->getCollector('forms'); - $collectedForms = $formCollector->getForms(); - if (empty($forms)) { - $forms = $collectedForms; - } elseif (!empty($collectedForms)) { - $forms = array_merge($forms, $collectedForms); - } - } - return $forms; - } -} diff --git a/src/Command/Generate/FormBaseCommand.php b/src/Command/Generate/FormBaseCommand.php deleted file mode 100644 index 9e75348da..000000000 --- a/src/Command/Generate/FormBaseCommand.php +++ /dev/null @@ -1,18 +0,0 @@ -setFormType('FormBase'); - $this->setCommandName('generate:form'); - parent::configure(); - } -} diff --git a/src/Command/Generate/FormCommand.php b/src/Command/Generate/FormCommand.php deleted file mode 100644 index 6b84175c8..000000000 --- a/src/Command/Generate/FormCommand.php +++ /dev/null @@ -1,330 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->chainQueue = $chainQueue; - $this->stringConverter = $stringConverter; - $this->elementInfoManager = $elementInfoManager; - $this->routeProvider = $routeProvider; - parent::__construct(); - } - - protected function setFormType($formType) - { - return $this->formType = $formType; - } - - protected function setCommandName($commandName) - { - return $this->commandName = $commandName; - } - - protected function configure() - { - $this - ->setName($this->commandName) - ->setDescription( - sprintf( - $this->trans('commands.generate.form.description'), - $this->formType - ) - ) - ->setHelp( - sprintf( - $this->trans('commands.generate.form.help'), - $this->commandName, - $this->formType - ) - ) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.form.options.class') - ) - ->addOption( - 'form-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.form.options.form-id') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ) - ->addOption( - 'config-file', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.form.options.config-file') - ) - ->addOption( - 'inputs', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.common.options.inputs') - ) - ->addOption( - 'path', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.form.options.path') - ) - ->addOption( - 'menu-link-gen', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.form.options.menu-link-gen') - ) - ->addOption( - 'menu-link-title', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.form.options.menu-link-title') - ) - ->addOption( - 'menu-parent', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.form.options.menu-parent') - ) - ->addOption( - 'menu-link-desc', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.form.options.menu-link-desc') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $module = $input->getOption('module'); - $services = $input->getOption('services'); - $path = $input->getOption('path'); - $config_file = $input->getOption('config-file'); - $class_name = $input->getOption('class'); - $form_id = $input->getOption('form-id'); - $form_type = $this->formType; - $menu_link_gen = $input->getOption('menu-link-gen'); - $menu_parent = $input->getOption('menu-parent'); - $menu_link_title = $input->getOption('menu-link-title'); - $menu_link_desc = $input->getOption('menu-link-desc'); - - // if exist form generate config file - $inputs = $input->getOption('inputs'); - $build_services = $this->buildServices($services); - - $this - ->generator - ->generate($module, $class_name, $form_id, $form_type, $build_services, $config_file, $inputs, $path, $menu_link_gen, $menu_link_title, $menu_parent, $menu_link_desc); - - $this->chainQueue->addCommand('router:rebuild', []); - } - - /** - * {@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 - $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->stringConverter->camelCaseToMachineName($className) - ); - $input->setOption('form-id', $formId); - } - - // --services option - // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion - $services = $this->servicesQuestion($io); - $input->setOption('services', $services); - - // --config_file option - $config_file = $input->getOption('config-file'); - - if (!$config_file) { - $config_file = $io->confirm( - $this->trans('commands.generate.form.questions.config-file'), - true - ); - $input->setOption('config-file', $config_file); - } - - // --inputs option - $inputs = $input->getOption('inputs'); - if (!$inputs) { - // @see \Drupal\Console\Command\Shared\FormTrait::formQuestion - $inputs = $this->formQuestion($io); - $input->setOption('inputs', $inputs); - } - - $path = $input->getOption('path'); - if (!$path) { - if ($this->formType == 'ConfigFormBase') { - $form_path = '/admin/config/{{ module_name }}/{{ class_name_short }}'; - $form_path = sprintf( - '/admin/config/%s/%s', - $module, - strtolower($this->stringConverter->removeSuffix($className)) - ); - } else { - $form_path = sprintf( - '/%s/form/%s', - $module, - $this->stringConverter->camelCaseToMachineName($this->stringConverter->removeSuffix($className)) - ); - } - $path = $io->ask( - $this->trans('commands.generate.form.questions.path'), - $form_path, - function ($path) { - if (count($this->routeProvider->getRoutesByPattern($path)) > 0) { - throw new \InvalidArgumentException( - sprintf( - $this->trans( - 'commands.generate.form.messages.path-already-added' - ), - $path - ) - ); - } - - return $path; - } - ); - $input->setOption('path', $path); - } - - // --link option for links.menu - if ($this->formType == 'ConfigFormBase') { - $menu_options = $this->menuQuestion($io, $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']); - } - } - } -} diff --git a/src/Command/Generate/HelpCommand.php b/src/Command/Generate/HelpCommand.php deleted file mode 100644 index 678ce7143..000000000 --- a/src/Command/Generate/HelpCommand.php +++ /dev/null @@ -1,148 +0,0 @@ -generator = $generator; - $this->site = $site; - $this->extensionManager = $extensionManager; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:help') - ->setDescription($this->trans('commands.generate.help.description')) - ->setHelp($this->trans('commands.generate.help.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'description', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.module.options.description') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - - if ($this->extensionManager->validateModuleFunctionExist($module, $module . '_help')) { - throw new \Exception( - sprintf( - $this->trans('commands.generate.help.messages.help-already-implemented'), - $module - ) - ); - } - - $description = $input->getOption('description'); - - $this - ->generator - ->generate($module, $description); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 0; - } - - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $this->site->loadLegacyFile('/core/includes/update.inc'); - $this->site->loadLegacyFile('/core/includes/schema.inc'); - - $module = $input->getOption('module'); - if (!$module) { - // @see Drupal\Console\Command\ModuleTrait::moduleQuestion - $module = $this->moduleQuestion($io); - $input->setOption('module', $module); - } - - $description = $input->getOption('description'); - if (!$description) { - $description = $io->ask( - $this->trans('commands.generate.module.questions.description'), - 'My Awesome Module' - ); - } - $input->setOption('description', $description); - } -} diff --git a/src/Command/Generate/ModuleCommand.php b/src/Command/Generate/ModuleCommand.php deleted file mode 100644 index 1382b08b3..000000000 --- a/src/Command/Generate/ModuleCommand.php +++ /dev/null @@ -1,409 +0,0 @@ -generator = $generator; - $this->validator = $validator; - $this->appRoot = $appRoot; - $this->stringConverter = $stringConverter; - $this->drupalApi = $drupalApi; - $this->twigtemplate = $twigtemplate; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:module') - ->setDescription($this->trans('commands.generate.module.description')) - ->setHelp($this->trans('commands.generate.module.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.module.options.module') - ) - ->addOption( - 'machine-name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.module.options.machine-name') - ) - ->addOption( - 'module-path', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.module.options.module-path') - ) - ->addOption( - 'description', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.module.options.description') - ) - ->addOption( - 'core', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.module.options.core') - ) - ->addOption( - 'package', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.module.options.package') - ) - ->addOption( - 'module-file', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.module.options.module-file') - ) - ->addOption( - 'features-bundle', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.module.options.features-bundle') - ) - ->addOption( - 'composer', - null, - InputOption::VALUE_NONE, - $this->trans('commands.generate.module.options.composer') - ) - ->addOption( - 'dependencies', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.module.options.dependencies'), - '' - ) - ->addOption( - 'test', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.module.options.test') - ) - ->addOption( - 'twigtemplate', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.module.options.twigtemplate') - ) - ->setAliases(['gm']); - } - - /** - * {@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 1; - } - - $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'); - $dependencies = $this->validator->validateExtensions( - $input->getOption('dependencies'), - 'module', - $io - ); - $test = $input->getOption('test'); - $twigTemplate = $input->getOption('twigtemplate'); - - $this->generator->generate( - $module, - $machineName, - $modulePath, - $description, - $core, - $package, - $moduleFile, - $featuresBundle, - $composer, - $dependencies, - $test, - $twigTemplate - ); - - return 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 1; - } - - 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); - } - - $twigtemplate = $input->getOption('twigtemplate'); - if (!$twigtemplate) { - $twigtemplate = $io->confirm( - $this->trans('commands.generate.module.questions.twigtemplate'), - true - ); - $input->setOption('twigtemplate', $twigtemplate); - } - } - - /** - * @return ModuleGenerator - */ - protected function createGenerator() - { - return new ModuleGenerator(); - } -} diff --git a/src/Command/Generate/ModuleFileCommand.php b/src/Command/Generate/ModuleFileCommand.php deleted file mode 100644 index e28c8ac33..000000000 --- a/src/Command/Generate/ModuleFileCommand.php +++ /dev/null @@ -1,115 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:module:file') - ->setDescription($this->trans('commands.generate.module.file.description')) - ->setHelp($this->trans('commands.generate.module.file.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io, $yes)) { - return 1; - } - - $machine_name = $input->getOption('module'); - $file_path = $this->extensionManager->getModule($machine_name)->getPath(); - $generator = $this->generator; - - $generator->generate( - $machine_name, - $file_path - ); - } - - - /** - * {@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); - } -} diff --git a/src/Command/Generate/PermissionCommand.php b/src/Command/Generate/PermissionCommand.php deleted file mode 100644 index a7aee3778..000000000 --- a/src/Command/Generate/PermissionCommand.php +++ /dev/null @@ -1,122 +0,0 @@ -extensionManager = $extensionManager; - $this->stringConverter = $stringConverter; - $this->generator = $permissionGenerator; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:permissions') - ->setDescription($this->trans('commands.generate.permission.description')) - ->setHelp($this->trans('commands.generate.permission.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'permissions', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.common.options.permissions') - ) - ->setAliases(['gp']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $module = $input->getOption('module'); - $permissions = $input->getOption('permissions'); - $learning = $input->hasOption('learning'); - - - $this->generator->generate($module, $permissions, $learning); - } - - /** - * {@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); - } - - // --permissions option - $permissions = $input->getOption('permissions'); - if (!$permissions) { - // @see \Drupal\Console\Command\Shared\PermissionTrait::permissionQuestion - $permissions = $this->permissionQuestion($io); - $input->setOption('permissions', $permissions); - } - } -} diff --git a/src/Command/Generate/PluginBlockCommand.php b/src/Command/Generate/PluginBlockCommand.php deleted file mode 100644 index 21679d997..000000000 --- a/src/Command/Generate/PluginBlockCommand.php +++ /dev/null @@ -1,292 +0,0 @@ -configFactory = $configFactory; - $this->chainQueue = $chainQueue; - $this->generator = $generator; - $this->entityTypeManager = $entityTypeManager; - $this->extensionManager = $extensionManager; - $this->validator = $validator; - $this->stringConverter = $stringConverter; - $this->elementInfoManager = $elementInfoManager; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:block') - ->setDescription($this->trans('commands.generate.plugin.block.description')) - ->setHelp($this->trans('commands.generate.plugin.block.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.block.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.block.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.block.options.plugin-id') - ) - ->addOption( - 'theme-region', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.block.options.theme-region') - ) - ->addOption( - 'inputs', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.inputs') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ) - ->setAliases(['gpb']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $services = $input->getOption('services'); - $theme_region = $input->getOption('theme-region'); - $inputs = $input->getOption('inputs'); - - $theme = $this->configFactory->get('system.theme')->get('default'); - $themeRegions = \system_region_list($theme, REGIONS_VISIBLE); - - if (!empty($theme_region) && !isset($themeRegions[$theme_region])) { - $io->error( - sprintf( - $this->trans('commands.generate.plugin.block.messages.invalid-theme-region'), - $theme_region - ) - ); - - return 1; - } - - // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices - $build_services = $this->buildServices($services); - - $this->generator - ->generate( - $module, - $class_name, - $label, - $plugin_id, - $build_services, - $inputs - ); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - if ($theme_region) { - $block = $this->entityTypeManager - ->getStorage('block') - ->create( - [ - 'id'=> $plugin_id, - 'plugin' => $plugin_id, - 'theme' => $theme - ] - ); - $block->setRegion($theme_region); - $block->save(); - } - } - - 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.questions.class'), - 'DefaultBlock', - 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.block.questions.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.questions.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.questions.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); - } -} diff --git a/src/Command/Generate/PluginCKEditorButtonCommand.php b/src/Command/Generate/PluginCKEditorButtonCommand.php deleted file mode 100644 index 2152dbeac..000000000 --- a/src/Command/Generate/PluginCKEditorButtonCommand.php +++ /dev/null @@ -1,207 +0,0 @@ -chainQueue = $chainQueue; - $this->generator = $generator; - $this->extensionManager = $extensionManager; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:ckeditorbutton') - ->setDescription($this->trans('commands.generate.plugin.ckeditorbutton.description')) - ->setHelp($this->trans('commands.generate.plugin.ckeditorbutton.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.ckeditorbutton.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.ckeditorbutton.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.ckeditorbutton.options.plugin-id') - ) - ->addOption( - 'button-name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.ckeditorbutton.options.button-name') - ) - ->addOption( - 'button-icon-path', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.ckeditorbutton.options.button-icon-path') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $button_name = $input->getOption('button-name'); - $button_icon_path = $input->getOption('button-icon-path'); - - $this - ->generator - ->generate($module, $class_name, $label, $plugin_id, $button_name, $button_icon_path); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false); - - return 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_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->stringConverter->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->stringConverter->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->stringConverter->anyCaseToUcFirst($plugin_id) - ); - $input->setOption('button-name', $button_name); - } - - // --button-icon-path option - $button_icon_path = $input->getOption('button-icon-path'); - if (!$button_icon_path) { - $button_icon_path = $io->ask( - $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-icon-path'), - drupal_get_path('module', $module) . '/js/plugins/' . $plugin_id . '/images/icon.png' - ); - $input->setOption('button-icon-path', $button_icon_path); - } - } -} diff --git a/src/Command/Generate/PluginConditionCommand.php b/src/Command/Generate/PluginConditionCommand.php deleted file mode 100644 index 24bc6da17..000000000 --- a/src/Command/Generate/PluginConditionCommand.php +++ /dev/null @@ -1,253 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->chainQueue = $chainQueue; - $this->entitytyperepository = $entitytyperepository; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:condition') - ->setDescription($this->trans('commands.generate.plugin.condition.description')) - ->setHelp($this->trans('commands.generate.plugin.condition.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.condition.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.condition.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.condition.options.plugin-id') - ) - ->addOption( - 'context-definition-id', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.condition.options.context-definition-id') - ) - ->addOption( - 'context-definition-label', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.condition.options.context-definition-label') - ) - ->addOption( - 'context-definition-required', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.condition.options.context-definition-required') - ) - ->setAliases(['gpc']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $context_definition_id = $input->getOption('context-definition-id'); - $context_definition_label = $input->getOption('context-definition-label'); - $context_definition_required = $input->getOption('context-definition-required')?'TRUE':'FALSE'; - - $this - ->generator - ->generate($module, $class_name, $label, $plugin_id, $context_definition_id, $context_definition_label, $context_definition_required); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 0; - } - - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $entityTypeRepository = $this->entitytyperepository; - - $entity_types = $entityTypeRepository->getEntityTypeLabels(true); - - // --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.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->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.condition.questions.plugin-id'), - $this->stringConverter->camelCaseToUnderscore($class) - ); - $input->setOption('plugin-id', $pluginId); - } - - $context_definition_id = $input->getOption('context-definition-id'); - if (!$context_definition_id) { - $context_type = ['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); - } - } -} diff --git a/src/Command/Generate/PluginFieldCommand.php b/src/Command/Generate/PluginFieldCommand.php deleted file mode 100644 index 35577216a..000000000 --- a/src/Command/Generate/PluginFieldCommand.php +++ /dev/null @@ -1,346 +0,0 @@ -extensionManager = $extensionManager; - $this->stringConverter = $stringConverter; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:field') - ->setDescription($this->trans('commands.generate.plugin.field.description')) - ->setHelp($this->trans('commands.generate.plugin.field.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'type-class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.field.options.type-class') - ) - ->addOption( - 'type-label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.type-label') - ) - ->addOption( - 'type-plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.type-plugin-id') - ) - ->addOption( - 'type-description', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.type-type-description') - ) - ->addOption( - 'formatter-class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.field.options.class') - ) - ->addOption( - 'formatter-label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.formatter-label') - ) - ->addOption( - 'formatter-plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.formatter-plugin-id') - ) - ->addOption( - 'widget-class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.field.options.formatter-class') - ) - ->addOption( - 'widget-label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.widget-label') - ) - ->addOption( - 'widget-plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.widget-plugin-id') - ) - ->addOption( - 'field-type', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.field-type') - ) - ->addOption( - 'default-widget', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.default-widget') - ) - ->addOption( - 'default-formatter', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.field.options.default-formatter') - ) - ->setAliases(['gpf']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $this->chainQueue - ->addCommand( - 'generate:plugin:fieldtype', [ - '--module' => $input->getOption('module'), - '--class' => $input->getOption('type-class'), - '--label' => $input->getOption('type-label'), - '--plugin-id' => $input->getOption('type-plugin-id'), - '--description' => $input->getOption('type-description'), - '--default-widget' => $input->getOption('default-widget'), - '--default-formatter' => $input->getOption('default-formatter'), - ], - false - ); - - $this->chainQueue - ->addCommand( - 'generate:plugin:fieldwidget', [ - '--module' => $input->getOption('module'), - '--class' => $input->getOption('widget-class'), - '--label' => $input->getOption('widget-label'), - '--plugin-id' => $input->getOption('widget-plugin-id'), - '--field-type' => $input->getOption('field-type'), - ], - false - ); - $this->chainQueue - ->addCommand( - 'generate:plugin:fieldformatter', [ - '--module' => $input->getOption('module'), - '--class' => $input->getOption('formatter-class'), - '--label' => $input->getOption('formatter-label'), - '--plugin-id' => $input->getOption('formatter-plugin-id'), - '--field-type' => $input->getOption('field-type'), - ], - false - ); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false); - - return 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); - } - - // --type-class option - $typeClass = $input->getOption('type-class'); - if (!$typeClass) { - $typeClass = $io->ask( - $this->trans('commands.generate.plugin.field.questions.type-class'), - 'ExampleFieldType' - ); - $input->setOption('type-class', $typeClass); - } - - // --type-label option - $label = $input->getOption('type-label'); - if (!$label) { - $label = $io->ask( - $this->trans('commands.generate.plugin.field.questions.type-label'), - $this->stringConverter->camelCaseToHuman($typeClass) - ); - $input->setOption('type-label', $label); - } - - // --type-plugin-id option - $plugin_id = $input->getOption('type-plugin-id'); - if (!$plugin_id) { - $plugin_id = $io->ask( - $this->trans('commands.generate.plugin.field.questions.type-plugin-id'), - $this->stringConverter->camelCaseToUnderscore($typeClass) - ); - $input->setOption('type-plugin-id', $plugin_id); - } - - // --type-description option - $description = $input->getOption('type-description'); - if (!$description) { - $description = $io->ask( - $this->trans('commands.generate.plugin.field.questions.type-description'), - 'My Field Type' - ); - $input->setOption('type-description', $description); - } - - // --widget-class option - $widgetClass = $input->getOption('widget-class'); - if (!$widgetClass) { - $widgetClass = $io->ask( - $this->trans('commands.generate.plugin.field.questions.widget-class'), - 'ExampleWidgetType' - ); - $input->setOption('widget-class', $widgetClass); - } - - // --widget-label option - $widgetLabel = $input->getOption('widget-label'); - if (!$widgetLabel) { - $widgetLabel = $io->ask( - $this->trans('commands.generate.plugin.field.questions.widget-label'), - $this->stringConverter->camelCaseToHuman($widgetClass) - ); - $input->setOption('widget-label', $widgetLabel); - } - - // --widget-plugin-id option - $widget_plugin_id = $input->getOption('widget-plugin-id'); - if (!$widget_plugin_id) { - $widget_plugin_id = $io->ask( - $this->trans('commands.generate.plugin.field.questions.widget-plugin-id'), - $this->stringConverter->camelCaseToUnderscore($widgetClass) - ); - $input->setOption('widget-plugin-id', $widget_plugin_id); - } - - // --formatter-class option - $formatterClass = $input->getOption('formatter-class'); - if (!$formatterClass) { - $formatterClass = $io->ask( - $this->trans('commands.generate.plugin.field.questions.formatter-class'), - 'ExampleFormatterType' - ); - $input->setOption('formatter-class', $formatterClass); - } - - // --formatter-label option - $formatterLabel = $input->getOption('formatter-label'); - if (!$formatterLabel) { - $formatterLabel = $io->ask( - $this->trans('commands.generate.plugin.field.questions.formatter-label'), - $this->stringConverter->camelCaseToHuman($formatterClass) - ); - $input->setOption('formatter-label', $formatterLabel); - } - - // --formatter-plugin-id option - $formatter_plugin_id = $input->getOption('formatter-plugin-id'); - if (!$formatter_plugin_id) { - $formatter_plugin_id = $io->ask( - $this->trans('commands.generate.plugin.field.questions.formatter-plugin-id'), - $this->stringConverter->camelCaseToUnderscore($formatterClass) - ); - $input->setOption('formatter-plugin-id', $formatter_plugin_id); - } - - // --field-type option - $field_type = $input->getOption('field-type'); - if (!$field_type) { - $field_type = $io->ask( - $this->trans('commands.generate.plugin.field.questions.field-type'), - $plugin_id - ); - $input->setOption('field-type', $field_type); - } - - // --default-widget option - $default_widget = $input->getOption('default-widget'); - if (!$default_widget) { - $default_widget = $io->ask( - $this->trans('commands.generate.plugin.field.questions.default-widget'), - $widget_plugin_id - ); - $input->setOption('default-widget', $default_widget); - } - - // --default-formatter option - $default_formatter = $input->getOption('default-formatter'); - if (!$default_formatter) { - $default_formatter = $io->ask( - $this->trans('commands.generate.plugin.field.questions.default-formatter'), - $formatter_plugin_id - ); - $input->setOption('default-formatter', $default_formatter); - } - } -} diff --git a/src/Command/Generate/PluginFieldFormatterCommand.php b/src/Command/Generate/PluginFieldFormatterCommand.php deleted file mode 100644 index 627ae163e..000000000 --- a/src/Command/Generate/PluginFieldFormatterCommand.php +++ /dev/null @@ -1,205 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->fieldTypePluginManager = $fieldTypePluginManager; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:fieldformatter') - ->setDescription($this->trans('commands.generate.plugin.fieldformatter.description')) - ->setHelp($this->trans('commands.generate.plugin.fieldformatter.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.fieldformatter.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldformatter.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldformatter.options.plugin-id') - ) - ->addOption( - 'field-type', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldformatter.options.field-type') - ) - ->setAliases(['gpff']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $field_type = $input->getOption('field-type'); - - $this->generator->generate($module, $class_name, $label, $plugin_id, $field_type); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 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.fieldformatter.questions.class'), - 'ExampleFieldFormatter' - ); - $input->setOption('class', $class); - } - - // --plugin label option - $label = $input->getOption('label'); - if (!$label) { - $label = $io->ask( - $this->trans('commands.generate.plugin.fieldformatter.questions.label'), - $this->stringConverter->camelCaseToHuman($class) - ); - $input->setOption('label', $label); - } - - // --name option - $plugin_id = $input->getOption('plugin-id'); - if (!$plugin_id) { - $plugin_id = $io->ask( - $this->trans('commands.generate.plugin.fieldformatter.questions.plugin-id'), - $this->stringConverter->camelCaseToUnderscore($class) - ); - $input->setOption('plugin-id', $plugin_id); - } - - // --field type option - $field_type = $input->getOption('field-type'); - if (!$field_type) { - // Gather valid field types. - $field_type_options = []; - foreach ($this->fieldTypePluginManager->getGroupedDefinitions($this->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); - } - } -} diff --git a/src/Command/Generate/PluginFieldTypeCommand.php b/src/Command/Generate/PluginFieldTypeCommand.php deleted file mode 100644 index 49f6b6eef..000000000 --- a/src/Command/Generate/PluginFieldTypeCommand.php +++ /dev/null @@ -1,221 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:fieldtype') - ->setDescription($this->trans('commands.generate.plugin.fieldtype.description')) - ->setHelp($this->trans('commands.generate.plugin.fieldtype.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.fieldtype.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldtype.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldtype.options.plugin-id') - ) - ->addOption( - 'description', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldtype.options.description') - ) - ->addOption( - 'default-widget', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldtype.options.default-widget') - ) - ->addOption( - 'default-formatter', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldtype.options.default-formatter') - ) - ->setAliases(['gpft']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $description = $input->getOption('description'); - $default_widget = $input->getOption('default-widget'); - $default_formatter = $input->getOption('default-formatter'); - - $this->generator - ->generate($module, $class_name, $label, $plugin_id, $description, $default_widget, $default_formatter); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false); - - return 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_name = $input->getOption('class'); - if (!$class_name) { - $class_name = $io->ask( - $this->trans('commands.generate.plugin.fieldtype.questions.class'), - 'ExampleFieldType' - ); - $input->setOption('class', $class_name); - } - - // --label option - $label = $input->getOption('label'); - if (!$label) { - $label = $io->ask( - $this->trans('commands.generate.plugin.fieldtype.questions.label'), - $this->stringConverter->camelCaseToHuman($class_name) - ); - $input->setOption('label', $label); - } - - // --plugin-id option - $plugin_id = $input->getOption('plugin-id'); - if (!$plugin_id) { - $plugin_id = $io->ask( - $this->trans('commands.generate.plugin.fieldtype.questions.plugin-id'), - $this->stringConverter->camelCaseToUnderscore($class_name) - ); - $input->setOption('plugin-id', $plugin_id); - } - - // --description option - $description = $input->getOption('description'); - if (!$description) { - $description = $io->ask( - $this->trans('commands.generate.plugin.fieldtype.questions.description'), - 'My Field Type' - ); - $input->setOption('description', $description); - } - - // --default-widget option - $default_widget = $input->getOption('default-widget'); - if (!$default_widget) { - $default_widget = $io->askEmpty( - $this->trans('commands.generate.plugin.fieldtype.questions.default-widget') - ); - $input->setOption('default-widget', $default_widget); - } - - // --default-formatter option - $default_formatter = $input->getOption('default-formatter'); - if (!$default_formatter) { - $default_formatter = $io->askEmpty( - $this->trans('commands.generate.plugin.fieldtype.questions.default-formatter') - ); - $input->setOption('default-formatter', $default_formatter); - } - } -} diff --git a/src/Command/Generate/PluginFieldWidgetCommand.php b/src/Command/Generate/PluginFieldWidgetCommand.php deleted file mode 100644 index a56213756..000000000 --- a/src/Command/Generate/PluginFieldWidgetCommand.php +++ /dev/null @@ -1,210 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->fieldTypePluginManager = $fieldTypePluginManager; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:fieldwidget') - ->setDescription($this->trans('commands.generate.plugin.fieldwidget.description')) - ->setHelp($this->trans('commands.generate.plugin.fieldwidget.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.fieldwidget.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldwidget.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldwidget.options.plugin-id') - ) - ->addOption( - 'field-type', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.fieldwidget.options.field-type') - ) - ->setAliases(['gpfw']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $field_type = $input->getOption('field-type'); - - $this->generator->generate($module, $class_name, $label, $plugin_id, $field_type); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 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_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->stringConverter->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->stringConverter->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 = []; - foreach ($this->fieldTypePluginManager->getGroupedDefinitions($this->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); - } - } -} diff --git a/src/Command/Generate/PluginImageEffectCommand.php b/src/Command/Generate/PluginImageEffectCommand.php deleted file mode 100644 index cf516e813..000000000 --- a/src/Command/Generate/PluginImageEffectCommand.php +++ /dev/null @@ -1,185 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:imageeffect') - ->setDescription($this->trans('commands.generate.plugin.imageeffect.description')) - ->setHelp($this->trans('commands.generate.plugin.imageeffect.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.imageeffect.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.imageeffect.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.imageeffect.options.plugin-id') - ) - ->addOption( - 'description', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.imageeffect.options.description') - ) - ->setAliases(['gpie']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $description = $input->getOption('description'); - - $this->generator->generate($module, $class_name, $label, $plugin_id, $description); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - } - - 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_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->stringConverter->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->stringConverter->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); - } - } -} diff --git a/src/Command/Generate/PluginImageFormatterCommand.php b/src/Command/Generate/PluginImageFormatterCommand.php deleted file mode 100644 index 5a3cb696f..000000000 --- a/src/Command/Generate/PluginImageFormatterCommand.php +++ /dev/null @@ -1,172 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->validator = $validator; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:imageformatter') - ->setDescription($this->trans('commands.generate.plugin.imageformatter.description')) - ->setHelp($this->trans('commands.generate.plugin.imageformatter.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.imageformatter.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.imageformatter.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.imageformatter.options.plugin-id') - ) - ->setAliases(['gpif']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - - $this->generator->generate($module, $class_name, $label, $plugin_id); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - } - - 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_name = $input->getOption('class'); - if (!$class_name) { - $class_name = $io->ask( - $this->trans('commands.generate.plugin.imageformatter.questions.class'), - 'ExampleImageFormatter' - ); - $input->setOption('class', $class_name); - } - - // --label option - $label = $input->getOption('label'); - if (!$label) { - $label = $io->ask( - $this->trans('commands.generate.plugin.imageformatter.questions.label'), - $this->stringConverter->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.imageformatter.questions.plugin-id'), - $this->stringConverter->camelCaseToUnderscore($class_name) - ); - $input->setOption('plugin-id', $plugin_id); - } - } -} diff --git a/src/Command/Generate/PluginMailCommand.php b/src/Command/Generate/PluginMailCommand.php deleted file mode 100644 index 48a47d0d6..000000000 --- a/src/Command/Generate/PluginMailCommand.php +++ /dev/null @@ -1,198 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->validator = $validator; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:mail') - ->setDescription($this->trans('commands.generate.plugin.mail.description')) - ->setHelp($this->trans('commands.generate.plugin.mail.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.mail.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.mail.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.mail.options.plugin-id') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $services = $input->getOption('services'); - - // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices - $build_services = $this->buildServices($services); - - $this->generator->generate($module, $class_name, $label, $plugin_id, $build_services); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - } - - 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); - } -} diff --git a/src/Command/Generate/PluginMigrateProcessCommand.php b/src/Command/Generate/PluginMigrateProcessCommand.php deleted file mode 100644 index 20ba70a60..000000000 --- a/src/Command/Generate/PluginMigrateProcessCommand.php +++ /dev/null @@ -1,147 +0,0 @@ -generator = $generator; - $this->chainQueue = $chainQueue; - $this->extensionManager = $extensionManager; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:migrate:process') - ->setDescription($this->trans('commands.generate.plugin.migrate.process.description')) - ->setHelp($this->trans('commands.generate.plugin.migrate.process.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.migrate.process.options.class') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.migrate.process.options.plugin-id') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $plugin_id = $input->getOption('plugin-id'); - - $this->generator->generate($module, $class_name, $plugin_id); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // 'module-name' option. - $module = $input->getOption('module'); - if (!$module) { - // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion - $module = $this->moduleQuestion($io); - $input->setOption('module', $module); - } - - // 'class-name' option - $class = $input->getOption('class'); - if (!$class) { - $class = $io->ask( - $this->trans('commands.generate.plugin.migrate.process.questions.class'), - ucfirst($this->stringConverter->underscoreToCamelCase($module)) - ); - $input->setOption('class', $class); - } - - // 'plugin-id' option. - $pluginId = $input->getOption('plugin-id'); - if (!$pluginId) { - $pluginId = $io->ask( - $this->trans('commands.generate.plugin.migrate.source.questions.plugin-id'), - $this->stringConverter->camelCaseToUnderscore($class) - ); - $input->setOption('plugin-id', $pluginId); - } - } -} diff --git a/src/Command/Generate/PluginMigrateSourceCommand.php b/src/Command/Generate/PluginMigrateSourceCommand.php deleted file mode 100644 index 5de03cccf..000000000 --- a/src/Command/Generate/PluginMigrateSourceCommand.php +++ /dev/null @@ -1,267 +0,0 @@ -configFactory = $configFactory; - $this->chainQueue = $chainQueue; - $this->generator = $generator; - $this->entityTypeManager = $entityTypeManager; - $this->extensionManager = $extensionManager; - $this->validator = $validator; - $this->stringConverter = $stringConverter; - $this->elementInfoManager = $elementInfoManager; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:migrate:source') - ->setDescription($this->trans('commands.generate.plugin.migrate.source.description')) - ->setHelp($this->trans('commands.generate.plugin.migrate.source.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.migrate.source.options.class') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.migrate.source.options.plugin-id') - ) - ->addOption( - 'table', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.migrate.source.options.table') - ) - ->addOption( - 'alias', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.migrate.source.options.alias') - ) - ->addOption( - 'group-by', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.migrate.source.options.group-by') - ) - ->addOption( - 'fields', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.generate.plugin.migrate.source.options.fields') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $plugin_id = $input->getOption('plugin-id'); - $table = $input->getOption('table'); - $alias = $input->getOption('alias'); - $group_by = $input->getOption('group-by'); - $fields = $input->getOption('fields'); - - $this->generator - ->generate( - $module, - $class_name, - $plugin_id, - $table, - $alias, - $group_by, - $fields - ); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - } - - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $module = $input->getOption('module'); - if (!$module) { - // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion - $module = $this->moduleQuestion($io); - $input->setOption('module', $module); - } - - $class = $input->getOption('class'); - if (!$class) { - $class = $io->ask( - $this->trans('commands.generate.plugin.migrate.source.questions.class'), - ucfirst($this->stringConverter->underscoreToCamelCase($module)), - function ($class) { - return $this->validator->validateClassName($class); - } - ); - $input->setOption('class', $class); - } - - $pluginId = $input->getOption('plugin-id'); - if (!$pluginId) { - $pluginId = $io->ask( - $this->trans('commands.generate.plugin.migrate.source.questions.plugin-id'), - $this->stringConverter->camelCaseToUnderscore($class) - ); - $input->setOption('plugin-id', $pluginId); - } - - $table = $input->getOption('table'); - if (!$table) { - $table = $io->ask( - $this->trans('commands.generate.plugin.migrate.source.questions.table'), - '' - ); - $input->setOption('table', $table); - } - - $alias = $input->getOption('alias'); - if (!$alias) { - $alias = $io->ask( - $this->trans('commands.generate.plugin.migrate.source.questions.alias'), - substr($table, 0, 1) - ); - $input->setOption('alias', $alias); - } - - $groupBy = $input->getOption('group-by'); - if ($groupBy == '') { - $groupBy = $io->ask( - $this->trans('commands.generate.plugin.migrate.source.questions.group-by'), - false - ); - $input->setOption('group-by', $groupBy); - } - - $fields = $input->getOption('fields'); - if (!$fields) { - $fields = []; - while (true) { - $id = $io->ask( - $this->trans('commands.generate.plugin.migrate.source.questions.fields.id'), - false - ); - if (!$id) { - break; - } - $description = $io->ask( - $this->trans('commands.generate.plugin.migrate.source.questions.fields.description'), - $id - ); - $fields[] = [ - 'id' => $id, - 'description' => $description, - ]; - } - $input->setOption('fields', $fields); - } - } -} diff --git a/src/Command/Generate/PluginRestResourceCommand.php b/src/Command/Generate/PluginRestResourceCommand.php deleted file mode 100644 index c11e9685d..000000000 --- a/src/Command/Generate/PluginRestResourceCommand.php +++ /dev/null @@ -1,225 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:rest:resource') - ->setDescription($this->trans('commands.generate.plugin.rest.resource.description')) - ->setHelp($this->trans('commands.generate.plugin.rest.resource.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.rest.resource.options.class') - ) - ->addOption( - 'name', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.service.options.name') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.rest.resource.options.plugin-id') - ) - ->addOption( - 'plugin-label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.rest.resource.options.plugin-label') - ) - ->addOption( - 'plugin-url', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.generate.plugin.rest.resource.options.plugin-url') - ) - ->addOption( - 'plugin-states', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.generate.plugin.rest.resource.options.plugin-states') - ) - ->setAliases(['gprr']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $plugin_id = $input->getOption('plugin-id'); - $plugin_label = $input->getOption('plugin-label'); - $plugin_url = $input->getOption('plugin-url'); - $plugin_states = $input->getOption('plugin-states'); - - $this->generator->generate($module, $class_name, $plugin_label, $plugin_id, $plugin_url, $plugin_states); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 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_name = $input->getOption('class'); - if (!$class_name) { - $stringUtils = $this->stringConverter; - $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'), - $this->stringConverter->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->stringConverter->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 = ['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); - } - } -} diff --git a/src/Command/Generate/PluginRulesActionCommand.php b/src/Command/Generate/PluginRulesActionCommand.php deleted file mode 100644 index 6a063f2b7..000000000 --- a/src/Command/Generate/PluginRulesActionCommand.php +++ /dev/null @@ -1,220 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:rulesaction') - ->setDescription($this->trans('commands.generate.plugin.rulesaction.description')) - ->setHelp($this->trans('commands.generate.plugin.rulesaction.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.rulesaction.options.class') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.rulesaction.options.label') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.rulesaction.options.plugin-id') - ) - ->addOption('type', null, InputOption::VALUE_REQUIRED, $this->trans('commands.generate.plugin.rulesaction.options.type')) - ->addOption( - 'category', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.generate.plugin.rulesaction.options.category') - ) - ->addOption( - 'context', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.rulesaction.options.context') - ) - ->setAliases(['gpra']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $label = $input->getOption('label'); - $plugin_id = $input->getOption('plugin-id'); - $type = $input->getOption('type'); - $category = $input->getOption('category'); - $context = $input->getOption('context'); - - $this->generator->generate($module, $class_name, $label, $plugin_id, $category, $context, $type); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 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_name = $input->getOption('class'); - if (!$class_name) { - $class_name = $io->ask( - $this->trans('commands.generate.plugin.rulesaction.options.class'), - 'DefaultAction' - ); - $input->setOption('class', $class_name); - } - - // --label option - $label = $input->getOption('label'); - if (!$label) { - $label = $io->ask( - $this->trans('commands.generate.plugin.rulesaction.options.label'), - $this->stringConverter->camelCaseToHuman($class_name) - ); - $input->setOption('label', $label); - } - - // --plugin-id option - $plugin_id = $input->getOption('plugin-id'); - if (!$plugin_id) { - $plugin_id = $io->ask( - $this->trans('commands.generate.plugin.rulesaction.options.plugin-id'), - $this->stringConverter->camelCaseToUnderscore($class_name) - ); - $input->setOption('plugin-id', $plugin_id); - } - - // --type option - $type = $input->getOption('type'); - if (!$type) { - $type = $io->ask( - $this->trans('commands.generate.plugin.rulesaction.options.type'), - 'user' - ); - $input->setOption('type', $type); - } - - // --category option - $category = $input->getOption('category'); - if (!$category) { - $category = $io->ask( - $this->trans('commands.generate.plugin.rulesaction.options.category'), - $this->stringConverter->camelCaseToUnderscore($class_name) - ); - $input->setOption('category', $category); - } - - // --context option - $context = $input->getOption('context'); - if (!$context) { - $context = $io->ask( - $this->trans('commands.generate.plugin.rulesaction.options.context'), - $this->stringConverter->camelCaseToUnderscore($class_name) - ); - $input->setOption('context', $context); - } - } -} diff --git a/src/Command/Generate/PluginSkeletonCommand.php b/src/Command/Generate/PluginSkeletonCommand.php deleted file mode 100644 index f1fb5ee18..000000000 --- a/src/Command/Generate/PluginSkeletonCommand.php +++ /dev/null @@ -1,384 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->validator = $validator; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected $pluginGeneratorsImplemented = [ - 'block' => 'generate:plugin:block', - 'ckeditor.plugin' => 'generate:plugin:ckeditorbutton', - 'condition' => 'generate:plugin:condition', - 'field.formatter' => 'generate:plugin:fieldformatter', - 'field.field_type' => 'generate:plugin:fieldtype', - 'field.widget' =>'generate:plugin:fieldwidget', - 'image.effect' => 'generate:plugin:imageeffect', - 'mail' => 'generate:plugin:mail' - ]; - - protected function configure() - { - $this - ->setName('generate:plugin:skeleton') - ->setDescription($this->trans('commands.generate.plugin.skeleton.description')) - ->setHelp($this->trans('commands.generate.plugin.skeleton.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'plugin-id', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.options.plugin-id') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.block.options.class') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL| InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - $plugins = $this->getPlugins(); - - // @see use Drupal\Console\Command\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - - $pluginId = $input->getOption('plugin-id'); - $plugin = ucfirst($this->stringConverter->underscoreToCamelCase($pluginId)); - - // Confirm that plugin.manager is available - if (!$this->validator->validatePluginManagerServiceExist($pluginId, $plugins)) { - throw new \Exception( - sprintf( - $this->trans('commands.generate.plugin.skeleton.messages.plugin-dont-exist'), - $pluginId - ) - ); - } - - if (array_key_exists($pluginId, $this->pluginGeneratorsImplemented)) { - $io->warning( - sprintf( - $this->trans('commands.generate.plugin.skeleton.messages.plugin-generator-implemented'), - $pluginId, - $this->pluginGeneratorsImplemented[$pluginId] - ) - ); - } - - $className = $input->getOption('class'); - $services = $input->getOption('services'); - - // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices - $buildServices = $this->buildServices($services); - $pluginMetaData = $this->getPluginMetadata($pluginId); - - $this->generator->generate($module, $pluginId, $plugin, $className, $pluginMetaData, $buildServices); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 0; - } - - 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); - } - } - - protected function getPluginMetadata($pluginId) - { - $pluginMetaData = [ - 'serviceId' => 'plugin.manager.' . $pluginId, - ]; - - // Load service and create reflection - $service = \Drupal::service($pluginMetaData['serviceId']); - - $reflectionClass = new \ReflectionClass($service); - - // Get list of properties with $reflectionClass->getProperties(); - $pluginManagerProperties = [ - 'subdir' => 'subdir', - 'pluginInterface' => 'pluginInterface', - 'pluginDefinitionAnnotationName' => 'pluginAnnotation', - ]; - - foreach ($pluginManagerProperties as $propertyName => $key) { - if (!$reflectionClass->hasProperty($propertyName)) { - $pluginMetaData[$key] = ''; - continue; - } - - $property = $reflectionClass->getProperty($propertyName); - $property->setAccessible(true); - $pluginMetaData[$key] = $property->getValue($service); - } - - if (empty($pluginMetaData['pluginInterface'])) { - $pluginMetaData['pluginInterfaceMethods'] = []; - } else { - $pluginMetaData['pluginInterfaceMethods'] = $this->getClassMethods($pluginMetaData['pluginInterface']); - } - - if (isset($pluginMetaData['pluginAnnotation']) && class_exists($pluginMetaData['pluginAnnotation'])) { - $pluginMetaData['pluginAnnotationProperties'] = $this->getPluginAnnotationProperties($pluginMetaData['pluginAnnotation']); - } else { - $pluginMetaData['pluginAnnotationProperties'] = []; - } - - return $pluginMetaData; - } - - /** - * Get data for the methods of a class. - * - * @param $class - * The fully-qualified name of class. - * - * @return - * An array keyed by method name, where each value is an array containing: - * - 'name: The name of the method. - * - 'declaration': The function declaration line. - * - 'description': The description from the method's docblock first line. - */ - protected function getClassMethods($class) - { - // Get a reflection class. - $classReflection = new \ReflectionClass($class); - $methods = $classReflection->getMethods(); - - $metaData = []; - $methodData = []; - - foreach ($methods as $method) { - $methodData['name'] = $method->getName(); - - $filename = $method->getFileName(); - $source = file($filename); - $startLine = $method->getStartLine(); - - $methodData['declaration'] = substr(trim($source[$startLine - 1]), 0, -1); - - $methodDocComment = explode("\n", $method->getDocComment()); - foreach ($methodDocComment as $line) { - if (substr($line, 0, 5) == ' * ') { - $methodData['description'] = substr($line, 5); - break; - } - } - - $metaData[$method->getName()] = $methodData; - } - - return $metaData; - } - - /** - * Get the list of properties from an annotation class. - * - * @param $pluginAnnotationClass - * The fully-qualified name of the plugin annotation class. - * - * @return - * An array keyed by property name, where each value is an array containing: - * - 'name: The name of the property. - * - 'description': The description from the property's docblock first line. - */ - protected function getPluginAnnotationProperties($pluginAnnotationClass) - { - // Get a reflection class for the annotation class. - // Each property of the annotation class describes a property for the - // plugin annotation. - $annotationReflection = new \ReflectionClass($pluginAnnotationClass); - $propertiesReflection = $annotationReflection->getProperties(\ReflectionProperty::IS_PUBLIC); - - $pluginProperties = []; - $annotationPropertyMetadata = []; - - foreach ($propertiesReflection as $propertyReflection) { - $annotationPropertyMetadata['name'] = $propertyReflection->name; - - $propertyDocblock = $propertyReflection->getDocComment(); - $propertyDocblockLines = explode("\n", $propertyDocblock); - foreach ($propertyDocblockLines as $line) { - if (substr($line, 0, 3) == '/**') { - continue; - } - - // Take the first actual docblock line to be the description. - if (!isset($annotationPropertyMetadata['description']) && substr($line, 0, 5) == ' * ') { - $annotationPropertyMetadata['description'] = substr($line, 5); - } - - // Look for a @var token, to tell us the type of the property. - if (substr($line, 0, 10) == ' * @var ') { - $annotationPropertyMetadata['type'] = substr($line, 10); - } - } - - $pluginProperties[$propertyReflection->name] = $annotationPropertyMetadata; - } - - return $pluginProperties; - } - - protected function getPlugins() - { - $plugins = []; - - foreach ($this->container->getServiceIds() as $serviceId) { - if (strpos($serviceId, 'plugin.manager.') === 0) { - $plugins[] = substr($serviceId, 15); - } - } - - return $plugins; - } -} diff --git a/src/Command/Generate/PluginTypeAnnotationCommand.php b/src/Command/Generate/PluginTypeAnnotationCommand.php deleted file mode 100644 index 93bd76d82..000000000 --- a/src/Command/Generate/PluginTypeAnnotationCommand.php +++ /dev/null @@ -1,153 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:type:annotation') - ->setDescription($this->trans('commands.generate.plugin.type.annotation.description')) - ->setHelp($this->trans('commands.generate.plugin.type.annotation.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.type.annotation.options.class') - ) - ->addOption( - 'machine-name', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.type.annotation.options.plugin-id') - ) - ->addOption( - 'label', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.type.annotation.options.label') - ) - ->setAliases(['gpta']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $machine_name = $input->getOption('machine-name'); - $label = $input->getOption('label'); - - $this->generator->generate($module, $class_name, $machine_name, $label); - } - - 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_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->stringConverter->camelCaseToUnderscore($class_name) - ); - $input->setOption('machine-name', $machine_name); - } - - // --label option - $label = $input->getOption('label'); - if (!$label) { - $label = $io->ask( - $this->trans('commands.generate.plugin.type.annotation.options.label'), - $this->stringConverter->camelCaseToHuman($class_name) - ); - $input->setOption('label', $label); - } - } -} diff --git a/src/Command/Generate/PluginTypeYamlCommand.php b/src/Command/Generate/PluginTypeYamlCommand.php deleted file mode 100644 index 3674b6ec4..000000000 --- a/src/Command/Generate/PluginTypeYamlCommand.php +++ /dev/null @@ -1,154 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:type:yaml') - ->setDescription($this->trans('commands.generate.plugin.type.yaml.description')) - ->setHelp($this->trans('commands.generate.plugin.type.yaml.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.type.yaml.options.class') - ) - ->addOption( - 'plugin-name', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.type.yaml.options.plugin-name') - ) - ->addOption( - 'plugin-file-name', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.type.yaml.options.plugin-file-name') - ) - ->setAliases(['gpty']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $plugin_name = $input->getOption('plugin-name'); - $plugin_file_name = $input->getOption('plugin-file-name'); - - $this->generator->generate($module, $class_name, $plugin_name, $plugin_file_name); - } - - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // --module option - $module = $input->getOption('module'); - if (!$module) { - // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion - $module = $this->moduleQuestion($io); - $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->stringConverter->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); - } - } -} diff --git a/src/Command/Generate/PluginViewsFieldCommand.php b/src/Command/Generate/PluginViewsFieldCommand.php deleted file mode 100644 index b91b08ad8..000000000 --- a/src/Command/Generate/PluginViewsFieldCommand.php +++ /dev/null @@ -1,185 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->site = $site; - $this->stringConverter = $stringConverter; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:plugin:views:field') - ->setDescription($this->trans('commands.generate.plugin.views.field.description')) - ->setHelp($this->trans('commands.generate.plugin.views.field.help')) - ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.plugin.views.field.options.class') - ) - ->addOption( - 'title', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.views.field.options.title') - ) - ->addOption( - 'description', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.plugin.views.field.options.description') - ) - ->setAliases(['gpvf']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $class_name = $input->getOption('class'); - $class_machine_name = $this->stringConverter->camelCaseToUnderscore($class_name); - $title = $input->getOption('title'); - $description = $input->getOption('description'); - - $this->generator->generate($module, $class_machine_name, $class_name, $title, $description); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 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_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->stringConverter->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); - } - } - - protected function createGenerator() - { - return new PluginViewsFieldGenerator(); - } -} diff --git a/src/Command/Generate/PostUpdateCommand.php b/src/Command/Generate/PostUpdateCommand.php deleted file mode 100644 index 180a70c0d..000000000 --- a/src/Command/Generate/PostUpdateCommand.php +++ /dev/null @@ -1,198 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->site = $site; - $this->validator = $validator; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:post:update') - ->setDescription($this->trans('commands.generate.post:update.description')) - ->setHelp($this->trans('commands.generate.post.update.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'post-update-name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.post.update.options.post-update-name') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $postUpdateName = $input->getOption('post-update-name'); - - $this->validatePostUpdateName($module, $postUpdateName); - - $this->generator->generate($module, $postUpdateName); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 0; - } - - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $this->site->loadLegacyFile('/core/includes/update.inc'); - $this->site->loadLegacyFile('/core/includes/schema.inc'); - - $module = $input->getOption('module'); - if (!$module) { - // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion - $module = $this->moduleQuestion($io); - $input->setOption('module', $module); - } - - $postUpdateName = $input->getOption('post-update-name'); - if (!$postUpdateName) { - $postUpdateName = $io->ask( - $this->trans('commands.generate.post.update.questions.post-update-name'), - '', - function ($postUpdateName) { - return $this->validator->validateSpaces($postUpdateName); - } - ); - - $input->setOption('post-update-name', $postUpdateName); - } - } - - - protected function createGenerator() - { - return new PostUpdateGenerator(); - } - - protected function getLastUpdate($module) - { - $this->site->loadLegacyFile('/core/includes/update.inc'); - $this->site->loadLegacyFile('/core/includes/schema.inc'); - - $updates = update_get_update_list(); - - if (empty($updates[$module]['pending'])) { - $lastUpdateSchema = drupal_get_schema_versions($module); - } else { - $lastUpdateSchema = reset(array_keys($updates[$module]['pending'], max($updates[$module]['pending']))); - } - - return $lastUpdateSchema; - } - - 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 - ) - ); - } - } -} diff --git a/src/Command/Generate/ProfileCommand.php b/src/Command/Generate/ProfileCommand.php deleted file mode 100644 index 5dfbe1509..000000000 --- a/src/Command/Generate/ProfileCommand.php +++ /dev/null @@ -1,270 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->validator = $validator; - $this->appRoot = $appRoot; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:profile') - ->setDescription($this->trans('commands.generate.profile.description')) - ->setHelp($this->trans('commands.generate.profile.help')) - ->addOption( - 'profile', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.profile.options.profile') - ) - ->addOption( - 'machine-name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.profile.options.machine-name') - ) - ->addOption( - 'description', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.profile.options.description') - ) - ->addOption( - 'core', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.profile.options.core') - ) - ->addOption( - 'dependencies', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.profile.options.dependencies'), - '' - ) - ->addOption( - 'themes', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.profile.options.themes'), - '' - ) - ->addOption( - 'distribution', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.profile.options.distribution') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - if (!$this->confirmGeneration($io)) { - return 1; - } - - $profile = $this->validator->validateModuleName($input->getOption('profile')); - $machine_name = $this->validator->validateMachineName($input->getOption('machine-name')); - $description = $input->getOption('description'); - $core = $input->getOption('core'); - $dependencies = $this->validator->validateExtensions($input->getOption('dependencies'), 'module', $io); - $themes = $this->validator->validateExtensions($input->getOption('themes'), 'theme', $io); - $distribution = $input->getOption('distribution'); - $profile_path = $this->appRoot . '/profiles'; - - $this->generator->generate( - $profile, - $machine_name, - $profile_path, - $description, - $core, - $dependencies, - $themes, - $distribution - ); - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - //$stringUtils = $this->getStringHelper(); - $validators = $this->validator; - - try { - // A profile is technically also a module, so we can use the same - // validator to check the name. - $profile = $input->getOption('profile') ? $validators->validateModuleName($input->getOption('profile')) : null; - } catch (\Exception $error) { - $io->error($error->getMessage()); - - return 1; - } - - if (!$profile) { - $profile = $io->ask( - $this->trans('commands.generate.profile.questions.profile'), - '', - function ($profile) use ($validators) { - return $validators->validateModuleName($profile); - } - ); - $input->setOption('profile', $profile); - } - - try { - $machine_name = $input->getOption('machine-name') ? $validators->validateModuleName($input->getOption('machine-name')) : null; - } catch (\Exception $error) { - $io->error($error->getMessage()); - - return 1; - } - - if (!$machine_name) { - $machine_name = $io->ask( - $this->trans('commands.generate.profile.questions.machine-name'), - $this->stringConverter->createMachineName($profile), - function ($machine_name) use ($validators) { - return $validators->validateMachineName($machine_name); - } - ); - $input->setOption('machine-name', $machine_name); - } - - $description = $input->getOption('description'); - if (!$description) { - $description = $io->ask( - $this->trans('commands.generate.profile.questions.description'), - 'My Useful Profile' - ); - $input->setOption('description', $description); - } - - $core = $input->getOption('core'); - if (!$core) { - $core = $io->ask( - $this->trans('commands.generate.profile.questions.core'), - '8.x' - ); - $input->setOption('core', $core); - } - - $dependencies = $input->getOption('dependencies'); - if (!$dependencies) { - if ($io->confirm( - $this->trans('commands.generate.profile.questions.dependencies'), - true - ) - ) { - $dependencies = $io->ask( - $this->trans('commands.generate.profile.options.dependencies'), - '' - ); - } - $input->setOption('dependencies', $dependencies); - } - - $distribution = $input->getOption('distribution'); - if (!$distribution) { - if ($io->confirm( - $this->trans('commands.generate.profile.questions.distribution'), - false - ) - ) { - $distribution = $io->ask( - $this->trans('commands.generate.profile.options.distribution'), - 'My Kick-ass Distribution' - ); - $input->setOption('distribution', $distribution); - } - } - } - - /** - * @return ProfileGenerator - */ - protected function createGenerator() - { - return new ProfileGenerator(); - } -} diff --git a/src/Command/Generate/RouteSubscriberCommand.php b/src/Command/Generate/RouteSubscriberCommand.php deleted file mode 100644 index 1085ea469..000000000 --- a/src/Command/Generate/RouteSubscriberCommand.php +++ /dev/null @@ -1,158 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:routesubscriber') - ->setDescription($this->trans('commands.generate.routesubscriber.description')) - ->setHelp($this->trans('commands.generate.routesubscriber.description')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.routesubscriber.options.name') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.routesubscriber.options.class') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $output = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($output)) { - return 1; - } - - $module = $input->getOption('module'); - $name = $input->getOption('name'); - $class = $input->getOption('class'); - - $this->generator->generate($module, $name, $class); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); - - return 0; - } - - /** - * {@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); - } - - // --name option - $name = $input->getOption('name'); - if (!$name) { - $name = $io->ask( - $this->trans('commands.generate.routesubscriber.questions.name'), - $module.'.route_subscriber' - ); - $input->setOption('name', $name); - } - - // --class option - $class = $input->getOption('class'); - if (!$class) { - $class = $io->ask( - $this->trans('commands.generate.routesubscriber.questions.class'), - 'RouteSubscriber' - ); - $input->setOption('class', $class); - } - } - - protected function createGenerator() - { - return new RouteSubscriberGenerator(); - } -} diff --git a/src/Command/Generate/ServiceCommand.php b/src/Command/Generate/ServiceCommand.php deleted file mode 100644 index 859bcfe1b..000000000 --- a/src/Command/Generate/ServiceCommand.php +++ /dev/null @@ -1,244 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->stringConverter = $stringConverter; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:service') - ->setDescription($this->trans('commands.generate.service.description')) - ->setHelp($this->trans('commands.generate.service.description')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.service.options.name') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.service.options.class') - ) - ->addOption( - 'interface', - null, - InputOption::VALUE_NONE, - $this->trans('commands.common.service.options.interface') - ) - ->addOption( - 'interface-name', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.common.service.options.interface-name') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ) - ->addOption( - 'path-service', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.service.options.path') - ) - ->setAliases(['gs']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $name = $input->getOption('name'); - $class = $input->getOption('class'); - $interface = $input->getOption('interface'); - $interface_name = $input->getOption('interface-name'); - $services = $input->getOption('services'); - $path_service = $input->getOption('path-service'); - - $available_services = $this->container->getServiceIds(); - - if (in_array($name, array_values($available_services))) { - throw new \Exception( - sprintf( - $this->trans('commands.generate.service.messages.service-already-taken'), - $module - ) - ); - } - - // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices - $build_services = $this->buildServices($services); - $this->generator->generate($module, $name, $class, $interface, $interface_name, $build_services, $path_service); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); - - return 0; - } - - /** - * {@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); - } - - //--name option - $name = $input->getOption('name'); - if (!$name) { - $name = $io->ask( - $this->trans('commands.generate.service.questions.service-name'), - $module.'.default' - ); - $input->setOption('name', $name); - } - - // --class option - $class = $input->getOption('class'); - if (!$class) { - $class = $io->ask( - $this->trans('commands.generate.service.questions.class'), - 'DefaultService' - ); - $input->setOption('class', $class); - } - - // --interface option - $interface = $input->getOption('interface'); - if (!$interface) { - $interface = $io->confirm( - $this->trans('commands.generate.service.questions.interface'), - true - ); - $input->setOption('interface', $interface); - } - - // --interface_name option - $interface_name = $input->getOption('interface-name'); - if ($interface && !$interface_name) { - $interface_name = $io->askEmpty( - $this->trans('commands.generate.service.questions.interface-name') - ); - $input->setOption('interface-name', $interface_name); - } - - // --services option - $services = $input->getOption('services'); - if (!$services) { - // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion - $services = $this->servicesQuestion($io); - $input->setOption('services', $services); - } - - // --path_service option - $path_service = $input->getOption('path-service'); - if (!$path_service) { - $path_service = $io->ask( - $this->trans('commands.generate.service.questions.path'), - '/modules/custom/' . $module . '/src/' - ); - $input->setOption('path-service', $path_service); - } - } -} diff --git a/src/Command/Generate/ThemeCommand.php b/src/Command/Generate/ThemeCommand.php deleted file mode 100644 index 8c598baf2..000000000 --- a/src/Command/Generate/ThemeCommand.php +++ /dev/null @@ -1,383 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->validator = $validator; - $this->appRoot = $appRoot; - $this->themeHandler = $themeHandler; - $this->site = $site; - $this->stringConverter = $stringConverter; - parent::__construct(); - } - - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:theme') - ->setDescription($this->trans('commands.generate.theme.description')) - ->setHelp($this->trans('commands.generate.theme.help')) - ->addOption( - 'theme', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.theme.options.module') - ) - ->addOption( - 'machine-name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.theme.options.machine-name') - ) - ->addOption( - 'theme-path', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.theme.options.module-path') - ) - ->addOption( - 'description', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.theme.options.description') - ) - ->addOption('core', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.theme.options.core')) - ->addOption( - 'package', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.theme.options.package') - ) - ->addOption( - 'global-library', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.theme.options.global-library') - ) - ->addOption( - 'libraries', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.theme.options.libraries') - ) - ->addOption( - 'base-theme', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.theme.options.base-theme') - ) - ->addOption( - 'regions', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.theme.options.regions') - ) - ->addOption( - 'breakpoints', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.theme.options.breakpoints') - ) - ->setAliases(['gt']); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $theme = $this->validator->validateModuleName($input->getOption('theme')); - $theme_path = $this->appRoot . $input->getOption('theme-path'); - $theme_path = $this->validator->validateModulePath($theme_path, true); - - $machine_name = $this->validator->validateMachineName($input->getOption('machine-name')); - $description = $input->getOption('description'); - $core = $input->getOption('core'); - $package = $input->getOption('package'); - $base_theme = $input->getOption('base-theme'); - $global_library = $input->getOption('global-library'); - $libraries = $input->getOption('libraries'); - $regions = $input->getOption('regions'); - $breakpoints = $input->getOption('breakpoints'); - - $this->generator->generate( - $theme, - $machine_name, - $theme_path, - $description, - $core, - $package, - $base_theme, - $global_library, - $libraries, - $regions, - $breakpoints - ); - - return 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 1; - } - - 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 1; - } - - if (!$machine_name) { - $machine_name = $io->ask( - $this->trans('commands.generate.theme.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); - } - - - // --libraries option. - $libraries = $input->getOption('libraries'); - if (!$libraries) { - if ($io->confirm( - $this->trans('commands.generate.theme.questions.library-add'), - true - ) - ) { - // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::libraryQuestion - $libraries = $this->libraryQuestion($io); - $input->setOption('libraries', $libraries); - } - } - - // --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); - } - } - } -} diff --git a/src/Command/Generate/TwigExtensionCommand.php b/src/Command/Generate/TwigExtensionCommand.php deleted file mode 100644 index 182f408b8..000000000 --- a/src/Command/Generate/TwigExtensionCommand.php +++ /dev/null @@ -1,192 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->site = $site; - $this->stringConverter = $stringConverter; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('generate:twig:extension') - ->setDescription($this->trans('commands.generate.twig.extension.description')) - ->setHelp($this->trans('commands.generate.twig.extension.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'name', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.twig.extension.options.name') - ) - ->addOption( - 'class', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.class') - ) - ->addOption( - 'services', - null, - InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - $this->trans('commands.common.options.services') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $name = $input->getOption('name'); - $class = $input->getOption('class'); - $services = $input->getOption('services'); - // Add renderer service as first parameter. - array_unshift($services, 'renderer'); - - // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices - $build_services = $this->buildServices($services); - - $this->generator->generate($module, $name, $class, $build_services); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); - - return 0; - } - - /** - * {@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); - } - - // --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($io); - $input->setOption('services', $services); - } - } -} diff --git a/src/Command/Generate/UpdateCommand.php b/src/Command/Generate/UpdateCommand.php deleted file mode 100644 index 923970a7e..000000000 --- a/src/Command/Generate/UpdateCommand.php +++ /dev/null @@ -1,199 +0,0 @@ -extensionManager = $extensionManager; - $this->generator = $generator; - $this->site = $site; - $this->chainQueue = $chainQueue; - parent::__construct(); - } - - protected function configure() - { - $this - ->setName('generate:update') - ->setDescription($this->trans('commands.generate.update.description')) - ->setHelp($this->trans('commands.generate.update.help')) - ->addOption( - 'module', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.common.options.module') - ) - ->addOption( - 'update-n', - null, - InputOption::VALUE_REQUIRED, - $this->trans('commands.generate.update.options.update-n') - ); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io)) { - return 1; - } - - $module = $input->getOption('module'); - $updateNumber = $input->getOption('update-n'); - - $lastUpdateSchema = $this->getLastUpdate($module); - - if ($updateNumber <= $lastUpdateSchema) { - throw new \InvalidArgumentException( - sprintf( - $this->trans('commands.generate.update.messages.wrong-update-n'), - $updateNumber - ) - ); - } - - $this->generator->generate($module, $updateNumber); - - $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); - - return 0; - } - - protected function interact(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $this->site->loadLegacyFile('/core/includes/update.inc'); - $this->site->loadLegacyFile('/core/includes/schema.inc'); - - $module = $input->getOption('module'); - if (!$module) { - // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion - $module = $this->moduleQuestion($io); - $input->setOption('module', $module); - } - - $lastUpdateSchema = $this->getLastUpdate($module); - $nextUpdateSchema = $lastUpdateSchema ? ($lastUpdateSchema + 1): 8001; - - $updateNumber = $input->getOption('update-n'); - if (!$updateNumber) { - $updateNumber = $io->ask( - $this->trans('commands.generate.update.questions.update-n'), - $nextUpdateSchema, - function ($updateNumber) use ($lastUpdateSchema) { - if (!is_numeric($updateNumber)) { - throw new \InvalidArgumentException( - sprintf( - $this->trans('commands.generate.update.messages.wrong-update-n'), - $updateNumber - ) - ); - } else { - if ($updateNumber <= $lastUpdateSchema) { - throw new \InvalidArgumentException( - sprintf( - $this->trans('commands.generate.update.messages.wrong-update-n'), - $updateNumber - ) - ); - } - return $updateNumber; - } - } - ); - - $input->setOption('update-n', $updateNumber); - } - } - - - protected function createGenerator() - { - return new UpdateGenerator(); - } - - protected function getLastUpdate($module) - { - $this->site->loadLegacyFile('/core/includes/update.inc'); - $this->site->loadLegacyFile('/core/includes/schema.inc'); - - $updates = update_get_update_list(); - - if (empty($updates[$module]['pending'])) { - $lastUpdateSchema = drupal_get_schema_versions($module); - $lastUpdateSchema = $lastUpdateSchema[0]; - } else { - $lastUpdateSchema = reset(array_keys($updates[$module]['pending'], max($updates[$module]['pending']))); - } - - return $lastUpdateSchema; - } -} diff --git a/src/Generator/AuthenticationProviderGenerator.php b/src/Generator/AuthenticationProviderGenerator.php deleted file mode 100644 index 4fd53df28..000000000 --- a/src/Generator/AuthenticationProviderGenerator.php +++ /dev/null @@ -1,75 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Block. - * - * @param $module - * @param $class - * @param $provider_id - */ - public function generate($module, $class, $provider_id) - { - $parameters = [ - 'module' => $module, - 'class' => $class, - ]; - - $this->renderFile( - 'module/src/Authentication/Provider/authentication-provider.php.twig', - $this->extensionManager->getModule($module)->getAuthenticationPath('Provider'). '/' . $class . '.php', - $parameters - ); - - $parameters = [ - 'module' => $module, - 'class' => $class, - 'class_path' => sprintf('Drupal\%s\Authentication\Provider\%s', $module, $class), - 'name' => 'authentication.'.$module, - 'services' => [ - ['name' => 'config.factory'], - ['name' => 'entity_type.manager'], - ], - 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), - 'tags' => [ - 'name' => 'authentication_provider', - 'provider_id' => $provider_id, - 'priority' => '100', - ], - ]; - - $this->renderFile( - 'module/services.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/BreakPointGenerator.php b/src/Generator/BreakPointGenerator.php deleted file mode 100644 index 7e91e0e35..000000000 --- a/src/Generator/BreakPointGenerator.php +++ /dev/null @@ -1,61 +0,0 @@ -extensionManager = $extensionManager; - } - - - /** - * Generator BreakPoint. - * - * @param $theme - * @param $breakpoints - * @param $machine_name - */ - public function generate($theme, $breakpoints, $machine_name) - { - $parameters = [ - 'theme' => $theme, - 'breakpoints' => $breakpoints, - 'machine_name' => $machine_name - ]; - - $theme_path = $this->extensionManager->getTheme($theme)->getPath(); - - $this->renderFile( - 'theme/breakpoints.yml.twig', - $theme_path .'/'.$machine_name.'.breakpoints.yml', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/CacheContextGenerator.php b/src/Generator/CacheContextGenerator.php deleted file mode 100644 index da87ee974..000000000 --- a/src/Generator/CacheContextGenerator.php +++ /dev/null @@ -1,64 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Service. - * - * @param string $module Module name - * @param string $cache_context Cache context name - * @param string $class Class name - * @param array $services List of services - */ - public function generate($module, $cache_context, $class, $services) - { - $parameters = [ - 'module' => $module, - 'name' => 'cache_context.' . $cache_context, - 'class' => $class, - 'services' => $services, - 'class_path' => sprintf('Drupal\%s\CacheContext\%s', $module, $class), - 'tags' => ['name' => 'cache.context'], - 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), - ]; - - $this->renderFile( - 'module/src/cache-context.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/CacheContext/'.$class.'.php', - $parameters - ); - - $this->renderFile( - 'module/services.yml.twig', - $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/CommandGenerator.php b/src/Generator/CommandGenerator.php deleted file mode 100644 index ff01bd572..000000000 --- a/src/Generator/CommandGenerator.php +++ /dev/null @@ -1,94 +0,0 @@ -extensionManager = $extensionManager; - $this->translatorManager = $translatorManager; - } - - /** - * Generate. - * - * @param string $extension Extension name - * @param string $extensionType Extension type - * @param string $name Command name - * @param string $class Class name - * @param boolean $containerAware Container Aware command - * @param array $services Services array - */ - public function generate($extension, $extensionType, $name, $class, $containerAware, $services) - { - $command_key = str_replace(':', '.', $name); - - $extensionObject = $this->extensionManager->getDrupalExtension($extensionType, $extension); - - $parameters = [ - 'extension' => $extension, - 'extensionType' => $extensionType, - 'name' => $name, - 'class_name' => $class, - 'container_aware' => $containerAware, - 'command_key' => $command_key, - 'services' => $services, - 'tags' => ['name' => 'drupal.command'], - 'class_path' => sprintf('Drupal\%s\Command\%s', $extension, $class), - 'file_exists' => file_exists($extensionObject->getPath().'/console.services.yml'), - ]; - - $this->renderFile( - 'module/src/Command/command.php.twig', - $extensionObject->getCommandDirectory().$class.'.php', - $parameters - ); - - $parameters['name'] = $extension.'.'.str_replace(':', '_', $name); - - $this->renderFile( - 'module/services.yml.twig', - $extensionObject->getPath() .'/console.services.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/src/Command/console/translations/en/command.yml.twig', - $extensionObject->getPath().'/console/translations/en/'.$command_key.'.yml' - ); - } -} diff --git a/src/Generator/ControllerGenerator.php b/src/Generator/ControllerGenerator.php deleted file mode 100644 index bb95974d8..000000000 --- a/src/Generator/ControllerGenerator.php +++ /dev/null @@ -1,62 +0,0 @@ -extensionManager = $extensionManager; - } - - public function generate($module, $class, $routes, $test, $services) - { - $parameters = [ - 'class_name' => $class, - 'services' => $services, - 'module' => $module, - 'routes' => $routes, - //'learning' => $this->isLearning(), - ]; - - $this->renderFile( - 'module/src/Controller/controller.php.twig', - $this->extensionManager->getModule($module)->getControllerPath().'/'.$class.'.php', - $parameters - ); - - $this->renderFile( - 'module/routing-controller.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.routing.yml', - $parameters, - FILE_APPEND - ); - - if ($test) { - $this->renderFile( - 'module/Tests/Controller/controller.php.twig', - $this->extensionManager->getModule($module)->getTestPath('Controller').'/'.$class.'Test.php', - $parameters - ); - } - } -} diff --git a/src/Generator/EntityBundleGenerator.php b/src/Generator/EntityBundleGenerator.php deleted file mode 100644 index 18e6ac6c5..000000000 --- a/src/Generator/EntityBundleGenerator.php +++ /dev/null @@ -1,86 +0,0 @@ -extensionManager = $extensionManager; - } - - public function generate($module, $bundleName, $bundleTitle) - { - $parameters = [ - 'module' => $module, - 'bundle_name' => $bundleName, - 'bundle_title' => $bundleTitle, - //TODO: - //'learning' => $this->isLearning(), - ]; - - /** - * Generate core.entity_form_display.node.{ bundle_name }.default.yml - */ - $this->renderFile( - 'module/src/Entity/Bundle/core.entity_form_display.node.default.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/config/install/core.entity_form_display.node.' . $bundleName . '.default.yml', - $parameters - ); - - /** - * Generate core.entity_view_display.node.{ bundle_name }.default.yml - */ - $this->renderFile( - 'module/src/Entity/Bundle/core.entity_view_display.node.default.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/config/install/core.entity_view_display.node.' . $bundleName . '.default.yml', - $parameters - ); - - /** - * Generate core.entity_view_display.node.{ bundle_name }.teaser.yml - */ - $this->renderFile( - 'module/src/Entity/Bundle/core.entity_view_display.node.teaser.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/config/install/core.entity_view_display.node.' . $bundleName . '.teaser.yml', - $parameters - ); - - /** - * Generate field.field.node.{ bundle_name }.body.yml - */ - $this->renderFile( - 'module/src/Entity/Bundle/field.field.node.body.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/config/install/field.field.node.' . $bundleName . '.body.yml', - $parameters - ); - - /** - * Generate node.type.{ bundle_name }.yml - */ - $this->renderFile( - 'module/src/Entity/Bundle/node.type.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/config/install/node.type.' . $bundleName . '.yml', - $parameters - ); - } -} diff --git a/src/Generator/EntityConfigGenerator.php b/src/Generator/EntityConfigGenerator.php deleted file mode 100644 index 3a4f752b2..000000000 --- a/src/Generator/EntityConfigGenerator.php +++ /dev/null @@ -1,109 +0,0 @@ -extensionManager = $extensionManager; - } - - - /** - * Generator Entity. - * - * @param string $module Module name - * @param string $entity_name Entity machine name - * @param string $entity_class Entity class name - * @param string $label Entity label - * @param string $base_path Base path - * @param string $bundle_of Entity machine name of the content entity this config entity acts as a bundle for. - */ - public function generate($module, $entity_name, $entity_class, $label, $base_path, $bundle_of = null) - { - $parameters = [ - 'module' => $module, - 'entity_name' => $entity_name, - 'entity_class' => $entity_class, - 'label' => $label, - 'bundle_of' => $bundle_of, - 'base_path' => $base_path, - ]; - - $this->renderFile( - 'module/config/schema/entity.schema.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/config/schema/'.$entity_name.'.schema.yml', - $parameters - ); - - $this->renderFile( - 'module/links.menu-entity-config.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.menu.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/links.action-entity.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.action.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/src/Entity/interface-entity.php.twig', - $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'Interface.php', - $parameters - ); - - $this->renderFile( - 'module/src/Entity/entity.php.twig', - $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'.php', - $parameters - ); - - $this->renderFile( - 'module/src/entity-route-provider.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'HtmlRouteProvider.php', - $parameters - ); - - $this->renderFile( - 'module/src/Form/entity.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'Form.php', - $parameters - ); - - $this->renderFile( - 'module/src/Form/entity-delete.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'DeleteForm.php', - $parameters - ); - - $this->renderFile( - 'module/src/entity-listbuilder.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'ListBuilder.php', - $parameters - ); - } -} diff --git a/src/Generator/EntityContentGenerator.php b/src/Generator/EntityContentGenerator.php deleted file mode 100644 index 3c9f98cce..000000000 --- a/src/Generator/EntityContentGenerator.php +++ /dev/null @@ -1,291 +0,0 @@ -extensionManager = $extensionManager; - $this->site = $site; - $this->twigrenderer = $twigrenderer; - } - - public function setIo($io) - { - $this->io = $io; - } - - - /** - * Generator Entity. - * - * @param string $module Module name - * @param string $entity_name Entity machine name - * @param string $entity_class Entity class name - * @param string $label Entity label - * @param string $base_path Base path - * @param string $is_translatable Translation configuration - * @param string $bundle_entity_type (Config) entity type acting as bundle - * @param bool $revisionable Revision configuration - */ - public function generate($module, $entity_name, $entity_class, $label, $base_path, $is_translatable, $bundle_entity_type = null, $revisionable = false) - { - $parameters = [ - 'module' => $module, - 'entity_name' => $entity_name, - 'entity_class' => $entity_class, - 'label' => $label, - 'bundle_entity_type' => $bundle_entity_type, - 'base_path' => $base_path, - 'is_translatable' => $is_translatable, - 'revisionable' => $revisionable, - ]; - - $this->renderFile( - 'module/permissions-entity-content.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.permissions.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/links.menu-entity-content.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.menu.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/links.task-entity-content.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.task.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/links.action-entity-content.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.action.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/src/accesscontrolhandler-entity-content.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'AccessControlHandler.php', - $parameters - ); - - if ($is_translatable) { - $this->renderFile( - 'module/src/entity-translation-handler.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'TranslationHandler.php', - $parameters - ); - } - - $this->renderFile( - 'module/src/Entity/interface-entity-content.php.twig', - $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'Interface.php', - $parameters - ); - - $this->renderFile( - 'module/src/Entity/entity-content.php.twig', - $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'.php', - $parameters - ); - - $this->renderFile( - 'module/src/entity-content-route-provider.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'HtmlRouteProvider.php', - $parameters - ); - - $this->renderFile( - 'module/src/Entity/entity-content-views-data.php.twig', - $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'ViewsData.php', - $parameters - ); - - $this->renderFile( - 'module/src/listbuilder-entity-content.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'ListBuilder.php', - $parameters - ); - - $this->renderFile( - 'module/src/Entity/Form/entity-settings.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'SettingsForm.php', - $parameters - ); - - $this->renderFile( - 'module/src/Entity/Form/entity-content.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'Form.php', - $parameters - ); - - $this->renderFile( - 'module/src/Entity/Form/entity-content-delete.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'DeleteForm.php', - $parameters - ); - - $this->renderFile( - 'module/entity-content-page.php.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$entity_name.'.page.inc', - $parameters - ); - - $this->renderFile( - 'module/templates/entity-html.twig', - $this->extensionManager->getModule($module)->getTemplatePath().'/'.$entity_name.'.html.twig', - $parameters - ); - - if ($revisionable) { - $this->renderFile( - 'module/src/Entity/Form/entity-content-revision-delete.php.twig', - $this->extensionManager->getModule($module)->getFormPath() .'/'.$entity_class.'RevisionDeleteForm.php', - $parameters - ); - $this->renderFile( - 'module/src/Entity/Form/entity-content-revision-revert-translation.php.twig', - $this->extensionManager->getModule($module)->getFormPath() .'/'.$entity_class.'RevisionRevertTranslationForm.php', - $parameters - ); - $this->renderFile( - 'module/src/Entity/Form/entity-content-revision-revert.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'RevisionRevertForm.php', - $parameters - ); - $this->renderFile( - 'module/src/entity-storage.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() .'/'.$entity_class.'Storage.php', - $parameters - ); - $this->renderFile( - 'module/src/interface-entity-storage.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() .'/'.$entity_class.'StorageInterface.php', - $parameters - ); - $this->renderFile( - 'module/src/Controller/entity-controller.php.twig', - $this->extensionManager->getModule($module)->getControllerPath() .'/'.$entity_class.'Controller.php', - $parameters - ); - } - - if ($bundle_entity_type) { - $this->renderFile( - 'module/templates/entity-with-bundle-content-add-list-html.twig', - $this->extensionManager->getModule($module)->getTemplatePath().'/'.str_replace('_', '-', $entity_name).'-content-add-list.html.twig', - $parameters - ); - - // Check for hook_theme() in module file and warn ... - $module_filename = $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module'; - // Check if the module file exists. - if (!file_exists($module_filename)) { - $this->renderFile( - 'module/module.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module . '.module', - [ - 'machine_name' => $module, - 'description' => '', - ] - ); - } - $module_file_contents = file_get_contents($module_filename); - if (strpos($module_file_contents, 'function ' . $module . '_theme') !== false) { - $this->io->warning( - [ - "It looks like you have a hook_theme already declared", - "Please manually merge the two hook_theme() implementations in", - $module_filename - ] - ); - } - - $this->renderFile( - 'module/src/Entity/entity-content-with-bundle.theme.php.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module', - $parameters, - FILE_APPEND - ); - - if (strpos($module_file_contents, 'function ' . $module . '_theme_suggestions_' . $entity_name) !== false) { - $this->io->warning( - [ - "It looks like you have a hook_theme_suggestions_HOOK already declared", - "Please manually merge the two hook_theme_suggestions_HOOK() implementations in", - $module_filename - ] - ); - } - - $this->renderFile( - 'module/src/Entity/entity-content-with-bundle.theme_hook_suggestions.php.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module', - $parameters, - FILE_APPEND - ); - } - - $content = $this->twigrenderer->render( - 'module/src/Entity/entity-content.theme.php.twig', - $parameters - ); - - - //@TODO: - /** - if ($this->isLearning()) { - $this->io->commentBlock( - [ - 'Add this to your hook_theme:', - $content - ] - ); - } - */ - } -} diff --git a/src/Generator/EventSubscriberGenerator.php b/src/Generator/EventSubscriberGenerator.php deleted file mode 100644 index f53178be2..000000000 --- a/src/Generator/EventSubscriberGenerator.php +++ /dev/null @@ -1,66 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Service. - * - * @param string $module Module name - * @param string $name Service name - * @param string $class Class name - * @param string $events - * @param array $services List of services - */ - public function generate($module, $name, $class, $events, $services) - { - $parameters = [ - 'module' => $module, - 'name' => $name, - 'class' => $class, - 'class_path' => sprintf('Drupal\%s\EventSubscriber\%s', $module, $class), - 'events' => $events, - 'services' => $services, - 'tags' => ['name' => 'event_subscriber'], - 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), - ]; - - $this->renderFile( - 'module/src/event-subscriber.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/EventSubscriber/'.$class.'.php', - $parameters - ); - - $this->renderFile( - 'module/services.yml.twig', - $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/FormAlterGenerator.php b/src/Generator/FormAlterGenerator.php deleted file mode 100644 index 19fba6d82..000000000 --- a/src/Generator/FormAlterGenerator.php +++ /dev/null @@ -1,57 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Block. - * - * @param $module - * @param $form_id - * @param $inputs - * @param $metadata - */ - public function generate($module, $form_id, $inputs, $metadata) - { - $parameters = [ - 'module' => $module, - 'form_id' => $form_id, - 'inputs' => $inputs, - 'metadata' => $metadata - ]; - - $module_path = $this->extensionManager->getModule($module)->getPath(); - - $this->renderFile( - 'module/src/Form/form-alter.php.twig', - $module_path .'/'.$module.'.module', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/FormGenerator.php b/src/Generator/FormGenerator.php deleted file mode 100644 index d19897480..000000000 --- a/src/Generator/FormGenerator.php +++ /dev/null @@ -1,114 +0,0 @@ -extensionManager = $extensionManager; - $this->stringConverter = $stringConverter; - } - - /** - * @param $module - * @param $class_name - * @param $services - * @param $config_file - * @param $inputs - * @param $form_id - * @param $form_type - * @param $path - * @param $menu_link_gen - * @param $menu_link_title - * @param $menu_parent - * @param $menu_link_desc - */ - public function generate($module, $class_name, $form_id, $form_type, $services, $config_file, $inputs, $path, $menu_link_gen, $menu_link_title, $menu_parent, $menu_link_desc) - { - $class_name_short = strtolower( - $this->stringConverter->removeSuffix($class_name) - ); - - $parameters = [ - 'class_name' => $class_name, - 'services' => $services, - 'config_file' => $config_file, - 'inputs' => $inputs, - 'module_name' => $module, - 'form_id' => $form_id, - 'path' => $path, - 'route_name' => $class_name, - 'menu_link_title' => $menu_link_title, - 'menu_parent' => $menu_parent, - 'menu_link_desc' => $menu_link_desc, - 'class_name_short' => $class_name_short - ]; - - if ($form_type == 'ConfigFormBase') { - $template = 'module/src/Form/form-config.php.twig'; - $parameters['config_form'] = true; - } else { - $template = 'module/src/Form/form.php.twig'; - $parameters['config_form'] = false; - } - - $this->renderFile( - 'module/routing-form.yml.twig', - $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.routing.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - $template, - $this->extensionManager->getModule($module)->getFormPath() .'/'.$class_name.'.php', - $parameters - ); - - // Render defaults YML file. - if ($config_file == true) { - $this->renderFile( - 'module/config/install/field.default.yml.twig', - $this->extensionManager->getModule($module)->getPath() .'/config/install/'.$module.'.'.$class_name_short.'.yml', - $parameters - ); - } - - if ($menu_link_gen == true) { - $this->renderFile( - 'module/links.menu.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.links.menu.yml', - $parameters, - FILE_APPEND - ); - } - } -} diff --git a/src/Generator/HelpGenerator.php b/src/Generator/HelpGenerator.php deleted file mode 100644 index 420240c19..000000000 --- a/src/Generator/HelpGenerator.php +++ /dev/null @@ -1,54 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Post Update Name function. - * - * @param $module - * @param $description - */ - public function generate($module, $description) - { - $module_path = $this->extensionManager->getModule($module)->getPath(); - - $parameters = [ - 'machine_name' => $module, - 'description' => $description, - 'file_exists' => file_exists($module_path .'/'.$module.'.module'), - ]; - - $this->renderFile( - 'module/help.php.twig', - $module_path .'/'.$module.'.module', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/ModuleFileGenerator.php b/src/Generator/ModuleFileGenerator.php deleted file mode 100644 index 8f8e84e47..000000000 --- a/src/Generator/ModuleFileGenerator.php +++ /dev/null @@ -1,53 +0,0 @@ - $machine_name, - 'file_path' => $file_path , - ]; - - if ($machine_name) { - $this->renderFile( - 'module/module-file.twig', - $file_path . '/' . $machine_name . '.module', - $parameters - ); - } - } -} diff --git a/src/Generator/ModuleGenerator.php b/src/Generator/ModuleGenerator.php deleted file mode 100644 index f7c2ed0a7..000000000 --- a/src/Generator/ModuleGenerator.php +++ /dev/null @@ -1,188 +0,0 @@ - $module, - 'machine_name' => $machineName, - 'type' => 'module', - 'core' => $core, - 'description' => $description, - 'package' => $package, - 'dependencies' => $dependencies, - 'test' => $test, - 'twigtemplate' => $twigtemplate, - ]; - - $this->renderFile( - 'module/info.yml.twig', - $dir.'/'.$machineName.'.info.yml', - $parameters - ); - - if (!empty($featuresBundle)) { - $this->renderFile( - 'module/features.yml.twig', - $dir.'/'.$machineName.'.features.yml', - [ - 'bundle' => $featuresBundle, - ] - ); - } - - if ($moduleFile) { - // Generate '.module' file. - $this->createModuleFile($dir, $parameters); - } - - if ($composer) { - $this->renderFile( - 'module/composer.json.twig', - $dir.'/'.'composer.json', - $parameters - ); - } - - if ($test) { - $this->renderFile( - 'module/src/Tests/load-test.php.twig', - $dir . '/tests/src/Functional/' . 'LoadTest.php', - $parameters - ); - } - if ($twigtemplate) { - // If module file is not created earlier, create now. - if (!$moduleFile) { - // Generate '.module' file. - $this->createModuleFile($dir, $parameters); - } - $this->renderFile( - 'module/module-twig-template-append.twig', - $dir .'/' . $machineName . '.module', - $parameters, - FILE_APPEND - ); - $dir .= '/templates/'; - if (file_exists($dir)) { - if (!is_dir($dir)) { - throw new \RuntimeException( - sprintf( - 'Unable to generate the templates directory as the target directory "%s" exists but is a file.', - realpath($dir) - ) - ); - } - $files = scandir($dir); - if ($files != ['.', '..']) { - throw new \RuntimeException( - sprintf( - 'Unable to generate the templates directory as the target directory "%s" is not empty.', - realpath($dir) - ) - ); - } - if (!is_writable($dir)) { - throw new \RuntimeException( - sprintf( - 'Unable to generate the templates directory as the target directory "%s" is not writable.', - realpath($dir) - ) - ); - } - } - $this->renderFile( - 'module/twig-template-file.twig', - $dir . str_replace("_", "-", $machineName) . '.html.twig', - $parameters - ); - } - } - - /** - * Generate the '.module' file. - * - * @param string $dir - * The directory name. - * @param array $parameters - * The parameter array. - */ - protected function createModuleFile($dir, $parameters) - { - $this->renderFile( - 'module/module.twig', - $dir . '/' . $parameters['machine_name'] . '.module', - $parameters - ); - } -} diff --git a/src/Generator/PermissionGenerator.php b/src/Generator/PermissionGenerator.php deleted file mode 100644 index 643b1f4ba..000000000 --- a/src/Generator/PermissionGenerator.php +++ /dev/null @@ -1,60 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * @param $module - * @param $permissions - * @param $learning - */ - public function generate($module, $permissions, $learning) - { - $parameters = [ - 'module_name' => $module, - 'permissions' => $permissions, - ]; - - $this->renderFile( - 'module/permission.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.permissions.yml', - $parameters, - FILE_APPEND - ); - - $content = $this->renderer->render( - 'module/permission-routing.yml.twig', - $parameters - ); - - if ($learning) { - echo 'You can use this permission in the routing file like this:'.PHP_EOL; - echo $content; - } - } -} diff --git a/src/Generator/PluginBlockGenerator.php b/src/Generator/PluginBlockGenerator.php deleted file mode 100644 index 3755ae193..000000000 --- a/src/Generator/PluginBlockGenerator.php +++ /dev/null @@ -1,89 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Block. - * - * @param $module - * @param $class_name - * @param $label - * @param $plugin_id - * @param $services - */ - public function generate($module, $class_name, $label, $plugin_id, $services, $inputs) - { - // Consider the type when determining a default value. Figure out what - // the code looks like for the default value tht we need to generate. - foreach ($inputs as &$input) { - $default_code = '$this->t(\'\')'; - if ($input['default_value'] == '') { - switch ($input['type']) { - case 'checkbox': - case 'number': - case 'weight': - case 'radio': - $default_code = 0; - break; - - case 'radios': - case 'checkboxes': - $default_code = 'array()'; - break; - } - } elseif (substr($input['default_value'], 0, 1) == '$') { - // If they want to put in code, let them, they're programmers. - $default_code = $input['default_value']; - } elseif (is_numeric($input['default_value'])) { - $default_code = $input['default_value']; - } elseif (preg_match('/^(true|false)$/i', $input['default_value'])) { - // Coding Standards - $default_code = strtoupper($input['default_value']); - } else { - $default_code = '$this->t(\'' . $input['default_value'] . '\')'; - } - $input['default_code'] = $default_code; - } - - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'services' => $services, - 'inputs' => $inputs, - ]; - - $this->renderFile( - 'module/src/Plugin/Block/block.php.twig', - $this->extensionManager->getPluginPath($module, 'Block').'/'.$class_name.'.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginCKEditorButtonGenerator.php b/src/Generator/PluginCKEditorButtonGenerator.php deleted file mode 100644 index bcbef106b..000000000 --- a/src/Generator/PluginCKEditorButtonGenerator.php +++ /dev/null @@ -1,57 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin CKEditor Button. - * - * @param string $module Module name - * @param string $class_name Plugin Class name - * @param string $label Plugin label - * @param string $plugin_id Plugin id - * @param string $button_name Button name - */ - public function generate($module, $class_name, $label, $plugin_id, $button_name, $button_icon_path) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'button_name' => $button_name, - 'button_icon_path' => $button_icon_path, - ]; - - $this->renderFile( - 'module/src/Plugin/CKEditorPlugin/ckeditorbutton.php.twig', - $this->extensionManager->getPluginPath($module, 'CKEditorPlugin') . '/' . $class_name . '.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginConditionGenerator.php b/src/Generator/PluginConditionGenerator.php deleted file mode 100644 index 3b6fa9ad8..000000000 --- a/src/Generator/PluginConditionGenerator.php +++ /dev/null @@ -1,66 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Field Formatter. - * - * @param string $module Module name - * @param string $class_name Plugin condition Class name - * @param string $label Plugin condition label - * @param string $plugin_id Plugin condition id - * @param string $context_definition_id Plugin condition context definition id - * @param string $context_definition_label Plugin condition context definition label - * @param bool $context_definition_required Plugin condition context definition required - */ - public function generate($module, $class_name, $label, $plugin_id, $context_definition_id, $context_definition_label, $context_definition_required) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'context_definition_id' => $context_definition_id, - 'context_definition_label' => $context_definition_label, - 'context_definition_required' => $context_definition_required, - 'context_id' => str_replace('entity:', '', $context_definition_id) - ]; - - $this->renderFile( - 'module/src/Plugin/Condition/condition.php.twig', - $this->extensionManager->getPluginPath($module, 'Condition') . '/' . $class_name . '.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginFieldFormatterGenerator.php b/src/Generator/PluginFieldFormatterGenerator.php deleted file mode 100644 index b97fee7e3..000000000 --- a/src/Generator/PluginFieldFormatterGenerator.php +++ /dev/null @@ -1,51 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Field Formatter. - * - * @param string $module Module name - * @param string $class_name Plugin Class name - * @param string $label Plugin label - * @param string $plugin_id Plugin id - * @param string $field_type Field type this formatter supports - */ - public function generate($module, $class_name, $label, $plugin_id, $field_type) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'field_type' => $field_type, - ]; - - $this->renderFile( - 'module/src/Plugin/Field/FieldFormatter/fieldformatter.php.twig', - $this->extensionManager->getPluginPath($module, 'Field/FieldFormatter') . '/' . $class_name . '.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginFieldTypeGenerator.php b/src/Generator/PluginFieldTypeGenerator.php deleted file mode 100644 index 75f832a9d..000000000 --- a/src/Generator/PluginFieldTypeGenerator.php +++ /dev/null @@ -1,55 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Field Type. - * - * @param string $module Module name - * @param string $class_name Plugin Class name - * @param string $label Plugin label - * @param string $plugin_id Plugin id - * @param string $description Plugin description - * @param string $default_widget Default widget this field type used supports - * @param string $default_formatter Default formatter this field type used supports - */ - public function generate($module, $class_name, $label, $plugin_id, $description, $default_widget, $default_formatter) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'description' => $description, - 'default_widget' => $default_widget, - 'default_formatter' => $default_formatter, - ]; - - $this->renderFile( - 'module/src/Plugin/Field/FieldType/fieldtype.php.twig', - $this->extensionManager->getPluginPath($module, 'Field/FieldType') . '/' . $class_name . '.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginFieldWidgetGenerator.php b/src/Generator/PluginFieldWidgetGenerator.php deleted file mode 100644 index 3e252e296..000000000 --- a/src/Generator/PluginFieldWidgetGenerator.php +++ /dev/null @@ -1,51 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Field Formatter. - * - * @param string $module Module name - * @param string $class_name Plugin Class name - * @param string $label Plugin label - * @param string $plugin_id Plugin id - * @param string $field_type Field type this widget supports - */ - public function generate($module, $class_name, $label, $plugin_id, $field_type) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'field_type' => $field_type, - ]; - - $this->renderFile( - 'module/src/Plugin/Field/FieldWidget/fieldwidget.php.twig', - $this->extensionManager->getPluginPath($module, 'Field/FieldWidget') . '/' . $class_name . '.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginImageEffectGenerator.php b/src/Generator/PluginImageEffectGenerator.php deleted file mode 100644 index fa56ef27b..000000000 --- a/src/Generator/PluginImageEffectGenerator.php +++ /dev/null @@ -1,51 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Image Effect. - * - * @param string $module Module name - * @param string $class_name Plugin Class name - * @param string $plugin_label Plugin label - * @param string $plugin_id Plugin id - * @param string $description Plugin description - */ - public function generate($module, $class_name, $label, $plugin_id, $description) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'description' => $description, - ]; - - $this->renderFile( - 'module/src/Plugin/ImageEffect/imageeffect.php.twig', - $this->extensionManager->getPluginPath($module, 'ImageEffect') .'/'.$class_name.'.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginImageFormatterGenerator.php b/src/Generator/PluginImageFormatterGenerator.php deleted file mode 100644 index e71e739eb..000000000 --- a/src/Generator/PluginImageFormatterGenerator.php +++ /dev/null @@ -1,50 +0,0 @@ -extensionManager = $extensionManager; - } - - - /** - * Generator Plugin Image Formatter. - * - * @param string $module Module name - * @param string $class_name Plugin Class name - * @param string $label Plugin label - * @param string $plugin_id Plugin id - */ - public function generate($module, $class_name, $label, $plugin_id) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - ]; - - $this->renderFile( - 'module/src/Plugin/Field/FieldFormatter/imageformatter.php.twig', - $this->extensionManager->getPluginPath($module, 'Field/FieldFormatter') . '/' . $class_name . '.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginMailGenerator.php b/src/Generator/PluginMailGenerator.php deleted file mode 100644 index 0c053b5d8..000000000 --- a/src/Generator/PluginMailGenerator.php +++ /dev/null @@ -1,51 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Block. - * - * @param $module - * @param $class_name - * @param $label - * @param $plugin_id - * @param $services - */ - public function generate($module, $class_name, $label, $plugin_id, $services) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'services' => $services, - ]; - - $this->renderFile( - 'module/src/Plugin/Mail/mail.php.twig', - $this->extensionManager->getPluginPath($module, 'Mail') .'/'.$class_name.'.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginMigrateProcessGenerator.php b/src/Generator/PluginMigrateProcessGenerator.php deleted file mode 100644 index 227a5eda8..000000000 --- a/src/Generator/PluginMigrateProcessGenerator.php +++ /dev/null @@ -1,52 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generate Migrate Source plugin code. - * - * @param $module - * @param $class_name - * @param $plugin_id - */ - public function generate($module, $class_name, $plugin_id) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'plugin_id' => $plugin_id, - ]; - - $this->renderFile( - 'module/src/Plugin/migrate/process/process.php.twig', - $this->extensionManager->getPluginPath($module, 'migrate').'/process/'.$class_name.'.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginMigrateSourceGenerator.php b/src/Generator/PluginMigrateSourceGenerator.php deleted file mode 100644 index 123fab82c..000000000 --- a/src/Generator/PluginMigrateSourceGenerator.php +++ /dev/null @@ -1,60 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generate Migrate Source plugin code. - * - * @param $module - * @param $class_name - * @param $plugin_id - * @param $table - * @param $alias - * @param $group_by - * @param fields - */ - public function generate($module, $class_name, $plugin_id, $table, $alias, $group_by, $fields) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'plugin_id' => $plugin_id, - 'table' => $table, - 'alias' => $alias, - 'group_by' => $group_by, - 'fields' => $fields, - ]; - - $this->renderFile( - 'module/src/Plugin/migrate/source/source.php.twig', - $this->extensionManager->getPluginPath($module, 'migrate').'/source/'.$class_name.'.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginRestResourceGenerator.php b/src/Generator/PluginRestResourceGenerator.php deleted file mode 100644 index 05518ce81..000000000 --- a/src/Generator/PluginRestResourceGenerator.php +++ /dev/null @@ -1,59 +0,0 @@ -extensionManager = $extensionManager; - } - - - /** - * Generator Plugin Block. - * - * @param $module - * @param $class_name - * @param $plugin_label - * @param $plugin_id - * @param $plugin_url - * @param $plugin_states - */ - public function generate($module, $class_name, $plugin_label, $plugin_id, $plugin_url, $plugin_states) - { - $parameters = [ - 'module_name' => $module, - 'class_name' => $class_name, - 'plugin_label' => $plugin_label, - 'plugin_id' => $plugin_id, - 'plugin_url' => $plugin_url, - 'plugin_states' => $plugin_states, - ]; - - $this->renderFile( - 'module/src/Plugin/Rest/Resource/rest.php.twig', - $this->extensionManager->getPluginPath($module, 'rest') .'/resource/'.$class_name.'.php', - $parameters - ); - } -} diff --git a/src/Generator/PluginRulesActionGenerator.php b/src/Generator/PluginRulesActionGenerator.php deleted file mode 100644 index a60ee380c..000000000 --- a/src/Generator/PluginRulesActionGenerator.php +++ /dev/null @@ -1,65 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin RulesAction. - * - * @param $module - * @param $class_name - * @param $label - * @param $plugin_id - * @param $category - * @param $context - */ - public function generate($module, $class_name, $label, $plugin_id, $category, $context, $type) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'label' => $label, - 'plugin_id' => $plugin_id, - 'category' => $category, - 'context' => $context, - 'type' => $type, - ]; - - $this->renderFile( - 'module/src/Plugin/Action/rulesaction.php.twig', - $this->extensionManager->getPluginPath($module, 'Action').'/'.$class_name.'.php', - $parameters - ); - - $this->renderFile( - 'module/system.action.action.yml.twig', - $this->extensionManager->getModule($module)->getPath() .'/config/install/system.action.'.$plugin_id.'.yml', - $parameters - ); - } -} diff --git a/src/Generator/PluginSkeletonGenerator.php b/src/Generator/PluginSkeletonGenerator.php deleted file mode 100644 index 1e80864f4..000000000 --- a/src/Generator/PluginSkeletonGenerator.php +++ /dev/null @@ -1,61 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Post Update Name function. - * - * @param $module - * @param $pluginId - * @param $plugin - * @param $className - * @param $pluginMetaData - * @param $services - */ - public function generate($module, $pluginId, $plugin, $className, $pluginMetaData, $services) - { - $module_path = $this->extensionManager->getModule($module)->getPath(); - - $parameters = [ - 'module' => $module, - 'plugin_id' => $pluginId, - 'plugin' => $plugin, - 'class_name' => $className, - 'services' => $services, - 'plugin_annotation' => array_pop(explode('\\', $pluginMetaData['pluginAnnotation'])), - 'plugin_interface' => array_pop(explode('\\', $pluginMetaData['pluginInterface'])) - ]; - - $this->renderFile( - 'module/src/Plugin/skeleton.php.twig', - $module_path .'/src/'. $pluginMetaData['subdir'] . '/' . $className .'.php', - array_merge($parameters, $pluginMetaData) - ); - } -} diff --git a/src/Generator/PluginTypeAnnotationGenerator.php b/src/Generator/PluginTypeAnnotationGenerator.php deleted file mode 100644 index 2a5181f17..000000000 --- a/src/Generator/PluginTypeAnnotationGenerator.php +++ /dev/null @@ -1,85 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator for Plugin type with annotation discovery. - * - * @param $module - * @param $class_name - * @param $machine_name - * @param $label - */ - public function generate($module, $class_name, $machine_name, $label) - { - $parameters = [ - 'module' => $module, - 'class_name' => $class_name, - 'machine_name' => $machine_name, - 'label' => $label, - 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), - ]; - - $directory = $this->extensionManager->getModule($module)->getSourcePath() . '/Plugin/' . $class_name; - - if (!is_dir($directory)) { - mkdir($directory, 0777, true); - } - - $this->renderFile( - 'module/src/Annotation/plugin-type.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() . '/Annotation/' . $class_name . '.php', - $parameters - ); - - $this->renderFile( - 'module/src/plugin-type-annotation-base.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() .'/Plugin/' . $class_name . 'Base.php', - $parameters - ); - - $this->renderFile( - 'module/src/plugin-type-annotation-interface.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() .'/Plugin/' . $class_name . 'Interface.php', - $parameters - ); - - $this->renderFile( - 'module/src/plugin-type-annotation-manager.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() .'/Plugin/' . $class_name . 'Manager.php', - $parameters - ); - $this->renderFile( - 'module/plugin-annotation-services.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/PluginTypeYamlGenerator.php b/src/Generator/PluginTypeYamlGenerator.php deleted file mode 100644 index 8dd2807fb..000000000 --- a/src/Generator/PluginTypeYamlGenerator.php +++ /dev/null @@ -1,74 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator for Plugin type with Yaml discovery. - * - * @param $module - * @param $plugin_class - * @param $plugin_name - * @param $plugin_file_name - */ - public function generate($module, $plugin_class, $plugin_name, $plugin_file_name) - { - $parameters = [ - 'module' => $module, - 'plugin_class' => $plugin_class, - 'plugin_name' => $plugin_name, - 'plugin_file_name' => $plugin_file_name, - 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml'), - ]; - - $this->renderFile( - 'module/src/yaml-plugin-manager.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() . '/' . $plugin_class . 'Manager.php', - $parameters - ); - - $this->renderFile( - 'module/src/yaml-plugin-manager-interface.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() . '/' . $plugin_class . 'ManagerInterface.php', - $parameters - ); - - $this->renderFile( - 'module/plugin-yaml-services.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/plugin.yml.twig', - $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.' . $plugin_file_name . '.yml', - $parameters - ); - } -} diff --git a/src/Generator/PluginViewsFieldGenerator.php b/src/Generator/PluginViewsFieldGenerator.php deleted file mode 100644 index 3d0d03681..000000000 --- a/src/Generator/PluginViewsFieldGenerator.php +++ /dev/null @@ -1,62 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Plugin Field Formatter. - * - * @param string $module Module name - * @param string $class_name Plugin Class name - * @param string $label Plugin label - * @param string $plugin_id Plugin id - * @param string $field_type Field type this formatter supports - */ - public function generate($module, $class_machine_name, $class_name, $title, $description) - { - $parameters = [ - 'module' => $module, - 'class_machine_name' => $class_machine_name, - 'class_name' => $class_name, - 'title' => $title, - 'description' => $description, - ]; - - $this->renderFile( - 'module/module.views.inc.twig', - $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.views.inc', - $parameters - ); - - $this->renderFile( - 'module/src/Plugin/Views/field/field.php.twig', - $this->extensionManager->getPluginPath($module, 'views/field') . '/' . $class_name . '.php', - $parameters - ); - } -} diff --git a/src/Generator/PostUpdateGenerator.php b/src/Generator/PostUpdateGenerator.php deleted file mode 100644 index c3c10db7b..000000000 --- a/src/Generator/PostUpdateGenerator.php +++ /dev/null @@ -1,54 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Post Update Name function. - * - * @param $module - * @param $post_update_name - */ - public function generate($module, $post_update_name) - { - $module_path = $this->extensionManager->getModule($module)->getPath(); - - $parameters = [ - 'module' => $module, - 'post_update_name' => $post_update_name, - 'file_exists' => file_exists($module_path .'/'.$module.'.post_update.php'), - ]; - - $this->renderFile( - 'module/post-update.php.twig', - $module_path .'/'.$module.'.post_update.php', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/ProfileGenerator.php b/src/Generator/ProfileGenerator.php deleted file mode 100644 index 8d0857c1a..000000000 --- a/src/Generator/ProfileGenerator.php +++ /dev/null @@ -1,83 +0,0 @@ - $profile, - 'machine_name' => $machine_name, - 'type' => 'profile', - 'core' => $core, - 'description' => $description, - 'dependencies' => $dependencies, - 'themes' => $themes, - 'distribution' => $distribution, - ]; - - $this->renderFile( - 'profile/info.yml.twig', - $dir . '/' . $machine_name . '.info.yml', - $parameters - ); - - $this->renderFile( - 'profile/profile.twig', - $dir . '/' . $machine_name . '.profile', - $parameters - ); - - $this->renderFile( - 'profile/install.twig', - $dir . '/' . $machine_name . '.install', - $parameters - ); - } -} diff --git a/src/Generator/RouteSubscriberGenerator.php b/src/Generator/RouteSubscriberGenerator.php deleted file mode 100644 index 388991f37..000000000 --- a/src/Generator/RouteSubscriberGenerator.php +++ /dev/null @@ -1,62 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Service. - * - * @param string $module Module name - * @param string $name Service name - * @param string $class Class name - */ - public function generate($module, $name, $class) - { - $parameters = [ - 'module' => $module, - 'name' => $name, - 'class' => $class, - 'class_path' => sprintf('Drupal\%s\Routing\%s', $module, $class), - 'tags' => ['name' => 'event_subscriber'], - 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), - ]; - - $this->renderFile( - 'module/src/Routing/route-subscriber.php.twig', - $this->extensionManager->getModule($module)->getRoutingPath().'/'.$class.'.php', - $parameters - ); - - $this->renderFile( - 'module/services.yml.twig', - $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', - $parameters, - FILE_APPEND - ); - } -} diff --git a/src/Generator/ServiceGenerator.php b/src/Generator/ServiceGenerator.php deleted file mode 100644 index 855839f80..000000000 --- a/src/Generator/ServiceGenerator.php +++ /dev/null @@ -1,102 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Service. - * - * @param string $module Module name - * @param string $name Service name - * @param string $class Class name - * @param string $interface If TRUE an interface for this service is generated - * @param array $services List of services - * @param string $path_service Path of services - */ - public function generate($module, $name, $class, $interface, $interface_name, $services, $path_service) - { - $interface = $interface ? ($interface_name ?: $class . 'Interface') : false; - $parameters = [ - 'module' => $module, - 'name' => $name, - 'class' => $class, - 'class_path' => sprintf('Drupal\%s\%s', $module, $class), - 'interface' => $interface, - 'services' => $services, - 'path_service' => $path_service, - 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), - ]; - - $this->renderFile( - 'module/services.yml.twig', - $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/src/service.php.twig', - $this->setDirectory($path_service, 'service.php.twig', $module, $class), - $parameters - ); - - if ($interface) { - $this->renderFile( - 'module/src/service-interface.php.twig', - $this->setDirectory($path_service, 'interface.php.twig', $module, $interface), - $parameters - ); - } - } - - protected function setDirectory($target, $template, $module, $class) - { - $default_path = '/modules/custom/' . $module . '/src/'; - $directory = ''; - - switch ($template) { - case 'service.php.twig': - $default_target = $this->extensionManager->getModule($module)->getPath() .'/src/'.$class.'.php'; - $custom_target = $this->extensionManager->getModule($module)->getPath() .'/'.$target.'/'.$class.'.php'; - - $directory = (strcmp($target, $default_path) == 0) ? $default_target : $custom_target; - break; - case 'interface.php.twig': - $default_target = $this->extensionManager->getModule($module)->getPath() .'/src/'.$class.'.php'; - $custom_target = $this->extensionManager->getModule($module)->getPath() .'/'.$target.'/'.$class.'.php'; - - $directory = (strcmp($target, $default_path) == 0) ? $default_target : $custom_target; - break; - default: - // code... - break; - } - - return $directory; - } -} diff --git a/src/Generator/ThemeGenerator.php b/src/Generator/ThemeGenerator.php deleted file mode 100644 index 78342bf98..000000000 --- a/src/Generator/ThemeGenerator.php +++ /dev/null @@ -1,118 +0,0 @@ -extensionManager = $extensionManager; - } - - public function generate( - $theme, - $machine_name, - $dir, - $description, - $core, - $package, - $base_theme, - $global_library, - $libraries, - $regions, - $breakpoints - ) { - $dir .= '/' . $machine_name; - if (file_exists($dir)) { - if (!is_dir($dir)) { - throw new \RuntimeException( - sprintf( - 'Unable to generate the bundle as the target directory "%s" exists but is a file.', - realpath($dir) - ) - ); - } - $files = scandir($dir); - if ($files != ['.', '..']) { - throw new \RuntimeException( - sprintf( - 'Unable to generate the bundle as the target directory "%s" is not empty.', - realpath($dir) - ) - ); - } - if (!is_writable($dir)) { - throw new \RuntimeException( - sprintf( - 'Unable to generate the bundle as the target directory "%s" is not writable.', - realpath($dir) - ) - ); - } - } - - $parameters = [ - 'theme' => $theme, - 'machine_name' => $machine_name, - 'type' => 'theme', - 'core' => $core, - 'description' => $description, - 'package' => $package, - 'base_theme' => $base_theme, - 'global_library' => $global_library, - 'libraries' => $libraries, - 'regions' => $regions, - 'breakpoints' => $breakpoints, - ]; - - $this->renderFile( - 'theme/info.yml.twig', - $dir . '/' . $machine_name . '.info.yml', - $parameters - ); - - $this->renderFile( - 'theme/theme.twig', - $dir . '/' . $machine_name . '.theme', - $parameters - ); - - if ($libraries) { - $this->renderFile( - 'theme/libraries.yml.twig', - $dir . '/' . $machine_name . '.libraries.yml', - $parameters - ); - } - - if ($breakpoints) { - $this->renderFile( - 'theme/breakpoints.yml.twig', - $dir . '/' . $machine_name . '.breakpoints.yml', - $parameters - ); - } - } -} diff --git a/src/Generator/TwigExtensionGenerator.php b/src/Generator/TwigExtensionGenerator.php deleted file mode 100644 index 91c522023..000000000 --- a/src/Generator/TwigExtensionGenerator.php +++ /dev/null @@ -1,69 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Service. - * - * @param string $module Module name - * @param string $name Service name - * @param string $class Class name - * @param array $services List of services - */ - public function generate($module, $name, $class, $services) - { - $parameters = [ - 'module' => $module, - 'name' => $name, - 'class' => $class, - 'class_path' => sprintf('Drupal\%s\TwigExtension\%s', $module, $class), - 'services' => $services, - 'tags' => ['name' => 'twig.extension'], - 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), - ]; - - $this->renderFile( - 'module/services.yml.twig', - $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', - $parameters, - FILE_APPEND - ); - - $this->renderFile( - 'module/src/TwigExtension/twig-extension.php.twig', - $this->extensionManager->getModule($module)->getPath() .'/src/TwigExtension/'.$class.'.php', - $parameters - ); - } -} diff --git a/src/Generator/UpdateGenerator.php b/src/Generator/UpdateGenerator.php deleted file mode 100644 index 55180668d..000000000 --- a/src/Generator/UpdateGenerator.php +++ /dev/null @@ -1,55 +0,0 @@ -extensionManager = $extensionManager; - } - - /** - * Generator Update N function. - * - * @param $module - * @param $update_number - */ - public function generate($module, $update_number) - { - $modulePath = $this->extensionManager->getModule($module)->getPath(); - $updateFile = $modulePath .'/'.$module.'.install'; - - $parameters = [ - 'module' => $module, - 'update_number' => $update_number, - 'file_exists' => file_exists($updateFile) - ]; - - $this->renderFile( - 'module/update.php.twig', - $updateFile, - $parameters, - FILE_APPEND - ); - } -} From 7c7ca2e90055c6d5fa9d9e5e1331762735a56e12 Mon Sep 17 00:00:00 2001 From: enzo - Eduardo Garcia Date: Thu, 13 Jul 2017 18:44:46 +1000 Subject: [PATCH 2/2] Revert "Removed generate commands and generators (#3417)" This reverts commit 1dea474267555f569ca7f1d8d61396918be99bfb. --- config/services/database.yml | 6 - config/services/generate.yml | 247 +++++++++++ config/services/generator.yml | 244 +++++++++++ .../AuthenticationProviderCommand.php | 158 +++++++ src/Command/Generate/BreakPointCommand.php | 172 ++++++++ src/Command/Generate/CacheContextCommand.php | 174 ++++++++ src/Command/Generate/CommandCommand.php | 224 ++++++++++ .../Generate/ConfigFormBaseCommand.php | 91 ++++ src/Command/Generate/ControllerCommand.php | 320 ++++++++++++++ src/Command/Generate/EntityBundleCommand.php | 151 +++++++ src/Command/Generate/EntityCommand.php | 176 ++++++++ src/Command/Generate/EntityConfigCommand.php | 101 +++++ src/Command/Generate/EntityContentCommand.php | 174 ++++++++ .../Generate/EventSubscriberCommand.php | 197 +++++++++ src/Command/Generate/FormAlterCommand.php | 324 ++++++++++++++ src/Command/Generate/FormBaseCommand.php | 18 + src/Command/Generate/FormCommand.php | 330 ++++++++++++++ src/Command/Generate/HelpCommand.php | 148 +++++++ src/Command/Generate/ModuleCommand.php | 409 ++++++++++++++++++ src/Command/Generate/ModuleFileCommand.php | 115 +++++ src/Command/Generate/PermissionCommand.php | 122 ++++++ src/Command/Generate/PluginBlockCommand.php | 292 +++++++++++++ .../Generate/PluginCKEditorButtonCommand.php | 207 +++++++++ .../Generate/PluginConditionCommand.php | 253 +++++++++++ src/Command/Generate/PluginFieldCommand.php | 346 +++++++++++++++ .../Generate/PluginFieldFormatterCommand.php | 205 +++++++++ .../Generate/PluginFieldTypeCommand.php | 221 ++++++++++ .../Generate/PluginFieldWidgetCommand.php | 210 +++++++++ .../Generate/PluginImageEffectCommand.php | 185 ++++++++ .../Generate/PluginImageFormatterCommand.php | 172 ++++++++ src/Command/Generate/PluginMailCommand.php | 198 +++++++++ .../Generate/PluginMigrateProcessCommand.php | 147 +++++++ .../Generate/PluginMigrateSourceCommand.php | 267 ++++++++++++ .../Generate/PluginRestResourceCommand.php | 225 ++++++++++ .../Generate/PluginRulesActionCommand.php | 220 ++++++++++ .../Generate/PluginSkeletonCommand.php | 384 ++++++++++++++++ .../Generate/PluginTypeAnnotationCommand.php | 153 +++++++ .../Generate/PluginTypeYamlCommand.php | 154 +++++++ .../Generate/PluginViewsFieldCommand.php | 185 ++++++++ src/Command/Generate/PostUpdateCommand.php | 198 +++++++++ src/Command/Generate/ProfileCommand.php | 270 ++++++++++++ .../Generate/RouteSubscriberCommand.php | 158 +++++++ src/Command/Generate/ServiceCommand.php | 244 +++++++++++ src/Command/Generate/ThemeCommand.php | 383 ++++++++++++++++ src/Command/Generate/TwigExtensionCommand.php | 192 ++++++++ src/Command/Generate/UpdateCommand.php | 199 +++++++++ .../AuthenticationProviderGenerator.php | 75 ++++ src/Generator/BreakPointGenerator.php | 61 +++ src/Generator/CacheContextGenerator.php | 64 +++ src/Generator/CommandGenerator.php | 94 ++++ src/Generator/ControllerGenerator.php | 62 +++ src/Generator/EntityBundleGenerator.php | 86 ++++ src/Generator/EntityConfigGenerator.php | 109 +++++ src/Generator/EntityContentGenerator.php | 291 +++++++++++++ src/Generator/EventSubscriberGenerator.php | 66 +++ src/Generator/FormAlterGenerator.php | 57 +++ src/Generator/FormGenerator.php | 114 +++++ src/Generator/HelpGenerator.php | 54 +++ src/Generator/ModuleFileGenerator.php | 53 +++ src/Generator/ModuleGenerator.php | 188 ++++++++ src/Generator/PermissionGenerator.php | 60 +++ src/Generator/PluginBlockGenerator.php | 89 ++++ .../PluginCKEditorButtonGenerator.php | 57 +++ src/Generator/PluginConditionGenerator.php | 66 +++ .../PluginFieldFormatterGenerator.php | 51 +++ src/Generator/PluginFieldTypeGenerator.php | 55 +++ src/Generator/PluginFieldWidgetGenerator.php | 51 +++ src/Generator/PluginImageEffectGenerator.php | 51 +++ .../PluginImageFormatterGenerator.php | 50 +++ src/Generator/PluginMailGenerator.php | 51 +++ .../PluginMigrateProcessGenerator.php | 52 +++ .../PluginMigrateSourceGenerator.php | 60 +++ src/Generator/PluginRestResourceGenerator.php | 59 +++ src/Generator/PluginRulesActionGenerator.php | 65 +++ src/Generator/PluginSkeletonGenerator.php | 61 +++ .../PluginTypeAnnotationGenerator.php | 85 ++++ src/Generator/PluginTypeYamlGenerator.php | 74 ++++ src/Generator/PluginViewsFieldGenerator.php | 62 +++ src/Generator/PostUpdateGenerator.php | 54 +++ src/Generator/ProfileGenerator.php | 83 ++++ src/Generator/RouteSubscriberGenerator.php | 62 +++ src/Generator/ServiceGenerator.php | 102 +++++ src/Generator/ThemeGenerator.php | 118 +++++ src/Generator/TwigExtensionGenerator.php | 69 +++ src/Generator/UpdateGenerator.php | 55 +++ 85 files changed, 12579 insertions(+), 6 deletions(-) create mode 100644 config/services/generate.yml create mode 100644 config/services/generator.yml create mode 100644 src/Command/Generate/AuthenticationProviderCommand.php create mode 100644 src/Command/Generate/BreakPointCommand.php create mode 100644 src/Command/Generate/CacheContextCommand.php create mode 100644 src/Command/Generate/CommandCommand.php create mode 100644 src/Command/Generate/ConfigFormBaseCommand.php create mode 100644 src/Command/Generate/ControllerCommand.php create mode 100644 src/Command/Generate/EntityBundleCommand.php create mode 100644 src/Command/Generate/EntityCommand.php create mode 100644 src/Command/Generate/EntityConfigCommand.php create mode 100644 src/Command/Generate/EntityContentCommand.php create mode 100644 src/Command/Generate/EventSubscriberCommand.php create mode 100644 src/Command/Generate/FormAlterCommand.php create mode 100644 src/Command/Generate/FormBaseCommand.php create mode 100644 src/Command/Generate/FormCommand.php create mode 100644 src/Command/Generate/HelpCommand.php create mode 100644 src/Command/Generate/ModuleCommand.php create mode 100644 src/Command/Generate/ModuleFileCommand.php create mode 100644 src/Command/Generate/PermissionCommand.php create mode 100644 src/Command/Generate/PluginBlockCommand.php create mode 100644 src/Command/Generate/PluginCKEditorButtonCommand.php create mode 100644 src/Command/Generate/PluginConditionCommand.php create mode 100644 src/Command/Generate/PluginFieldCommand.php create mode 100644 src/Command/Generate/PluginFieldFormatterCommand.php create mode 100644 src/Command/Generate/PluginFieldTypeCommand.php create mode 100644 src/Command/Generate/PluginFieldWidgetCommand.php create mode 100644 src/Command/Generate/PluginImageEffectCommand.php create mode 100644 src/Command/Generate/PluginImageFormatterCommand.php create mode 100644 src/Command/Generate/PluginMailCommand.php create mode 100644 src/Command/Generate/PluginMigrateProcessCommand.php create mode 100644 src/Command/Generate/PluginMigrateSourceCommand.php create mode 100644 src/Command/Generate/PluginRestResourceCommand.php create mode 100644 src/Command/Generate/PluginRulesActionCommand.php create mode 100644 src/Command/Generate/PluginSkeletonCommand.php create mode 100644 src/Command/Generate/PluginTypeAnnotationCommand.php create mode 100644 src/Command/Generate/PluginTypeYamlCommand.php create mode 100644 src/Command/Generate/PluginViewsFieldCommand.php create mode 100644 src/Command/Generate/PostUpdateCommand.php create mode 100644 src/Command/Generate/ProfileCommand.php create mode 100644 src/Command/Generate/RouteSubscriberCommand.php create mode 100644 src/Command/Generate/ServiceCommand.php create mode 100644 src/Command/Generate/ThemeCommand.php create mode 100644 src/Command/Generate/TwigExtensionCommand.php create mode 100644 src/Command/Generate/UpdateCommand.php create mode 100644 src/Generator/AuthenticationProviderGenerator.php create mode 100644 src/Generator/BreakPointGenerator.php create mode 100644 src/Generator/CacheContextGenerator.php create mode 100644 src/Generator/CommandGenerator.php create mode 100644 src/Generator/ControllerGenerator.php create mode 100644 src/Generator/EntityBundleGenerator.php create mode 100644 src/Generator/EntityConfigGenerator.php create mode 100644 src/Generator/EntityContentGenerator.php create mode 100644 src/Generator/EventSubscriberGenerator.php create mode 100644 src/Generator/FormAlterGenerator.php create mode 100644 src/Generator/FormGenerator.php create mode 100644 src/Generator/HelpGenerator.php create mode 100644 src/Generator/ModuleFileGenerator.php create mode 100644 src/Generator/ModuleGenerator.php create mode 100644 src/Generator/PermissionGenerator.php create mode 100644 src/Generator/PluginBlockGenerator.php create mode 100644 src/Generator/PluginCKEditorButtonGenerator.php create mode 100644 src/Generator/PluginConditionGenerator.php create mode 100644 src/Generator/PluginFieldFormatterGenerator.php create mode 100644 src/Generator/PluginFieldTypeGenerator.php create mode 100644 src/Generator/PluginFieldWidgetGenerator.php create mode 100644 src/Generator/PluginImageEffectGenerator.php create mode 100644 src/Generator/PluginImageFormatterGenerator.php create mode 100644 src/Generator/PluginMailGenerator.php create mode 100644 src/Generator/PluginMigrateProcessGenerator.php create mode 100644 src/Generator/PluginMigrateSourceGenerator.php create mode 100644 src/Generator/PluginRestResourceGenerator.php create mode 100644 src/Generator/PluginRulesActionGenerator.php create mode 100644 src/Generator/PluginSkeletonGenerator.php create mode 100644 src/Generator/PluginTypeAnnotationGenerator.php create mode 100644 src/Generator/PluginTypeYamlGenerator.php create mode 100644 src/Generator/PluginViewsFieldGenerator.php create mode 100644 src/Generator/PostUpdateGenerator.php create mode 100644 src/Generator/ProfileGenerator.php create mode 100644 src/Generator/RouteSubscriberGenerator.php create mode 100644 src/Generator/ServiceGenerator.php create mode 100644 src/Generator/ThemeGenerator.php create mode 100644 src/Generator/TwigExtensionGenerator.php create mode 100644 src/Generator/UpdateGenerator.php diff --git a/config/services/database.yml b/config/services/database.yml index 2a4f2eb74..573eda99c 100644 --- a/config/services/database.yml +++ b/config/services/database.yml @@ -1,10 +1,4 @@ services: - console.database_settings_generator: - class: Drupal\Console\Generator\DatabaseSettingsGenerator - arguments: ['@kernel'] - tags: - - { name: drupal.generator } - lazy: true console.database_add: class: Drupal\Console\Command\Database\AddCommand arguments: ['@console.database_settings_generator'] diff --git a/config/services/generate.yml b/config/services/generate.yml new file mode 100644 index 000000000..35b47fa17 --- /dev/null +++ b/config/services/generate.yml @@ -0,0 +1,247 @@ +services: + console.generate_module: + class: Drupal\Console\Command\Generate\ModuleCommand + arguments: ['@console.module_generator', '@console.validator', '@app.root', '@console.string_converter', '@console.drupal_api'] + tags: + - { name: drupal.command } + lazy: true + console.generate_modulefile: + class: Drupal\Console\Command\Generate\ModuleFileCommand + arguments: ['@console.extension_manager', '@console.modulefile_generator'] + tags: + - { name: drupal.command } + lazy: true + console.generate_authentication_provider: + class: Drupal\Console\Command\Generate\AuthenticationProviderCommand + arguments: ['@console.extension_manager', '@console.authentication_provider_generator', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_controller: + class: Drupal\Console\Command\Generate\ControllerCommand + arguments: ['@console.extension_manager', '@console.controller_generator', '@console.string_converter', '@console.validator', '@router.route_provider', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_breakpoint: + class: Drupal\Console\Command\Generate\BreakPointCommand + arguments: ['@console.breakpoint_generator', '@app.root', '@theme_handler', '@console.validator', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_help: + class: Drupal\Console\Command\Generate\HelpCommand + arguments: ['@console.help_generator', '@console.site', '@console.extension_manager', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_form: + class: Drupal\Console\Command\Generate\FormBaseCommand + arguments: ['@console.extension_manager', '@console.form_generator', '@console.chain_queue', '@console.string_converter', '@plugin.manager.element_info', '@router.route_provider'] + tags: + - { name: drupal.command } + lazy: true + console.generate_form_alter: + class: Drupal\Console\Command\Generate\FormAlterCommand + arguments: ['@console.extension_manager', '@console.form_alter_generator', '@console.string_converter', '@module_handler', '@plugin.manager.element_info', '@?profiler', '@app.root', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_permissions: + class: Drupal\Console\Command\Generate\PermissionCommand + arguments: ['@console.extension_manager', '@console.string_converter', '@console.permission_generator'] + tags: + - { name: drupal.command } + lazy: true + console.generate_event_subscriber: + class: Drupal\Console\Command\Generate\EventSubscriberCommand + arguments: ['@console.extension_manager', '@console.event_subscriber_generator', '@console.string_converter', '@event_dispatcher', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_form_config: + class: Drupal\Console\Command\Generate\ConfigFormBaseCommand + arguments: ['@console.extension_manager', '@console.form_generator', '@console.string_converter', '@router.route_provider', '@plugin.manager.element_info', '@app.root', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_type_annotation: + class: Drupal\Console\Command\Generate\PluginTypeAnnotationCommand + arguments: ['@console.extension_manager', '@console.plugin_type_annotation_generator', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_condition: + class: Drupal\Console\Command\Generate\PluginConditionCommand + arguments: ['@console.extension_manager', '@console.plugin_condition_generator', '@console.chain_queue', '@entity_type.repository', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_field: + class: Drupal\Console\Command\Generate\PluginFieldCommand + arguments: ['@console.extension_manager','@console.string_converter', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_field_formatter: + class: Drupal\Console\Command\Generate\PluginFieldFormatterCommand + arguments: ['@console.extension_manager', '@console.plugin_field_formatter_generator','@console.string_converter', '@plugin.manager.field.field_type', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_field_type: + class: Drupal\Console\Command\Generate\PluginFieldTypeCommand + arguments: ['@console.extension_manager', '@console.plugin_field_type_generator','@console.string_converter', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_field_widget: + class: Drupal\Console\Command\Generate\PluginFieldWidgetCommand + arguments: ['@console.extension_manager', '@console.plugin_field_widget_generator','@console.string_converter', '@plugin.manager.field.field_type', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_image_effect: + class: Drupal\Console\Command\Generate\PluginImageEffectCommand + arguments: ['@console.extension_manager', '@console.plugin_image_effect_generator','@console.string_converter', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_image_formatter: + class: Drupal\Console\Command\Generate\PluginImageFormatterCommand + arguments: ['@console.extension_manager', '@console.plugin_image_formatter_generator','@console.string_converter', '@console.validator', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_mail: + class: Drupal\Console\Command\Generate\PluginMailCommand + arguments: ['@console.extension_manager', '@console.plugin_mail_generator','@console.string_converter', '@console.validator', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_migrate_source: + class: Drupal\Console\Command\Generate\PluginMigrateSourceCommand + arguments: ['@config.factory', '@console.chain_queue', '@console.plugin_migrate_source_generator', '@entity_type.manager', '@console.extension_manager', '@console.validator', '@console.string_converter', '@plugin.manager.element_info'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_migrate_process: + class: Drupal\Console\Command\Generate\PluginMigrateProcessCommand + arguments: [ '@console.plugin_migrate_process_generator', '@console.chain_queue', '@console.extension_manager', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_rest_resource: + class: Drupal\Console\Command\Generate\PluginRestResourceCommand + arguments: ['@console.extension_manager', '@console.plugin_rest_resource_generator','@console.string_converter', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_rules_action: + class: Drupal\Console\Command\Generate\PluginRulesActionCommand + arguments: ['@console.extension_manager', '@console.plugin_rules_action_generator','@console.string_converter', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_skeleton: + class: Drupal\Console\Command\Generate\PluginSkeletonCommand + arguments: ['@console.extension_manager', '@console.plugin_skeleton_generator','@console.string_converter', '@console.validator', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_type_yaml: + class: Drupal\Console\Command\Generate\PluginTypeYamlCommand + arguments: ['@console.extension_manager', '@console.plugin_type_yaml_generator','@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_plugin_views_field: + class: Drupal\Console\Command\Generate\PluginViewsFieldCommand + arguments: ['@console.extension_manager', '@console.plugin_views_field_generator', '@console.site','@console.string_converter','@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_post_update: + class: Drupal\Console\Command\Generate\PostUpdateCommand + arguments: ['@console.extension_manager', '@console.post_update_generator', '@console.site', '@console.validator','@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_profile: + class: Drupal\Console\Command\Generate\ProfileCommand + arguments: ['@console.extension_manager', '@console.profile_generator', '@console.string_converter', '@console.validator', '@app.root'] + tags: + - { name: drupal.command } + lazy: true + console.generate_route_subscriber: + class: Drupal\Console\Command\Generate\RouteSubscriberCommand + arguments: ['@console.extension_manager', '@console.route_subscriber_generator', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_service: + class: Drupal\Console\Command\Generate\ServiceCommand + arguments: ['@console.extension_manager', '@console.service_generator', '@console.string_converter', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_theme: + class: Drupal\Console\Command\Generate\ThemeCommand + arguments: ['@console.extension_manager', '@console.theme_generator', '@console.validator', '@app.root', '@theme_handler', '@console.site', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_twig_extension: + class: Drupal\Console\Command\Generate\TwigExtensionCommand + arguments: ['@console.extension_manager', '@console.twig_extension_generator', '@console.site', '@console.string_converter', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_update: + class: Drupal\Console\Command\Generate\UpdateCommand + arguments: ['@console.extension_manager', '@console.update_generator', '@console.site', '@console.chain_queue'] + tags: + - { name: drupal.command } + lazy: true + console.generate_pluginblock: + class: Drupal\Console\Command\Generate\PluginBlockCommand + arguments: ['@config.factory', '@console.chain_queue', '@console.pluginblock_generator', '@entity_type.manager', '@console.extension_manager', '@console.validator', '@console.string_converter', '@plugin.manager.element_info'] + tags: + - { name: drupal.command } + lazy: true + console.generate_command: + class: Drupal\Console\Command\Generate\CommandCommand + arguments: ['@console.command_generator', '@console.extension_manager', '@console.validator', '@console.string_converter', '@console.site'] + tags: + - { name: drupal.command } + lazy: true + console.generate_ckeditorbutton: + class: Drupal\Console\Command\Generate\PluginCKEditorButtonCommand + arguments: ['@console.chain_queue', '@console.command_ckeditorbutton', '@console.extension_manager', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_entitycontent: + class: Drupal\Console\Command\Generate\EntityContentCommand + arguments: ['@console.chain_queue', '@console.entitycontent_generator', '@console.string_converter', '@console.extension_manager', '@console.validator'] + tags: + - { name: drupal.command } + lazy: true + console.generate_entitybundle: + class: Drupal\Console\Command\Generate\EntityBundleCommand + arguments: ['@console.validator', '@console.entitybundle_generator', '@console.extension_manager'] + tags: + - { name: drupal.command } + lazy: true + console.generate_entityconfig: + class: Drupal\Console\Command\Generate\EntityConfigCommand + arguments: ['@console.extension_manager', '@console.entityconfig_generator', '@console.validator', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true + console.generate_cache_context: + class: Drupal\Console\Command\Generate\CacheContextCommand + arguments: [ '@console.cache_context_generator', '@console.chain_queue', '@console.extension_manager', '@console.string_converter'] + tags: + - { name: drupal.command } + lazy: true diff --git a/config/services/generator.yml b/config/services/generator.yml new file mode 100644 index 000000000..aa2b56c7d --- /dev/null +++ b/config/services/generator.yml @@ -0,0 +1,244 @@ +services: + console.module_generator: + class: Drupal\Console\Generator\ModuleGenerator + tags: + - { name: drupal.generator } + lazy: true + console.modulefile_generator: + class: Drupal\Console\Generator\ModuleFileGenerator + tags: + - { name: drupal.generator } + lazy: true + console.authentication_provider_generator: + class: Drupal\Console\Generator\AuthenticationProviderGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.help_generator: + class: Drupal\Console\Generator\HelpGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.controller_generator: + class: Drupal\Console\Generator\ControllerGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.breakpoint_generator: + class: Drupal\Console\Generator\BreakPointGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.form_alter_generator: + class: Drupal\Console\Generator\FormAlterGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.permission_generator: + class: Drupal\Console\Generator\PermissionGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.event_subscriber_generator: + class: Drupal\Console\Generator\EventSubscriberGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.form_generator: + class: Drupal\Console\Generator\FormGenerator + arguments: ['@console.extension_manager', '@console.string_converter'] + tags: + - { name: drupal.generator } + lazy: true + console.profile_generator: + class: Drupal\Console\Generator\ProfileGenerator + tags: + - { name: drupal.generator } + lazy: true + console.post_update_generator: + class: Drupal\Console\Generator\PostUpdateGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_condition_generator: + class: Drupal\Console\Generator\PluginConditionGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_field_generator: + class: Drupal\Console\Generator\PluginFieldFormatterGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_field_formatter_generator: + class: Drupal\Console\Generator\PluginFieldFormatterGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_field_type_generator: + class: Drupal\Console\Generator\PluginFieldTypeGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_field_widget_generator: + class: Drupal\Console\Generator\PluginFieldWidgetGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_image_effect_generator: + class: Drupal\Console\Generator\PluginImageEffectGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_image_formatter_generator: + class: Drupal\Console\Generator\PluginImageFormatterGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_mail_generator: + class: Drupal\Console\Generator\PluginMailGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_migrate_source_generator: + class: Drupal\Console\Generator\PluginMigrateSourceGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_migrate_process_generator: + class: Drupal\Console\Generator\PluginMigrateProcessGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_rest_resource_generator: + class: Drupal\Console\Generator\PluginRestResourceGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_rules_action_generator: + class: Drupal\Console\Generator\PluginRulesActionGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_skeleton_generator: + class: Drupal\Console\Generator\PluginSkeletonGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_views_field_generator: + class: Drupal\Console\Generator\PluginViewsFieldGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_type_annotation_generator: + class: Drupal\Console\Generator\PluginTypeAnnotationGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.plugin_type_yaml_generator: + class: Drupal\Console\Generator\PluginTypeYamlGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.route_subscriber_generator: + class: Drupal\Console\Generator\RouteSubscriberGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.service_generator: + class: Drupal\Console\Generator\ServiceGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.theme_generator: + class: Drupal\Console\Generator\ThemeGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.twig_extension_generator: + class: Drupal\Console\Generator\TwigExtensionGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.update_generator: + class: Drupal\Console\Generator\UpdateGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.pluginblock_generator: + class: Drupal\Console\Generator\PluginBlockGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.command_generator: + class: Drupal\Console\Generator\CommandGenerator + arguments: ['@console.extension_manager', '@console.translator_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.command_ckeditorbutton: + class: Drupal\Console\Generator\PluginCKEditorButtonGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.database_settings_generator: + class: Drupal\Console\Generator\DatabaseSettingsGenerator + arguments: ['@kernel'] + tags: + - { name: drupal.generator } + lazy: true + console.entitycontent_generator: + class: Drupal\Console\Generator\EntityContentGenerator + arguments: ['@console.extension_manager', '@console.site', '@console.renderer'] + tags: + - { name: drupal.generator } + lazy: true + console.entitybundle_generator: + class: Drupal\Console\Generator\EntityBundleGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.entityconfig_generator: + class: Drupal\Console\Generator\EntityConfigGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true + console.cache_context_generator: + class: Drupal\Console\Generator\CacheContextGenerator + arguments: ['@console.extension_manager'] + tags: + - { name: drupal.generator } + lazy: true diff --git a/src/Command/Generate/AuthenticationProviderCommand.php b/src/Command/Generate/AuthenticationProviderCommand.php new file mode 100644 index 000000000..8e6e2a027 --- /dev/null +++ b/src/Command/Generate/AuthenticationProviderCommand.php @@ -0,0 +1,158 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:authentication:provider') + ->setDescription($this->trans('commands.generate.authentication.provider.description')) + ->setHelp($this->trans('commands.generate.authentication.provider.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.authentication.provider.options.class') + ) + ->addOption( + 'provider-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.authentication.provider.options.provider-id') + ) + ->setAliases(['gap']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class = $input->getOption('class'); + $provider_id = $input->getOption('provider-id'); + + $this->generator->generate($module, $class, $provider_id); + + return 0; + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $stringUtils = $this->stringConverter; + + // --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.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); + } + } +} diff --git a/src/Command/Generate/BreakPointCommand.php b/src/Command/Generate/BreakPointCommand.php new file mode 100644 index 000000000..bb53df8ef --- /dev/null +++ b/src/Command/Generate/BreakPointCommand.php @@ -0,0 +1,172 @@ +generator = $generator; + $this->appRoot = $appRoot; + $this->themeHandler = $themeHandler; + $this->validator = $validator; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:breakpoint') + ->setDescription($this->trans('commands.generate.breakpoint.description')) + ->setHelp($this->trans('commands.generate.breakpoint.help')) + ->addOption( + 'theme', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.breakpoint.options.theme') + ) + ->addOption( + 'breakpoints', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.breakpoint.options.breakpoints') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $validators = $this->validator; + // we must to ensure theme exist + $machine_name = $validators->validateMachineName($input->getOption('theme')); + $theme_path = $drupal_root . $input->getOption('theme'); + $breakpoints = $input->getOption('breakpoints'); + + $this->generator->generate( + $theme_path, + $breakpoints, + $machine_name + ); + + return 0; + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $drupalRoot = $this->appRoot; + + // --base-theme option. + $base_theme = $input->getOption('theme'); + + if (!$base_theme) { + $themeHandler = $this->themeHandler; + $themes = $themeHandler->rebuildThemeData(); + $themes['classy'] =''; + + uasort($themes, 'system_sort_modules_by_info_name'); + + $base_theme = $io->choiceNoList( + $this->trans('commands.generate.breakpoint.questions.theme'), + array_keys($themes) + ); + $input->setOption('theme', $base_theme); + } + + // --breakpoints option. + $breakpoints = $input->getOption('breakpoints'); + if (!$breakpoints) { + $breakpoints = $this->breakpointQuestion($io); + $input->setOption('breakpoints', $breakpoints); + } + } +} diff --git a/src/Command/Generate/CacheContextCommand.php b/src/Command/Generate/CacheContextCommand.php new file mode 100644 index 000000000..5ca9c0137 --- /dev/null +++ b/src/Command/Generate/CacheContextCommand.php @@ -0,0 +1,174 @@ +generator = $generator; + $this->chainQueue = $chainQueue; + $this->extensionManager = $extensionManager; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:cache:context') + ->setDescription($this->trans('commands.generate.cache.context.description')) + ->setHelp($this->trans('commands.generate.cache.context.description')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module')) + ->addOption( + 'cache-context', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.cache.context.questions.name') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.cache.context.questions.class') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $cache_context = $input->getOption('cache-context'); + $class = $input->getOption('class'); + $services = $input->getOption('services'); + + // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices + $buildServices = $this->buildServices($services); + + $this->generator->generate($module, $cache_context, $class, $buildServices); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); + } + + /** + * {@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); + } + + // --cache_context option + $cache_context = $input->getOption('cache-context'); + if (!$cache_context) { + $cache_context = $io->ask( + $this->trans('commands.generate.cache.context.questions.name'), + sprintf('%s', $module) + ); + $input->setOption('cache-context', $cache_context); + } + + // --class option + $class = $input->getOption('class'); + if (!$class) { + $class = $io->ask( + $this->trans('commands.generate.cache.context.questions.class'), + 'DefaultCacheContext' + ); + $input->setOption('class', $class); + } + + // --services option + $services = $input->getOption('services'); + if (!$services) { + // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion + $services = $this->servicesQuestion($io); + $input->setOption('services', $services); + } + } +} diff --git a/src/Command/Generate/CommandCommand.php b/src/Command/Generate/CommandCommand.php new file mode 100644 index 000000000..3b1901329 --- /dev/null +++ b/src/Command/Generate/CommandCommand.php @@ -0,0 +1,224 @@ +generator = $generator; + $this->extensionManager = $extensionManager; + $this->validator = $validator; + $this->stringConverter = $stringConverter; + $this->site = $site; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:command') + ->setDescription($this->trans('commands.generate.command.description')) + ->setHelp($this->trans('commands.generate.command.help')) + ->addOption( + 'extension', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.extension') + ) + ->addOption( + 'extension-type', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.extension-type') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.command.options.class') + ) + ->addOption( + 'name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.command.options.name') + ) + ->addOption( + 'container-aware', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.command.options.container-aware') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ) + ->setAliases(['gcm']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $extension = $input->getOption('extension'); + $extensionType = $input->getOption('extension-type'); + $class = $input->getOption('class'); + $name = $input->getOption('name'); + $containerAware = $input->getOption('container-aware'); + $services = $input->getOption('services'); + $yes = $input->hasOption('yes')?$input->getOption('yes'):false; + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io, $yes)) { + return 1; + } + + // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices + $build_services = $this->buildServices($services); + + $this->generator->generate( + $extension, + $extensionType, + $name, + $class, + $containerAware, + $build_services + ); + + $this->site->removeCachedServicesFile(); + + return 0; + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $extension = $input->getOption('extension'); + if (!$extension) { + $extension = $this->extensionQuestion($io, true, true); + $input->setOption('extension', $extension->getName()); + $input->setOption('extension-type', $extension->getType()); + } + + $extensionType = $input->getOption('extension-type'); + if (!$extensionType) { + $extensionType = $this->extensionTypeQuestion($io); + $input->setOption('extension-type', $extensionType); + } + + $name = $input->getOption('name'); + if (!$name) { + $name = $io->ask( + $this->trans('commands.generate.command.questions.name'), + sprintf('%s:default', $extension->getName()) + ); + $input->setOption('name', $name); + } + + $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); + } + + $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) { + // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion + $services = $this->servicesQuestion($io); + $input->setOption('services', $services); + } + } +} diff --git a/src/Command/Generate/ConfigFormBaseCommand.php b/src/Command/Generate/ConfigFormBaseCommand.php new file mode 100644 index 000000000..736180c1c --- /dev/null +++ b/src/Command/Generate/ConfigFormBaseCommand.php @@ -0,0 +1,91 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->routeProvider = $routeProvider; + $this->elementInfoManager = $elementInfoManager; + $this->appRoot = $appRoot; + $this->chainQueue = $chainQueue; + parent::__construct($extensionManager, $generator, $chainQueue, $stringConverter, $elementInfoManager, $routeProvider); + } + + protected function configure() + { + $this->setFormType('ConfigFormBase'); + $this->setCommandName('generate:form:config'); + $this->setAliases(['gfc']); + parent::configure(); + } +} diff --git a/src/Command/Generate/ControllerCommand.php b/src/Command/Generate/ControllerCommand.php new file mode 100644 index 000000000..0a0a08f14 --- /dev/null +++ b/src/Command/Generate/ControllerCommand.php @@ -0,0 +1,320 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->validator = $validator; + $this->routeProvider = $routeProvider; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:controller') + ->setDescription($this->trans('commands.generate.controller.description')) + ->setHelp($this->trans('commands.generate.controller.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.controller.options.class') + ) + ->addOption( + 'routes', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.generate.controller.options.routes') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ) + ->addOption( + 'test', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.controller.options.test') + ) + ->setAliases(['gcn']); + } + + /** + * {@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 1; + } + + $module = $input->getOption('module'); + $class = $input->getOption('class'); + $routes = $input->getOption('routes'); + $test = $input->getOption('test'); + $services = $input->getOption('services'); + + $routes = $this->inlineValueAsArray($routes); + $input->setOption('routes', $routes); + + // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices + $build_services = $this->buildServices($services); + + //$this->generator->setLearning($learning); + $this->generator->generate( + $module, + $class, + $routes, + $test, + $build_services + ); + + // Run cache rebuild to see changes in Web UI + $this->chainQueue->addCommand('router:rebuild', []); + + return 0; + } + + /** + * {@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/'.($method!='hello'?$method:'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); + } + + /** + * @return \Drupal\Console\Generator\ControllerGenerator + */ + protected function createGenerator() + { + return new ControllerGenerator(); + } +} diff --git a/src/Command/Generate/EntityBundleCommand.php b/src/Command/Generate/EntityBundleCommand.php new file mode 100644 index 000000000..2a9ef6897 --- /dev/null +++ b/src/Command/Generate/EntityBundleCommand.php @@ -0,0 +1,151 @@ +validator = $validator; + $this->generator = $generator; + $this->extensionManager = $extensionManager; + parent::__construct(); + } + + + protected function configure() + { + $this + ->setName('generate:entity:bundle') + ->setDescription($this->trans('commands.generate.entity.bundle.description')) + ->setHelp($this->trans('commands.generate.entity.bundle.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'bundle-name', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.entity.bundle.options.bundle-name') + ) + ->addOption( + 'bundle-title', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.entity.bundle.options.bundle-title') + ) + ->setAliases(['geb']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $bundleName = $input->getOption('bundle-name'); + $bundleTitle = $input->getOption('bundle-title'); + + $generator = $this->generator; + //TODO: + // $generator->setLearning($learning); + $generator->generate($module, $bundleName, $bundleTitle); + + return 0; + } + + /** + * {@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); + } + } +} diff --git a/src/Command/Generate/EntityCommand.php b/src/Command/Generate/EntityCommand.php new file mode 100644 index 000000000..d5869edc7 --- /dev/null +++ b/src/Command/Generate/EntityCommand.php @@ -0,0 +1,176 @@ +entityType = $entityType; + } + + /** + * @param $commandName + */ + protected function setCommandName($commandName) + { + $this->commandName = $commandName; + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $commandKey = str_replace(':', '.', $this->commandName); + + $this + ->setName($this->commandName) + ->setDescription( + sprintf( + $this->trans('commands.'.$commandKey.'.description'), + $this->entityType + ) + ) + ->setHelp( + sprintf( + $this->trans('commands.'.$commandKey.'.help'), + $this->commandName, + $this->entityType + ) + ) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'entity-class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.'.$commandKey.'.options.entity-class') + ) + ->addOption( + 'entity-name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.'.$commandKey.'.options.entity-name') + ) + ->addOption( + 'base-path', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.' . $commandKey . '.options.base-path') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.'.$commandKey.'.options.label') + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // Operations defined in EntityConfigCommand and EntityContentCommand. + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $commandKey = str_replace(':', '.', $this->commandName); + $utils = $this->stringConverter; + + // --module option + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + // --entity-class option + $entityClass = $input->getOption('entity-class'); + if (!$entityClass) { + $entityClass = $io->ask( + $this->trans('commands.'.$commandKey.'.questions.entity-class'), + 'DefaultEntity', + function ($entityClass) { + return $this->validator->validateSpaces($entityClass); + } + ); + + $input->setOption('entity-class', $entityClass); + } + + // --entity-name option + $entityName = $input->getOption('entity-name'); + if (!$entityName) { + $entityName = $io->ask( + $this->trans('commands.'.$commandKey.'.questions.entity-name'), + $utils->camelCaseToMachineName($entityClass), + function ($entityName) { + return $this->validator->validateMachineName($entityName); + } + ); + $input->setOption('entity-name', $entityName); + } + + // --label option + $label = $input->getOption('label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.'.$commandKey.'.questions.label'), + $utils->camelCaseToHuman($entityClass) + ); + $input->setOption('label', $label); + } + + // --base-path option + $base_path = $input->getOption('base-path'); + if (!$base_path) { + $base_path = $this->getDefaultBasePath(); + } + $base_path = $io->ask( + $this->trans('commands.'.$commandKey.'.questions.base-path'), + $base_path + ); + if (substr($base_path, 0, 1) !== '/') { + // Base path must start with a leading '/'. + $base_path = '/' . $base_path; + } + $input->setOption('base-path', $base_path); + } + + /** + * Gets default base path. + * + * @return string + * Default base path. + */ + protected function getDefaultBasePath() + { + return '/admin/structure'; + } +} diff --git a/src/Command/Generate/EntityConfigCommand.php b/src/Command/Generate/EntityConfigCommand.php new file mode 100644 index 000000000..0f77e100a --- /dev/null +++ b/src/Command/Generate/EntityConfigCommand.php @@ -0,0 +1,101 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->validator = $validator; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + + protected function configure() + { + $this->setEntityType('EntityConfig'); + $this->setCommandName('generate:entity:config'); + parent::configure(); + + $this->addOption( + 'bundle-of', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.entity.config.options.bundle-of') + ) + ->setAliases(['gecg']); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + parent::interact($input, $output); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $module = $input->getOption('module'); + $entity_class = $input->getOption('entity-class'); + $entity_name = $input->getOption('entity-name'); + $label = $input->getOption('label'); + $bundle_of = $input->getOption('bundle-of'); + $base_path = $input->getOption('base-path'); + + $this + ->generator + ->generate($module, $entity_name, $entity_class, $label, $base_path, $bundle_of); + } +} diff --git a/src/Command/Generate/EntityContentCommand.php b/src/Command/Generate/EntityContentCommand.php new file mode 100644 index 000000000..b664450e2 --- /dev/null +++ b/src/Command/Generate/EntityContentCommand.php @@ -0,0 +1,174 @@ +chainQueue = $chainQueue; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->extensionManager = $extensionManager; + $this->validator = $validator; + parent::__construct(); + } + + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setEntityType('EntityContent'); + $this->setCommandName('generate:entity:content'); + parent::configure(); + + $this->addOption( + 'has-bundles', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.entity.content.options.has-bundles') + ); + + $this->addOption( + 'is-translatable', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.entity.content.options.is-translatable') + ); + + $this->addOption( + 'revisionable', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.entity.content.options.revisionable') + ) + ->setAliases(['gect']); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + parent::interact($input, $output); + $io = new DrupalStyle($input, $output); + + // --bundle-of option + $bundle_of = $input->getOption('has-bundles'); + if (!$bundle_of) { + $bundle_of = $io->confirm( + $this->trans('commands.generate.entity.content.questions.has-bundles'), + false + ); + $input->setOption('has-bundles', $bundle_of); + } + + // --is-translatable option + $is_translatable = $io->confirm( + $this->trans('commands.generate.entity.content.questions.is-translatable'), + true + ); + $input->setOption('is-translatable', $is_translatable); + + // --revisionable option + $revisionable = $io->confirm( + $this->trans('commands.generate.entity.content.questions.revisionable'), + true + ); + $input->setOption('revisionable', $revisionable); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $module = $input->getOption('module'); + $entity_class = $input->getOption('entity-class'); + $entity_name = $input->getOption('entity-name'); + $label = $input->getOption('label'); + $has_bundles = $input->getOption('has-bundles'); + $base_path = $input->getOption('base-path'); + $learning = $input->hasOption('learning')?$input->getOption('learning'):false; + $bundle_entity_name = $has_bundles ? $entity_name . '_type' : null; + $is_translatable = $input->hasOption('is-translatable') ? $input->getOption('is-translatable') : true; + $revisionable = $input->hasOption('revisionable') ? $input->getOption('revisionable') : false; + + $io = new DrupalStyle($input, $output); + $generator = $this->generator; + + $generator->setIo($io); + //@TODO: + //$generator->setLearning($learning); + + $generator->generate($module, $entity_name, $entity_class, $label, $base_path, $is_translatable, $bundle_entity_name, $revisionable); + + if ($has_bundles) { + $this->chainQueue->addCommand( + 'generate:entity:config', [ + '--module' => $module, + '--entity-class' => $entity_class . 'Type', + '--entity-name' => $entity_name . '_type', + '--label' => $label . ' type', + '--bundle-of' => $entity_name + ] + ); + } + } +} diff --git a/src/Command/Generate/EventSubscriberCommand.php b/src/Command/Generate/EventSubscriberCommand.php new file mode 100644 index 000000000..b4f8b29fb --- /dev/null +++ b/src/Command/Generate/EventSubscriberCommand.php @@ -0,0 +1,197 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->eventDispatcher = $eventDispatcher; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:event:subscriber') + ->setDescription($this->trans('commands.generate.event.subscriber.description')) + ->setHelp($this->trans('commands.generate.event.subscriber.description')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'name', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.service.options.name') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.service.options.class') + ) + ->addOption( + 'events', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.events') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ) + ->setAliases(['ges']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $name = $input->getOption('name'); + $class = $input->getOption('class'); + $events = $input->getOption('events'); + $services = $input->getOption('services'); + + // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices + $buildServices = $this->buildServices($services); + + $this->generator->generate($module, $name, $class, $events, $buildServices); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); + } + + /** + * {@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); + } + + // --service-name option + $name = $input->getOption('name'); + if (!$name) { + $name = $io->ask( + $this->trans('commands.generate.service.questions.service-name'), + sprintf('%s.default', $module) + ); + $input->setOption('name', $name); + } + + // --class option + $class = $input->getOption('class'); + if (!$class) { + $class = $io->ask( + $this->trans('commands.generate.event.subscriber.questions.class'), + 'DefaultSubscriber' + ); + $input->setOption('class', $class); + } + + // --events option + $events = $input->getOption('events'); + if (!$events) { + // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion + $events = $this->eventsQuestion($io); + $input->setOption('events', $events); + } + + // --services option + $services = $input->getOption('services'); + if (!$services) { + // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion + $services = $this->servicesQuestion($io); + $input->setOption('services', $services); + } + } +} diff --git a/src/Command/Generate/FormAlterCommand.php b/src/Command/Generate/FormAlterCommand.php new file mode 100644 index 000000000..4c3d876f7 --- /dev/null +++ b/src/Command/Generate/FormAlterCommand.php @@ -0,0 +1,324 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->moduleHandler = $moduleHandler; + $this->elementInfoManager = $elementInfoManager; + $this->profiler = $profiler; + $this->appRoot = $appRoot; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected $metadata = [ + 'class' => [], + 'method'=> [], + 'file'=> [], + 'unset' => [] + ]; + + protected function configure() + { + $this + ->setName('generate:form:alter') + ->setDescription( + $this->trans('commands.generate.form.alter.description') + ) + ->setHelp($this->trans('commands.generate.form.alter.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'form-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.form.alter.options.form-id') + ) + ->addOption( + 'inputs', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.inputs') + ) + ->setAliases(['gfa']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $formId = $input->getOption('form-id'); + $inputs = $input->getOption('inputs'); + + $function = $module . '_form_' .$formId . '_alter'; + + if ($this->extensionManager->validateModuleFunctionExist($module, $function)) { + throw new \Exception( + sprintf( + $this->trans('commands.generate.form.alter.messages.help-already-implemented'), + $module + ) + ); + } + + //validate if input is an array + if (!is_array($inputs[0])) { + $inputs= $this->explodeInlineArray($inputs); + } + + $this + ->generator + ->generate($module, $formId, $inputs, $this->metadata); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 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); + + // --form-id option + $formId = $input->getOption('form-id'); + if (!$formId) { + $forms = []; + // Get form ids from webprofiler + if ($this->moduleHandler->moduleExists('webprofiler')) { + $io->info( + $this->trans('commands.generate.form.alter.messages.loading-forms') + ); + $forms = $this->getWebprofilerForms(); + } + + if (!empty($forms)) { + $formId = $io->choiceNoList( + $this->trans('commands.generate.form.alter.options.form-id'), + array_keys($forms) + ); + } + } + + if ($this->moduleHandler->moduleExists('webprofiler') && isset($forms[$formId])) { + $this->metadata['class'] = $forms[$formId]['class']['class']; + $this->metadata['method'] = $forms[$formId]['class']['method']; + $this->metadata['file'] = str_replace( + $this->appRoot, + '', + $forms[$formId]['class']['file'] + ); + + foreach ($forms[$formId]['form'] as $itemKey => $item) { + if ($item['#type'] == 'hidden') { + unset($forms[$formId]['form'][$itemKey]); + } + } + + unset($forms[$formId]['form']['form_build_id']); + unset($forms[$formId]['form']['form_token']); + unset($forms[$formId]['form']['form_id']); + unset($forms[$formId]['form']['actions']); + + $formItems = array_keys($forms[$formId]['form']); + + $formItemsToHide = $io->choice( + $this->trans('commands.generate.form.alter.messages.hide-form-elements'), + $formItems, + null, + true + ); + + $this->metadata['unset'] = array_filter(array_map('trim', $formItemsToHide)); + } + + $input->setOption('form-id', $formId); + + // @see Drupal\Console\Command\Shared\FormTrait::formQuestion + $inputs = $input->getOption('inputs'); + + if (empty($inputs)) { + $io->writeln($this->trans('commands.generate.form.alter.messages.inputs')); + $inputs = $this->formQuestion($io); + } else { + $inputs= $this->explodeInlineArray($inputs); + } + + $input->setOption('inputs', $inputs); + } + + /** + * @{@inheritdoc} + */ + public function explodeInlineArray($inlineInputs) + { + $inputs = []; + foreach ($inlineInputs as $inlineInput) { + $explodeInput = explode(" ", $inlineInput); + $parameters = []; + foreach ($explodeInput as $inlineParameter) { + list($key, $value) = explode(":", $inlineParameter); + if (!empty($value)) { + $parameters[$key] = $value; + } + } + $inputs[] = $parameters; + } + + return $inputs; + } + + protected function createGenerator() + { + return new FormAlterGenerator(); + } + + public function getWebprofilerForms() + { + $tokens = $this->profiler->find(null, null, 1000, null, '', ''); + $forms = []; + foreach ($tokens as $token) { + $token = [$token['token']]; + $profile = $this->profiler->loadProfile($token); + $formCollector = $profile->getCollector('forms'); + $collectedForms = $formCollector->getForms(); + if (empty($forms)) { + $forms = $collectedForms; + } elseif (!empty($collectedForms)) { + $forms = array_merge($forms, $collectedForms); + } + } + return $forms; + } +} diff --git a/src/Command/Generate/FormBaseCommand.php b/src/Command/Generate/FormBaseCommand.php new file mode 100644 index 000000000..9e75348da --- /dev/null +++ b/src/Command/Generate/FormBaseCommand.php @@ -0,0 +1,18 @@ +setFormType('FormBase'); + $this->setCommandName('generate:form'); + parent::configure(); + } +} diff --git a/src/Command/Generate/FormCommand.php b/src/Command/Generate/FormCommand.php new file mode 100644 index 000000000..6b84175c8 --- /dev/null +++ b/src/Command/Generate/FormCommand.php @@ -0,0 +1,330 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->chainQueue = $chainQueue; + $this->stringConverter = $stringConverter; + $this->elementInfoManager = $elementInfoManager; + $this->routeProvider = $routeProvider; + parent::__construct(); + } + + protected function setFormType($formType) + { + return $this->formType = $formType; + } + + protected function setCommandName($commandName) + { + return $this->commandName = $commandName; + } + + protected function configure() + { + $this + ->setName($this->commandName) + ->setDescription( + sprintf( + $this->trans('commands.generate.form.description'), + $this->formType + ) + ) + ->setHelp( + sprintf( + $this->trans('commands.generate.form.help'), + $this->commandName, + $this->formType + ) + ) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.form.options.class') + ) + ->addOption( + 'form-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.form.options.form-id') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ) + ->addOption( + 'config-file', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.form.options.config-file') + ) + ->addOption( + 'inputs', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.common.options.inputs') + ) + ->addOption( + 'path', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.form.options.path') + ) + ->addOption( + 'menu-link-gen', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.form.options.menu-link-gen') + ) + ->addOption( + 'menu-link-title', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.form.options.menu-link-title') + ) + ->addOption( + 'menu-parent', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.form.options.menu-parent') + ) + ->addOption( + 'menu-link-desc', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.form.options.menu-link-desc') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $module = $input->getOption('module'); + $services = $input->getOption('services'); + $path = $input->getOption('path'); + $config_file = $input->getOption('config-file'); + $class_name = $input->getOption('class'); + $form_id = $input->getOption('form-id'); + $form_type = $this->formType; + $menu_link_gen = $input->getOption('menu-link-gen'); + $menu_parent = $input->getOption('menu-parent'); + $menu_link_title = $input->getOption('menu-link-title'); + $menu_link_desc = $input->getOption('menu-link-desc'); + + // if exist form generate config file + $inputs = $input->getOption('inputs'); + $build_services = $this->buildServices($services); + + $this + ->generator + ->generate($module, $class_name, $form_id, $form_type, $build_services, $config_file, $inputs, $path, $menu_link_gen, $menu_link_title, $menu_parent, $menu_link_desc); + + $this->chainQueue->addCommand('router:rebuild', []); + } + + /** + * {@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 + $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->stringConverter->camelCaseToMachineName($className) + ); + $input->setOption('form-id', $formId); + } + + // --services option + // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion + $services = $this->servicesQuestion($io); + $input->setOption('services', $services); + + // --config_file option + $config_file = $input->getOption('config-file'); + + if (!$config_file) { + $config_file = $io->confirm( + $this->trans('commands.generate.form.questions.config-file'), + true + ); + $input->setOption('config-file', $config_file); + } + + // --inputs option + $inputs = $input->getOption('inputs'); + if (!$inputs) { + // @see \Drupal\Console\Command\Shared\FormTrait::formQuestion + $inputs = $this->formQuestion($io); + $input->setOption('inputs', $inputs); + } + + $path = $input->getOption('path'); + if (!$path) { + if ($this->formType == 'ConfigFormBase') { + $form_path = '/admin/config/{{ module_name }}/{{ class_name_short }}'; + $form_path = sprintf( + '/admin/config/%s/%s', + $module, + strtolower($this->stringConverter->removeSuffix($className)) + ); + } else { + $form_path = sprintf( + '/%s/form/%s', + $module, + $this->stringConverter->camelCaseToMachineName($this->stringConverter->removeSuffix($className)) + ); + } + $path = $io->ask( + $this->trans('commands.generate.form.questions.path'), + $form_path, + function ($path) { + if (count($this->routeProvider->getRoutesByPattern($path)) > 0) { + throw new \InvalidArgumentException( + sprintf( + $this->trans( + 'commands.generate.form.messages.path-already-added' + ), + $path + ) + ); + } + + return $path; + } + ); + $input->setOption('path', $path); + } + + // --link option for links.menu + if ($this->formType == 'ConfigFormBase') { + $menu_options = $this->menuQuestion($io, $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']); + } + } + } +} diff --git a/src/Command/Generate/HelpCommand.php b/src/Command/Generate/HelpCommand.php new file mode 100644 index 000000000..678ce7143 --- /dev/null +++ b/src/Command/Generate/HelpCommand.php @@ -0,0 +1,148 @@ +generator = $generator; + $this->site = $site; + $this->extensionManager = $extensionManager; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:help') + ->setDescription($this->trans('commands.generate.help.description')) + ->setHelp($this->trans('commands.generate.help.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'description', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.module.options.description') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + + if ($this->extensionManager->validateModuleFunctionExist($module, $module . '_help')) { + throw new \Exception( + sprintf( + $this->trans('commands.generate.help.messages.help-already-implemented'), + $module + ) + ); + } + + $description = $input->getOption('description'); + + $this + ->generator + ->generate($module, $description); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 0; + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $this->site->loadLegacyFile('/core/includes/update.inc'); + $this->site->loadLegacyFile('/core/includes/schema.inc'); + + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + $description = $input->getOption('description'); + if (!$description) { + $description = $io->ask( + $this->trans('commands.generate.module.questions.description'), + 'My Awesome Module' + ); + } + $input->setOption('description', $description); + } +} diff --git a/src/Command/Generate/ModuleCommand.php b/src/Command/Generate/ModuleCommand.php new file mode 100644 index 000000000..1382b08b3 --- /dev/null +++ b/src/Command/Generate/ModuleCommand.php @@ -0,0 +1,409 @@ +generator = $generator; + $this->validator = $validator; + $this->appRoot = $appRoot; + $this->stringConverter = $stringConverter; + $this->drupalApi = $drupalApi; + $this->twigtemplate = $twigtemplate; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:module') + ->setDescription($this->trans('commands.generate.module.description')) + ->setHelp($this->trans('commands.generate.module.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.module.options.module') + ) + ->addOption( + 'machine-name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.module.options.machine-name') + ) + ->addOption( + 'module-path', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.module.options.module-path') + ) + ->addOption( + 'description', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.module.options.description') + ) + ->addOption( + 'core', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.module.options.core') + ) + ->addOption( + 'package', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.module.options.package') + ) + ->addOption( + 'module-file', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.module.options.module-file') + ) + ->addOption( + 'features-bundle', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.module.options.features-bundle') + ) + ->addOption( + 'composer', + null, + InputOption::VALUE_NONE, + $this->trans('commands.generate.module.options.composer') + ) + ->addOption( + 'dependencies', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.module.options.dependencies'), + '' + ) + ->addOption( + 'test', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.module.options.test') + ) + ->addOption( + 'twigtemplate', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.module.options.twigtemplate') + ) + ->setAliases(['gm']); + } + + /** + * {@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 1; + } + + $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'); + $dependencies = $this->validator->validateExtensions( + $input->getOption('dependencies'), + 'module', + $io + ); + $test = $input->getOption('test'); + $twigTemplate = $input->getOption('twigtemplate'); + + $this->generator->generate( + $module, + $machineName, + $modulePath, + $description, + $core, + $package, + $moduleFile, + $featuresBundle, + $composer, + $dependencies, + $test, + $twigTemplate + ); + + return 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 1; + } + + 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); + } + + $twigtemplate = $input->getOption('twigtemplate'); + if (!$twigtemplate) { + $twigtemplate = $io->confirm( + $this->trans('commands.generate.module.questions.twigtemplate'), + true + ); + $input->setOption('twigtemplate', $twigtemplate); + } + } + + /** + * @return ModuleGenerator + */ + protected function createGenerator() + { + return new ModuleGenerator(); + } +} diff --git a/src/Command/Generate/ModuleFileCommand.php b/src/Command/Generate/ModuleFileCommand.php new file mode 100644 index 000000000..e28c8ac33 --- /dev/null +++ b/src/Command/Generate/ModuleFileCommand.php @@ -0,0 +1,115 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:module:file') + ->setDescription($this->trans('commands.generate.module.file.description')) + ->setHelp($this->trans('commands.generate.module.file.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io, $yes)) { + return 1; + } + + $machine_name = $input->getOption('module'); + $file_path = $this->extensionManager->getModule($machine_name)->getPath(); + $generator = $this->generator; + + $generator->generate( + $machine_name, + $file_path + ); + } + + + /** + * {@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); + } +} diff --git a/src/Command/Generate/PermissionCommand.php b/src/Command/Generate/PermissionCommand.php new file mode 100644 index 000000000..a7aee3778 --- /dev/null +++ b/src/Command/Generate/PermissionCommand.php @@ -0,0 +1,122 @@ +extensionManager = $extensionManager; + $this->stringConverter = $stringConverter; + $this->generator = $permissionGenerator; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:permissions') + ->setDescription($this->trans('commands.generate.permission.description')) + ->setHelp($this->trans('commands.generate.permission.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'permissions', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.common.options.permissions') + ) + ->setAliases(['gp']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $module = $input->getOption('module'); + $permissions = $input->getOption('permissions'); + $learning = $input->hasOption('learning'); + + + $this->generator->generate($module, $permissions, $learning); + } + + /** + * {@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); + } + + // --permissions option + $permissions = $input->getOption('permissions'); + if (!$permissions) { + // @see \Drupal\Console\Command\Shared\PermissionTrait::permissionQuestion + $permissions = $this->permissionQuestion($io); + $input->setOption('permissions', $permissions); + } + } +} diff --git a/src/Command/Generate/PluginBlockCommand.php b/src/Command/Generate/PluginBlockCommand.php new file mode 100644 index 000000000..21679d997 --- /dev/null +++ b/src/Command/Generate/PluginBlockCommand.php @@ -0,0 +1,292 @@ +configFactory = $configFactory; + $this->chainQueue = $chainQueue; + $this->generator = $generator; + $this->entityTypeManager = $entityTypeManager; + $this->extensionManager = $extensionManager; + $this->validator = $validator; + $this->stringConverter = $stringConverter; + $this->elementInfoManager = $elementInfoManager; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:block') + ->setDescription($this->trans('commands.generate.plugin.block.description')) + ->setHelp($this->trans('commands.generate.plugin.block.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.plugin-id') + ) + ->addOption( + 'theme-region', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.theme-region') + ) + ->addOption( + 'inputs', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.inputs') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ) + ->setAliases(['gpb']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $services = $input->getOption('services'); + $theme_region = $input->getOption('theme-region'); + $inputs = $input->getOption('inputs'); + + $theme = $this->configFactory->get('system.theme')->get('default'); + $themeRegions = \system_region_list($theme, REGIONS_VISIBLE); + + if (!empty($theme_region) && !isset($themeRegions[$theme_region])) { + $io->error( + sprintf( + $this->trans('commands.generate.plugin.block.messages.invalid-theme-region'), + $theme_region + ) + ); + + return 1; + } + + // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices + $build_services = $this->buildServices($services); + + $this->generator + ->generate( + $module, + $class_name, + $label, + $plugin_id, + $build_services, + $inputs + ); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + if ($theme_region) { + $block = $this->entityTypeManager + ->getStorage('block') + ->create( + [ + 'id'=> $plugin_id, + 'plugin' => $plugin_id, + 'theme' => $theme + ] + ); + $block->setRegion($theme_region); + $block->save(); + } + } + + 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.questions.class'), + 'DefaultBlock', + 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.block.questions.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.questions.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.questions.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); + } +} diff --git a/src/Command/Generate/PluginCKEditorButtonCommand.php b/src/Command/Generate/PluginCKEditorButtonCommand.php new file mode 100644 index 000000000..2152dbeac --- /dev/null +++ b/src/Command/Generate/PluginCKEditorButtonCommand.php @@ -0,0 +1,207 @@ +chainQueue = $chainQueue; + $this->generator = $generator; + $this->extensionManager = $extensionManager; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:ckeditorbutton') + ->setDescription($this->trans('commands.generate.plugin.ckeditorbutton.description')) + ->setHelp($this->trans('commands.generate.plugin.ckeditorbutton.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.ckeditorbutton.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.ckeditorbutton.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.ckeditorbutton.options.plugin-id') + ) + ->addOption( + 'button-name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.ckeditorbutton.options.button-name') + ) + ->addOption( + 'button-icon-path', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.ckeditorbutton.options.button-icon-path') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $button_name = $input->getOption('button-name'); + $button_icon_path = $input->getOption('button-icon-path'); + + $this + ->generator + ->generate($module, $class_name, $label, $plugin_id, $button_name, $button_icon_path); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false); + + return 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_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->stringConverter->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->stringConverter->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->stringConverter->anyCaseToUcFirst($plugin_id) + ); + $input->setOption('button-name', $button_name); + } + + // --button-icon-path option + $button_icon_path = $input->getOption('button-icon-path'); + if (!$button_icon_path) { + $button_icon_path = $io->ask( + $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-icon-path'), + drupal_get_path('module', $module) . '/js/plugins/' . $plugin_id . '/images/icon.png' + ); + $input->setOption('button-icon-path', $button_icon_path); + } + } +} diff --git a/src/Command/Generate/PluginConditionCommand.php b/src/Command/Generate/PluginConditionCommand.php new file mode 100644 index 000000000..24bc6da17 --- /dev/null +++ b/src/Command/Generate/PluginConditionCommand.php @@ -0,0 +1,253 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->chainQueue = $chainQueue; + $this->entitytyperepository = $entitytyperepository; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:condition') + ->setDescription($this->trans('commands.generate.plugin.condition.description')) + ->setHelp($this->trans('commands.generate.plugin.condition.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.condition.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.condition.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.condition.options.plugin-id') + ) + ->addOption( + 'context-definition-id', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.condition.options.context-definition-id') + ) + ->addOption( + 'context-definition-label', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.condition.options.context-definition-label') + ) + ->addOption( + 'context-definition-required', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.condition.options.context-definition-required') + ) + ->setAliases(['gpc']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $context_definition_id = $input->getOption('context-definition-id'); + $context_definition_label = $input->getOption('context-definition-label'); + $context_definition_required = $input->getOption('context-definition-required')?'TRUE':'FALSE'; + + $this + ->generator + ->generate($module, $class_name, $label, $plugin_id, $context_definition_id, $context_definition_label, $context_definition_required); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 0; + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $entityTypeRepository = $this->entitytyperepository; + + $entity_types = $entityTypeRepository->getEntityTypeLabels(true); + + // --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.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->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.condition.questions.plugin-id'), + $this->stringConverter->camelCaseToUnderscore($class) + ); + $input->setOption('plugin-id', $pluginId); + } + + $context_definition_id = $input->getOption('context-definition-id'); + if (!$context_definition_id) { + $context_type = ['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); + } + } +} diff --git a/src/Command/Generate/PluginFieldCommand.php b/src/Command/Generate/PluginFieldCommand.php new file mode 100644 index 000000000..35577216a --- /dev/null +++ b/src/Command/Generate/PluginFieldCommand.php @@ -0,0 +1,346 @@ +extensionManager = $extensionManager; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:field') + ->setDescription($this->trans('commands.generate.plugin.field.description')) + ->setHelp($this->trans('commands.generate.plugin.field.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'type-class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.field.options.type-class') + ) + ->addOption( + 'type-label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.type-label') + ) + ->addOption( + 'type-plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.type-plugin-id') + ) + ->addOption( + 'type-description', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.type-type-description') + ) + ->addOption( + 'formatter-class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.field.options.class') + ) + ->addOption( + 'formatter-label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.formatter-label') + ) + ->addOption( + 'formatter-plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.formatter-plugin-id') + ) + ->addOption( + 'widget-class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.field.options.formatter-class') + ) + ->addOption( + 'widget-label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.widget-label') + ) + ->addOption( + 'widget-plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.widget-plugin-id') + ) + ->addOption( + 'field-type', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.field-type') + ) + ->addOption( + 'default-widget', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.default-widget') + ) + ->addOption( + 'default-formatter', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.field.options.default-formatter') + ) + ->setAliases(['gpf']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $this->chainQueue + ->addCommand( + 'generate:plugin:fieldtype', [ + '--module' => $input->getOption('module'), + '--class' => $input->getOption('type-class'), + '--label' => $input->getOption('type-label'), + '--plugin-id' => $input->getOption('type-plugin-id'), + '--description' => $input->getOption('type-description'), + '--default-widget' => $input->getOption('default-widget'), + '--default-formatter' => $input->getOption('default-formatter'), + ], + false + ); + + $this->chainQueue + ->addCommand( + 'generate:plugin:fieldwidget', [ + '--module' => $input->getOption('module'), + '--class' => $input->getOption('widget-class'), + '--label' => $input->getOption('widget-label'), + '--plugin-id' => $input->getOption('widget-plugin-id'), + '--field-type' => $input->getOption('field-type'), + ], + false + ); + $this->chainQueue + ->addCommand( + 'generate:plugin:fieldformatter', [ + '--module' => $input->getOption('module'), + '--class' => $input->getOption('formatter-class'), + '--label' => $input->getOption('formatter-label'), + '--plugin-id' => $input->getOption('formatter-plugin-id'), + '--field-type' => $input->getOption('field-type'), + ], + false + ); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false); + + return 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); + } + + // --type-class option + $typeClass = $input->getOption('type-class'); + if (!$typeClass) { + $typeClass = $io->ask( + $this->trans('commands.generate.plugin.field.questions.type-class'), + 'ExampleFieldType' + ); + $input->setOption('type-class', $typeClass); + } + + // --type-label option + $label = $input->getOption('type-label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.generate.plugin.field.questions.type-label'), + $this->stringConverter->camelCaseToHuman($typeClass) + ); + $input->setOption('type-label', $label); + } + + // --type-plugin-id option + $plugin_id = $input->getOption('type-plugin-id'); + if (!$plugin_id) { + $plugin_id = $io->ask( + $this->trans('commands.generate.plugin.field.questions.type-plugin-id'), + $this->stringConverter->camelCaseToUnderscore($typeClass) + ); + $input->setOption('type-plugin-id', $plugin_id); + } + + // --type-description option + $description = $input->getOption('type-description'); + if (!$description) { + $description = $io->ask( + $this->trans('commands.generate.plugin.field.questions.type-description'), + 'My Field Type' + ); + $input->setOption('type-description', $description); + } + + // --widget-class option + $widgetClass = $input->getOption('widget-class'); + if (!$widgetClass) { + $widgetClass = $io->ask( + $this->trans('commands.generate.plugin.field.questions.widget-class'), + 'ExampleWidgetType' + ); + $input->setOption('widget-class', $widgetClass); + } + + // --widget-label option + $widgetLabel = $input->getOption('widget-label'); + if (!$widgetLabel) { + $widgetLabel = $io->ask( + $this->trans('commands.generate.plugin.field.questions.widget-label'), + $this->stringConverter->camelCaseToHuman($widgetClass) + ); + $input->setOption('widget-label', $widgetLabel); + } + + // --widget-plugin-id option + $widget_plugin_id = $input->getOption('widget-plugin-id'); + if (!$widget_plugin_id) { + $widget_plugin_id = $io->ask( + $this->trans('commands.generate.plugin.field.questions.widget-plugin-id'), + $this->stringConverter->camelCaseToUnderscore($widgetClass) + ); + $input->setOption('widget-plugin-id', $widget_plugin_id); + } + + // --formatter-class option + $formatterClass = $input->getOption('formatter-class'); + if (!$formatterClass) { + $formatterClass = $io->ask( + $this->trans('commands.generate.plugin.field.questions.formatter-class'), + 'ExampleFormatterType' + ); + $input->setOption('formatter-class', $formatterClass); + } + + // --formatter-label option + $formatterLabel = $input->getOption('formatter-label'); + if (!$formatterLabel) { + $formatterLabel = $io->ask( + $this->trans('commands.generate.plugin.field.questions.formatter-label'), + $this->stringConverter->camelCaseToHuman($formatterClass) + ); + $input->setOption('formatter-label', $formatterLabel); + } + + // --formatter-plugin-id option + $formatter_plugin_id = $input->getOption('formatter-plugin-id'); + if (!$formatter_plugin_id) { + $formatter_plugin_id = $io->ask( + $this->trans('commands.generate.plugin.field.questions.formatter-plugin-id'), + $this->stringConverter->camelCaseToUnderscore($formatterClass) + ); + $input->setOption('formatter-plugin-id', $formatter_plugin_id); + } + + // --field-type option + $field_type = $input->getOption('field-type'); + if (!$field_type) { + $field_type = $io->ask( + $this->trans('commands.generate.plugin.field.questions.field-type'), + $plugin_id + ); + $input->setOption('field-type', $field_type); + } + + // --default-widget option + $default_widget = $input->getOption('default-widget'); + if (!$default_widget) { + $default_widget = $io->ask( + $this->trans('commands.generate.plugin.field.questions.default-widget'), + $widget_plugin_id + ); + $input->setOption('default-widget', $default_widget); + } + + // --default-formatter option + $default_formatter = $input->getOption('default-formatter'); + if (!$default_formatter) { + $default_formatter = $io->ask( + $this->trans('commands.generate.plugin.field.questions.default-formatter'), + $formatter_plugin_id + ); + $input->setOption('default-formatter', $default_formatter); + } + } +} diff --git a/src/Command/Generate/PluginFieldFormatterCommand.php b/src/Command/Generate/PluginFieldFormatterCommand.php new file mode 100644 index 000000000..627ae163e --- /dev/null +++ b/src/Command/Generate/PluginFieldFormatterCommand.php @@ -0,0 +1,205 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->fieldTypePluginManager = $fieldTypePluginManager; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:fieldformatter') + ->setDescription($this->trans('commands.generate.plugin.fieldformatter.description')) + ->setHelp($this->trans('commands.generate.plugin.fieldformatter.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.fieldformatter.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldformatter.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldformatter.options.plugin-id') + ) + ->addOption( + 'field-type', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldformatter.options.field-type') + ) + ->setAliases(['gpff']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $field_type = $input->getOption('field-type'); + + $this->generator->generate($module, $class_name, $label, $plugin_id, $field_type); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 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.fieldformatter.questions.class'), + 'ExampleFieldFormatter' + ); + $input->setOption('class', $class); + } + + // --plugin label option + $label = $input->getOption('label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.generate.plugin.fieldformatter.questions.label'), + $this->stringConverter->camelCaseToHuman($class) + ); + $input->setOption('label', $label); + } + + // --name option + $plugin_id = $input->getOption('plugin-id'); + if (!$plugin_id) { + $plugin_id = $io->ask( + $this->trans('commands.generate.plugin.fieldformatter.questions.plugin-id'), + $this->stringConverter->camelCaseToUnderscore($class) + ); + $input->setOption('plugin-id', $plugin_id); + } + + // --field type option + $field_type = $input->getOption('field-type'); + if (!$field_type) { + // Gather valid field types. + $field_type_options = []; + foreach ($this->fieldTypePluginManager->getGroupedDefinitions($this->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); + } + } +} diff --git a/src/Command/Generate/PluginFieldTypeCommand.php b/src/Command/Generate/PluginFieldTypeCommand.php new file mode 100644 index 000000000..49f6b6eef --- /dev/null +++ b/src/Command/Generate/PluginFieldTypeCommand.php @@ -0,0 +1,221 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:fieldtype') + ->setDescription($this->trans('commands.generate.plugin.fieldtype.description')) + ->setHelp($this->trans('commands.generate.plugin.fieldtype.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.fieldtype.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldtype.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldtype.options.plugin-id') + ) + ->addOption( + 'description', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldtype.options.description') + ) + ->addOption( + 'default-widget', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldtype.options.default-widget') + ) + ->addOption( + 'default-formatter', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldtype.options.default-formatter') + ) + ->setAliases(['gpft']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $description = $input->getOption('description'); + $default_widget = $input->getOption('default-widget'); + $default_formatter = $input->getOption('default-formatter'); + + $this->generator + ->generate($module, $class_name, $label, $plugin_id, $description, $default_widget, $default_formatter); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false); + + return 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_name = $input->getOption('class'); + if (!$class_name) { + $class_name = $io->ask( + $this->trans('commands.generate.plugin.fieldtype.questions.class'), + 'ExampleFieldType' + ); + $input->setOption('class', $class_name); + } + + // --label option + $label = $input->getOption('label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.generate.plugin.fieldtype.questions.label'), + $this->stringConverter->camelCaseToHuman($class_name) + ); + $input->setOption('label', $label); + } + + // --plugin-id option + $plugin_id = $input->getOption('plugin-id'); + if (!$plugin_id) { + $plugin_id = $io->ask( + $this->trans('commands.generate.plugin.fieldtype.questions.plugin-id'), + $this->stringConverter->camelCaseToUnderscore($class_name) + ); + $input->setOption('plugin-id', $plugin_id); + } + + // --description option + $description = $input->getOption('description'); + if (!$description) { + $description = $io->ask( + $this->trans('commands.generate.plugin.fieldtype.questions.description'), + 'My Field Type' + ); + $input->setOption('description', $description); + } + + // --default-widget option + $default_widget = $input->getOption('default-widget'); + if (!$default_widget) { + $default_widget = $io->askEmpty( + $this->trans('commands.generate.plugin.fieldtype.questions.default-widget') + ); + $input->setOption('default-widget', $default_widget); + } + + // --default-formatter option + $default_formatter = $input->getOption('default-formatter'); + if (!$default_formatter) { + $default_formatter = $io->askEmpty( + $this->trans('commands.generate.plugin.fieldtype.questions.default-formatter') + ); + $input->setOption('default-formatter', $default_formatter); + } + } +} diff --git a/src/Command/Generate/PluginFieldWidgetCommand.php b/src/Command/Generate/PluginFieldWidgetCommand.php new file mode 100644 index 000000000..a56213756 --- /dev/null +++ b/src/Command/Generate/PluginFieldWidgetCommand.php @@ -0,0 +1,210 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->fieldTypePluginManager = $fieldTypePluginManager; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:fieldwidget') + ->setDescription($this->trans('commands.generate.plugin.fieldwidget.description')) + ->setHelp($this->trans('commands.generate.plugin.fieldwidget.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.fieldwidget.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldwidget.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldwidget.options.plugin-id') + ) + ->addOption( + 'field-type', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.fieldwidget.options.field-type') + ) + ->setAliases(['gpfw']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $field_type = $input->getOption('field-type'); + + $this->generator->generate($module, $class_name, $label, $plugin_id, $field_type); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 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_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->stringConverter->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->stringConverter->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 = []; + foreach ($this->fieldTypePluginManager->getGroupedDefinitions($this->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); + } + } +} diff --git a/src/Command/Generate/PluginImageEffectCommand.php b/src/Command/Generate/PluginImageEffectCommand.php new file mode 100644 index 000000000..cf516e813 --- /dev/null +++ b/src/Command/Generate/PluginImageEffectCommand.php @@ -0,0 +1,185 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:imageeffect') + ->setDescription($this->trans('commands.generate.plugin.imageeffect.description')) + ->setHelp($this->trans('commands.generate.plugin.imageeffect.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.imageeffect.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.imageeffect.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.imageeffect.options.plugin-id') + ) + ->addOption( + 'description', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.imageeffect.options.description') + ) + ->setAliases(['gpie']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $description = $input->getOption('description'); + + $this->generator->generate($module, $class_name, $label, $plugin_id, $description); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + } + + 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_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->stringConverter->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->stringConverter->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); + } + } +} diff --git a/src/Command/Generate/PluginImageFormatterCommand.php b/src/Command/Generate/PluginImageFormatterCommand.php new file mode 100644 index 000000000..5a3cb696f --- /dev/null +++ b/src/Command/Generate/PluginImageFormatterCommand.php @@ -0,0 +1,172 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->validator = $validator; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:imageformatter') + ->setDescription($this->trans('commands.generate.plugin.imageformatter.description')) + ->setHelp($this->trans('commands.generate.plugin.imageformatter.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.imageformatter.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.imageformatter.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.imageformatter.options.plugin-id') + ) + ->setAliases(['gpif']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + + $this->generator->generate($module, $class_name, $label, $plugin_id); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + } + + 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_name = $input->getOption('class'); + if (!$class_name) { + $class_name = $io->ask( + $this->trans('commands.generate.plugin.imageformatter.questions.class'), + 'ExampleImageFormatter' + ); + $input->setOption('class', $class_name); + } + + // --label option + $label = $input->getOption('label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.generate.plugin.imageformatter.questions.label'), + $this->stringConverter->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.imageformatter.questions.plugin-id'), + $this->stringConverter->camelCaseToUnderscore($class_name) + ); + $input->setOption('plugin-id', $plugin_id); + } + } +} diff --git a/src/Command/Generate/PluginMailCommand.php b/src/Command/Generate/PluginMailCommand.php new file mode 100644 index 000000000..48a47d0d6 --- /dev/null +++ b/src/Command/Generate/PluginMailCommand.php @@ -0,0 +1,198 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->validator = $validator; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:mail') + ->setDescription($this->trans('commands.generate.plugin.mail.description')) + ->setHelp($this->trans('commands.generate.plugin.mail.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.mail.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.mail.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.mail.options.plugin-id') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $services = $input->getOption('services'); + + // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices + $build_services = $this->buildServices($services); + + $this->generator->generate($module, $class_name, $label, $plugin_id, $build_services); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + } + + 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); + } +} diff --git a/src/Command/Generate/PluginMigrateProcessCommand.php b/src/Command/Generate/PluginMigrateProcessCommand.php new file mode 100644 index 000000000..20ba70a60 --- /dev/null +++ b/src/Command/Generate/PluginMigrateProcessCommand.php @@ -0,0 +1,147 @@ +generator = $generator; + $this->chainQueue = $chainQueue; + $this->extensionManager = $extensionManager; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:migrate:process') + ->setDescription($this->trans('commands.generate.plugin.migrate.process.description')) + ->setHelp($this->trans('commands.generate.plugin.migrate.process.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.migrate.process.options.class') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.migrate.process.options.plugin-id') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $plugin_id = $input->getOption('plugin-id'); + + $this->generator->generate($module, $class_name, $plugin_id); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // 'module-name' option. + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + // 'class-name' option + $class = $input->getOption('class'); + if (!$class) { + $class = $io->ask( + $this->trans('commands.generate.plugin.migrate.process.questions.class'), + ucfirst($this->stringConverter->underscoreToCamelCase($module)) + ); + $input->setOption('class', $class); + } + + // 'plugin-id' option. + $pluginId = $input->getOption('plugin-id'); + if (!$pluginId) { + $pluginId = $io->ask( + $this->trans('commands.generate.plugin.migrate.source.questions.plugin-id'), + $this->stringConverter->camelCaseToUnderscore($class) + ); + $input->setOption('plugin-id', $pluginId); + } + } +} diff --git a/src/Command/Generate/PluginMigrateSourceCommand.php b/src/Command/Generate/PluginMigrateSourceCommand.php new file mode 100644 index 000000000..5de03cccf --- /dev/null +++ b/src/Command/Generate/PluginMigrateSourceCommand.php @@ -0,0 +1,267 @@ +configFactory = $configFactory; + $this->chainQueue = $chainQueue; + $this->generator = $generator; + $this->entityTypeManager = $entityTypeManager; + $this->extensionManager = $extensionManager; + $this->validator = $validator; + $this->stringConverter = $stringConverter; + $this->elementInfoManager = $elementInfoManager; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:migrate:source') + ->setDescription($this->trans('commands.generate.plugin.migrate.source.description')) + ->setHelp($this->trans('commands.generate.plugin.migrate.source.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.migrate.source.options.class') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.migrate.source.options.plugin-id') + ) + ->addOption( + 'table', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.migrate.source.options.table') + ) + ->addOption( + 'alias', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.migrate.source.options.alias') + ) + ->addOption( + 'group-by', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.migrate.source.options.group-by') + ) + ->addOption( + 'fields', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.generate.plugin.migrate.source.options.fields') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $plugin_id = $input->getOption('plugin-id'); + $table = $input->getOption('table'); + $alias = $input->getOption('alias'); + $group_by = $input->getOption('group-by'); + $fields = $input->getOption('fields'); + + $this->generator + ->generate( + $module, + $class_name, + $plugin_id, + $table, + $alias, + $group_by, + $fields + ); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + $class = $input->getOption('class'); + if (!$class) { + $class = $io->ask( + $this->trans('commands.generate.plugin.migrate.source.questions.class'), + ucfirst($this->stringConverter->underscoreToCamelCase($module)), + function ($class) { + return $this->validator->validateClassName($class); + } + ); + $input->setOption('class', $class); + } + + $pluginId = $input->getOption('plugin-id'); + if (!$pluginId) { + $pluginId = $io->ask( + $this->trans('commands.generate.plugin.migrate.source.questions.plugin-id'), + $this->stringConverter->camelCaseToUnderscore($class) + ); + $input->setOption('plugin-id', $pluginId); + } + + $table = $input->getOption('table'); + if (!$table) { + $table = $io->ask( + $this->trans('commands.generate.plugin.migrate.source.questions.table'), + '' + ); + $input->setOption('table', $table); + } + + $alias = $input->getOption('alias'); + if (!$alias) { + $alias = $io->ask( + $this->trans('commands.generate.plugin.migrate.source.questions.alias'), + substr($table, 0, 1) + ); + $input->setOption('alias', $alias); + } + + $groupBy = $input->getOption('group-by'); + if ($groupBy == '') { + $groupBy = $io->ask( + $this->trans('commands.generate.plugin.migrate.source.questions.group-by'), + false + ); + $input->setOption('group-by', $groupBy); + } + + $fields = $input->getOption('fields'); + if (!$fields) { + $fields = []; + while (true) { + $id = $io->ask( + $this->trans('commands.generate.plugin.migrate.source.questions.fields.id'), + false + ); + if (!$id) { + break; + } + $description = $io->ask( + $this->trans('commands.generate.plugin.migrate.source.questions.fields.description'), + $id + ); + $fields[] = [ + 'id' => $id, + 'description' => $description, + ]; + } + $input->setOption('fields', $fields); + } + } +} diff --git a/src/Command/Generate/PluginRestResourceCommand.php b/src/Command/Generate/PluginRestResourceCommand.php new file mode 100644 index 000000000..c11e9685d --- /dev/null +++ b/src/Command/Generate/PluginRestResourceCommand.php @@ -0,0 +1,225 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:rest:resource') + ->setDescription($this->trans('commands.generate.plugin.rest.resource.description')) + ->setHelp($this->trans('commands.generate.plugin.rest.resource.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.rest.resource.options.class') + ) + ->addOption( + 'name', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.service.options.name') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.rest.resource.options.plugin-id') + ) + ->addOption( + 'plugin-label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.rest.resource.options.plugin-label') + ) + ->addOption( + 'plugin-url', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.generate.plugin.rest.resource.options.plugin-url') + ) + ->addOption( + 'plugin-states', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.generate.plugin.rest.resource.options.plugin-states') + ) + ->setAliases(['gprr']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $plugin_id = $input->getOption('plugin-id'); + $plugin_label = $input->getOption('plugin-label'); + $plugin_url = $input->getOption('plugin-url'); + $plugin_states = $input->getOption('plugin-states'); + + $this->generator->generate($module, $class_name, $plugin_label, $plugin_id, $plugin_url, $plugin_states); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 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_name = $input->getOption('class'); + if (!$class_name) { + $stringUtils = $this->stringConverter; + $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'), + $this->stringConverter->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->stringConverter->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 = ['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); + } + } +} diff --git a/src/Command/Generate/PluginRulesActionCommand.php b/src/Command/Generate/PluginRulesActionCommand.php new file mode 100644 index 000000000..6a063f2b7 --- /dev/null +++ b/src/Command/Generate/PluginRulesActionCommand.php @@ -0,0 +1,220 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:rulesaction') + ->setDescription($this->trans('commands.generate.plugin.rulesaction.description')) + ->setHelp($this->trans('commands.generate.plugin.rulesaction.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.rulesaction.options.class') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.rulesaction.options.label') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.rulesaction.options.plugin-id') + ) + ->addOption('type', null, InputOption::VALUE_REQUIRED, $this->trans('commands.generate.plugin.rulesaction.options.type')) + ->addOption( + 'category', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.generate.plugin.rulesaction.options.category') + ) + ->addOption( + 'context', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.rulesaction.options.context') + ) + ->setAliases(['gpra']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $label = $input->getOption('label'); + $plugin_id = $input->getOption('plugin-id'); + $type = $input->getOption('type'); + $category = $input->getOption('category'); + $context = $input->getOption('context'); + + $this->generator->generate($module, $class_name, $label, $plugin_id, $category, $context, $type); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 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_name = $input->getOption('class'); + if (!$class_name) { + $class_name = $io->ask( + $this->trans('commands.generate.plugin.rulesaction.options.class'), + 'DefaultAction' + ); + $input->setOption('class', $class_name); + } + + // --label option + $label = $input->getOption('label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.generate.plugin.rulesaction.options.label'), + $this->stringConverter->camelCaseToHuman($class_name) + ); + $input->setOption('label', $label); + } + + // --plugin-id option + $plugin_id = $input->getOption('plugin-id'); + if (!$plugin_id) { + $plugin_id = $io->ask( + $this->trans('commands.generate.plugin.rulesaction.options.plugin-id'), + $this->stringConverter->camelCaseToUnderscore($class_name) + ); + $input->setOption('plugin-id', $plugin_id); + } + + // --type option + $type = $input->getOption('type'); + if (!$type) { + $type = $io->ask( + $this->trans('commands.generate.plugin.rulesaction.options.type'), + 'user' + ); + $input->setOption('type', $type); + } + + // --category option + $category = $input->getOption('category'); + if (!$category) { + $category = $io->ask( + $this->trans('commands.generate.plugin.rulesaction.options.category'), + $this->stringConverter->camelCaseToUnderscore($class_name) + ); + $input->setOption('category', $category); + } + + // --context option + $context = $input->getOption('context'); + if (!$context) { + $context = $io->ask( + $this->trans('commands.generate.plugin.rulesaction.options.context'), + $this->stringConverter->camelCaseToUnderscore($class_name) + ); + $input->setOption('context', $context); + } + } +} diff --git a/src/Command/Generate/PluginSkeletonCommand.php b/src/Command/Generate/PluginSkeletonCommand.php new file mode 100644 index 000000000..f1fb5ee18 --- /dev/null +++ b/src/Command/Generate/PluginSkeletonCommand.php @@ -0,0 +1,384 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->validator = $validator; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected $pluginGeneratorsImplemented = [ + 'block' => 'generate:plugin:block', + 'ckeditor.plugin' => 'generate:plugin:ckeditorbutton', + 'condition' => 'generate:plugin:condition', + 'field.formatter' => 'generate:plugin:fieldformatter', + 'field.field_type' => 'generate:plugin:fieldtype', + 'field.widget' =>'generate:plugin:fieldwidget', + 'image.effect' => 'generate:plugin:imageeffect', + 'mail' => 'generate:plugin:mail' + ]; + + protected function configure() + { + $this + ->setName('generate:plugin:skeleton') + ->setDescription($this->trans('commands.generate.plugin.skeleton.description')) + ->setHelp($this->trans('commands.generate.plugin.skeleton.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'plugin-id', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.options.plugin-id') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.block.options.class') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL| InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + $plugins = $this->getPlugins(); + + // @see use Drupal\Console\Command\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + + $pluginId = $input->getOption('plugin-id'); + $plugin = ucfirst($this->stringConverter->underscoreToCamelCase($pluginId)); + + // Confirm that plugin.manager is available + if (!$this->validator->validatePluginManagerServiceExist($pluginId, $plugins)) { + throw new \Exception( + sprintf( + $this->trans('commands.generate.plugin.skeleton.messages.plugin-dont-exist'), + $pluginId + ) + ); + } + + if (array_key_exists($pluginId, $this->pluginGeneratorsImplemented)) { + $io->warning( + sprintf( + $this->trans('commands.generate.plugin.skeleton.messages.plugin-generator-implemented'), + $pluginId, + $this->pluginGeneratorsImplemented[$pluginId] + ) + ); + } + + $className = $input->getOption('class'); + $services = $input->getOption('services'); + + // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices + $buildServices = $this->buildServices($services); + $pluginMetaData = $this->getPluginMetadata($pluginId); + + $this->generator->generate($module, $pluginId, $plugin, $className, $pluginMetaData, $buildServices); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 0; + } + + 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); + } + } + + protected function getPluginMetadata($pluginId) + { + $pluginMetaData = [ + 'serviceId' => 'plugin.manager.' . $pluginId, + ]; + + // Load service and create reflection + $service = \Drupal::service($pluginMetaData['serviceId']); + + $reflectionClass = new \ReflectionClass($service); + + // Get list of properties with $reflectionClass->getProperties(); + $pluginManagerProperties = [ + 'subdir' => 'subdir', + 'pluginInterface' => 'pluginInterface', + 'pluginDefinitionAnnotationName' => 'pluginAnnotation', + ]; + + foreach ($pluginManagerProperties as $propertyName => $key) { + if (!$reflectionClass->hasProperty($propertyName)) { + $pluginMetaData[$key] = ''; + continue; + } + + $property = $reflectionClass->getProperty($propertyName); + $property->setAccessible(true); + $pluginMetaData[$key] = $property->getValue($service); + } + + if (empty($pluginMetaData['pluginInterface'])) { + $pluginMetaData['pluginInterfaceMethods'] = []; + } else { + $pluginMetaData['pluginInterfaceMethods'] = $this->getClassMethods($pluginMetaData['pluginInterface']); + } + + if (isset($pluginMetaData['pluginAnnotation']) && class_exists($pluginMetaData['pluginAnnotation'])) { + $pluginMetaData['pluginAnnotationProperties'] = $this->getPluginAnnotationProperties($pluginMetaData['pluginAnnotation']); + } else { + $pluginMetaData['pluginAnnotationProperties'] = []; + } + + return $pluginMetaData; + } + + /** + * Get data for the methods of a class. + * + * @param $class + * The fully-qualified name of class. + * + * @return + * An array keyed by method name, where each value is an array containing: + * - 'name: The name of the method. + * - 'declaration': The function declaration line. + * - 'description': The description from the method's docblock first line. + */ + protected function getClassMethods($class) + { + // Get a reflection class. + $classReflection = new \ReflectionClass($class); + $methods = $classReflection->getMethods(); + + $metaData = []; + $methodData = []; + + foreach ($methods as $method) { + $methodData['name'] = $method->getName(); + + $filename = $method->getFileName(); + $source = file($filename); + $startLine = $method->getStartLine(); + + $methodData['declaration'] = substr(trim($source[$startLine - 1]), 0, -1); + + $methodDocComment = explode("\n", $method->getDocComment()); + foreach ($methodDocComment as $line) { + if (substr($line, 0, 5) == ' * ') { + $methodData['description'] = substr($line, 5); + break; + } + } + + $metaData[$method->getName()] = $methodData; + } + + return $metaData; + } + + /** + * Get the list of properties from an annotation class. + * + * @param $pluginAnnotationClass + * The fully-qualified name of the plugin annotation class. + * + * @return + * An array keyed by property name, where each value is an array containing: + * - 'name: The name of the property. + * - 'description': The description from the property's docblock first line. + */ + protected function getPluginAnnotationProperties($pluginAnnotationClass) + { + // Get a reflection class for the annotation class. + // Each property of the annotation class describes a property for the + // plugin annotation. + $annotationReflection = new \ReflectionClass($pluginAnnotationClass); + $propertiesReflection = $annotationReflection->getProperties(\ReflectionProperty::IS_PUBLIC); + + $pluginProperties = []; + $annotationPropertyMetadata = []; + + foreach ($propertiesReflection as $propertyReflection) { + $annotationPropertyMetadata['name'] = $propertyReflection->name; + + $propertyDocblock = $propertyReflection->getDocComment(); + $propertyDocblockLines = explode("\n", $propertyDocblock); + foreach ($propertyDocblockLines as $line) { + if (substr($line, 0, 3) == '/**') { + continue; + } + + // Take the first actual docblock line to be the description. + if (!isset($annotationPropertyMetadata['description']) && substr($line, 0, 5) == ' * ') { + $annotationPropertyMetadata['description'] = substr($line, 5); + } + + // Look for a @var token, to tell us the type of the property. + if (substr($line, 0, 10) == ' * @var ') { + $annotationPropertyMetadata['type'] = substr($line, 10); + } + } + + $pluginProperties[$propertyReflection->name] = $annotationPropertyMetadata; + } + + return $pluginProperties; + } + + protected function getPlugins() + { + $plugins = []; + + foreach ($this->container->getServiceIds() as $serviceId) { + if (strpos($serviceId, 'plugin.manager.') === 0) { + $plugins[] = substr($serviceId, 15); + } + } + + return $plugins; + } +} diff --git a/src/Command/Generate/PluginTypeAnnotationCommand.php b/src/Command/Generate/PluginTypeAnnotationCommand.php new file mode 100644 index 000000000..93bd76d82 --- /dev/null +++ b/src/Command/Generate/PluginTypeAnnotationCommand.php @@ -0,0 +1,153 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:type:annotation') + ->setDescription($this->trans('commands.generate.plugin.type.annotation.description')) + ->setHelp($this->trans('commands.generate.plugin.type.annotation.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.type.annotation.options.class') + ) + ->addOption( + 'machine-name', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.type.annotation.options.plugin-id') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.type.annotation.options.label') + ) + ->setAliases(['gpta']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $machine_name = $input->getOption('machine-name'); + $label = $input->getOption('label'); + + $this->generator->generate($module, $class_name, $machine_name, $label); + } + + 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_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->stringConverter->camelCaseToUnderscore($class_name) + ); + $input->setOption('machine-name', $machine_name); + } + + // --label option + $label = $input->getOption('label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.generate.plugin.type.annotation.options.label'), + $this->stringConverter->camelCaseToHuman($class_name) + ); + $input->setOption('label', $label); + } + } +} diff --git a/src/Command/Generate/PluginTypeYamlCommand.php b/src/Command/Generate/PluginTypeYamlCommand.php new file mode 100644 index 000000000..3674b6ec4 --- /dev/null +++ b/src/Command/Generate/PluginTypeYamlCommand.php @@ -0,0 +1,154 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:type:yaml') + ->setDescription($this->trans('commands.generate.plugin.type.yaml.description')) + ->setHelp($this->trans('commands.generate.plugin.type.yaml.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.type.yaml.options.class') + ) + ->addOption( + 'plugin-name', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.type.yaml.options.plugin-name') + ) + ->addOption( + 'plugin-file-name', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.type.yaml.options.plugin-file-name') + ) + ->setAliases(['gpty']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $plugin_name = $input->getOption('plugin-name'); + $plugin_file_name = $input->getOption('plugin-file-name'); + + $this->generator->generate($module, $class_name, $plugin_name, $plugin_file_name); + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // --module option + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $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->stringConverter->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); + } + } +} diff --git a/src/Command/Generate/PluginViewsFieldCommand.php b/src/Command/Generate/PluginViewsFieldCommand.php new file mode 100644 index 000000000..b91b08ad8 --- /dev/null +++ b/src/Command/Generate/PluginViewsFieldCommand.php @@ -0,0 +1,185 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->site = $site; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:plugin:views:field') + ->setDescription($this->trans('commands.generate.plugin.views.field.description')) + ->setHelp($this->trans('commands.generate.plugin.views.field.help')) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.plugin.views.field.options.class') + ) + ->addOption( + 'title', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.views.field.options.title') + ) + ->addOption( + 'description', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.plugin.views.field.options.description') + ) + ->setAliases(['gpvf']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $class_name = $input->getOption('class'); + $class_machine_name = $this->stringConverter->camelCaseToUnderscore($class_name); + $title = $input->getOption('title'); + $description = $input->getOption('description'); + + $this->generator->generate($module, $class_machine_name, $class_name, $title, $description); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 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_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->stringConverter->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); + } + } + + protected function createGenerator() + { + return new PluginViewsFieldGenerator(); + } +} diff --git a/src/Command/Generate/PostUpdateCommand.php b/src/Command/Generate/PostUpdateCommand.php new file mode 100644 index 000000000..180a70c0d --- /dev/null +++ b/src/Command/Generate/PostUpdateCommand.php @@ -0,0 +1,198 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->site = $site; + $this->validator = $validator; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:post:update') + ->setDescription($this->trans('commands.generate.post:update.description')) + ->setHelp($this->trans('commands.generate.post.update.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'post-update-name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.post.update.options.post-update-name') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $postUpdateName = $input->getOption('post-update-name'); + + $this->validatePostUpdateName($module, $postUpdateName); + + $this->generator->generate($module, $postUpdateName); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 0; + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $this->site->loadLegacyFile('/core/includes/update.inc'); + $this->site->loadLegacyFile('/core/includes/schema.inc'); + + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + $postUpdateName = $input->getOption('post-update-name'); + if (!$postUpdateName) { + $postUpdateName = $io->ask( + $this->trans('commands.generate.post.update.questions.post-update-name'), + '', + function ($postUpdateName) { + return $this->validator->validateSpaces($postUpdateName); + } + ); + + $input->setOption('post-update-name', $postUpdateName); + } + } + + + protected function createGenerator() + { + return new PostUpdateGenerator(); + } + + protected function getLastUpdate($module) + { + $this->site->loadLegacyFile('/core/includes/update.inc'); + $this->site->loadLegacyFile('/core/includes/schema.inc'); + + $updates = update_get_update_list(); + + if (empty($updates[$module]['pending'])) { + $lastUpdateSchema = drupal_get_schema_versions($module); + } else { + $lastUpdateSchema = reset(array_keys($updates[$module]['pending'], max($updates[$module]['pending']))); + } + + return $lastUpdateSchema; + } + + 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 + ) + ); + } + } +} diff --git a/src/Command/Generate/ProfileCommand.php b/src/Command/Generate/ProfileCommand.php new file mode 100644 index 000000000..5dfbe1509 --- /dev/null +++ b/src/Command/Generate/ProfileCommand.php @@ -0,0 +1,270 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->validator = $validator; + $this->appRoot = $appRoot; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:profile') + ->setDescription($this->trans('commands.generate.profile.description')) + ->setHelp($this->trans('commands.generate.profile.help')) + ->addOption( + 'profile', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.profile.options.profile') + ) + ->addOption( + 'machine-name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.profile.options.machine-name') + ) + ->addOption( + 'description', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.profile.options.description') + ) + ->addOption( + 'core', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.profile.options.core') + ) + ->addOption( + 'dependencies', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.profile.options.dependencies'), + '' + ) + ->addOption( + 'themes', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.profile.options.themes'), + '' + ) + ->addOption( + 'distribution', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.profile.options.distribution') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + if (!$this->confirmGeneration($io)) { + return 1; + } + + $profile = $this->validator->validateModuleName($input->getOption('profile')); + $machine_name = $this->validator->validateMachineName($input->getOption('machine-name')); + $description = $input->getOption('description'); + $core = $input->getOption('core'); + $dependencies = $this->validator->validateExtensions($input->getOption('dependencies'), 'module', $io); + $themes = $this->validator->validateExtensions($input->getOption('themes'), 'theme', $io); + $distribution = $input->getOption('distribution'); + $profile_path = $this->appRoot . '/profiles'; + + $this->generator->generate( + $profile, + $machine_name, + $profile_path, + $description, + $core, + $dependencies, + $themes, + $distribution + ); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + //$stringUtils = $this->getStringHelper(); + $validators = $this->validator; + + try { + // A profile is technically also a module, so we can use the same + // validator to check the name. + $profile = $input->getOption('profile') ? $validators->validateModuleName($input->getOption('profile')) : null; + } catch (\Exception $error) { + $io->error($error->getMessage()); + + return 1; + } + + if (!$profile) { + $profile = $io->ask( + $this->trans('commands.generate.profile.questions.profile'), + '', + function ($profile) use ($validators) { + return $validators->validateModuleName($profile); + } + ); + $input->setOption('profile', $profile); + } + + try { + $machine_name = $input->getOption('machine-name') ? $validators->validateModuleName($input->getOption('machine-name')) : null; + } catch (\Exception $error) { + $io->error($error->getMessage()); + + return 1; + } + + if (!$machine_name) { + $machine_name = $io->ask( + $this->trans('commands.generate.profile.questions.machine-name'), + $this->stringConverter->createMachineName($profile), + function ($machine_name) use ($validators) { + return $validators->validateMachineName($machine_name); + } + ); + $input->setOption('machine-name', $machine_name); + } + + $description = $input->getOption('description'); + if (!$description) { + $description = $io->ask( + $this->trans('commands.generate.profile.questions.description'), + 'My Useful Profile' + ); + $input->setOption('description', $description); + } + + $core = $input->getOption('core'); + if (!$core) { + $core = $io->ask( + $this->trans('commands.generate.profile.questions.core'), + '8.x' + ); + $input->setOption('core', $core); + } + + $dependencies = $input->getOption('dependencies'); + if (!$dependencies) { + if ($io->confirm( + $this->trans('commands.generate.profile.questions.dependencies'), + true + ) + ) { + $dependencies = $io->ask( + $this->trans('commands.generate.profile.options.dependencies'), + '' + ); + } + $input->setOption('dependencies', $dependencies); + } + + $distribution = $input->getOption('distribution'); + if (!$distribution) { + if ($io->confirm( + $this->trans('commands.generate.profile.questions.distribution'), + false + ) + ) { + $distribution = $io->ask( + $this->trans('commands.generate.profile.options.distribution'), + 'My Kick-ass Distribution' + ); + $input->setOption('distribution', $distribution); + } + } + } + + /** + * @return ProfileGenerator + */ + protected function createGenerator() + { + return new ProfileGenerator(); + } +} diff --git a/src/Command/Generate/RouteSubscriberCommand.php b/src/Command/Generate/RouteSubscriberCommand.php new file mode 100644 index 000000000..1085ea469 --- /dev/null +++ b/src/Command/Generate/RouteSubscriberCommand.php @@ -0,0 +1,158 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:routesubscriber') + ->setDescription($this->trans('commands.generate.routesubscriber.description')) + ->setHelp($this->trans('commands.generate.routesubscriber.description')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.routesubscriber.options.name') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.routesubscriber.options.class') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $output = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($output)) { + return 1; + } + + $module = $input->getOption('module'); + $name = $input->getOption('name'); + $class = $input->getOption('class'); + + $this->generator->generate($module, $name, $class); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); + + return 0; + } + + /** + * {@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); + } + + // --name option + $name = $input->getOption('name'); + if (!$name) { + $name = $io->ask( + $this->trans('commands.generate.routesubscriber.questions.name'), + $module.'.route_subscriber' + ); + $input->setOption('name', $name); + } + + // --class option + $class = $input->getOption('class'); + if (!$class) { + $class = $io->ask( + $this->trans('commands.generate.routesubscriber.questions.class'), + 'RouteSubscriber' + ); + $input->setOption('class', $class); + } + } + + protected function createGenerator() + { + return new RouteSubscriberGenerator(); + } +} diff --git a/src/Command/Generate/ServiceCommand.php b/src/Command/Generate/ServiceCommand.php new file mode 100644 index 000000000..859bcfe1b --- /dev/null +++ b/src/Command/Generate/ServiceCommand.php @@ -0,0 +1,244 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:service') + ->setDescription($this->trans('commands.generate.service.description')) + ->setHelp($this->trans('commands.generate.service.description')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.service.options.name') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.service.options.class') + ) + ->addOption( + 'interface', + null, + InputOption::VALUE_NONE, + $this->trans('commands.common.service.options.interface') + ) + ->addOption( + 'interface-name', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.common.service.options.interface-name') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ) + ->addOption( + 'path-service', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.service.options.path') + ) + ->setAliases(['gs']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $name = $input->getOption('name'); + $class = $input->getOption('class'); + $interface = $input->getOption('interface'); + $interface_name = $input->getOption('interface-name'); + $services = $input->getOption('services'); + $path_service = $input->getOption('path-service'); + + $available_services = $this->container->getServiceIds(); + + if (in_array($name, array_values($available_services))) { + throw new \Exception( + sprintf( + $this->trans('commands.generate.service.messages.service-already-taken'), + $module + ) + ); + } + + // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices + $build_services = $this->buildServices($services); + $this->generator->generate($module, $name, $class, $interface, $interface_name, $build_services, $path_service); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); + + return 0; + } + + /** + * {@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); + } + + //--name option + $name = $input->getOption('name'); + if (!$name) { + $name = $io->ask( + $this->trans('commands.generate.service.questions.service-name'), + $module.'.default' + ); + $input->setOption('name', $name); + } + + // --class option + $class = $input->getOption('class'); + if (!$class) { + $class = $io->ask( + $this->trans('commands.generate.service.questions.class'), + 'DefaultService' + ); + $input->setOption('class', $class); + } + + // --interface option + $interface = $input->getOption('interface'); + if (!$interface) { + $interface = $io->confirm( + $this->trans('commands.generate.service.questions.interface'), + true + ); + $input->setOption('interface', $interface); + } + + // --interface_name option + $interface_name = $input->getOption('interface-name'); + if ($interface && !$interface_name) { + $interface_name = $io->askEmpty( + $this->trans('commands.generate.service.questions.interface-name') + ); + $input->setOption('interface-name', $interface_name); + } + + // --services option + $services = $input->getOption('services'); + if (!$services) { + // @see Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion + $services = $this->servicesQuestion($io); + $input->setOption('services', $services); + } + + // --path_service option + $path_service = $input->getOption('path-service'); + if (!$path_service) { + $path_service = $io->ask( + $this->trans('commands.generate.service.questions.path'), + '/modules/custom/' . $module . '/src/' + ); + $input->setOption('path-service', $path_service); + } + } +} diff --git a/src/Command/Generate/ThemeCommand.php b/src/Command/Generate/ThemeCommand.php new file mode 100644 index 000000000..8c598baf2 --- /dev/null +++ b/src/Command/Generate/ThemeCommand.php @@ -0,0 +1,383 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->validator = $validator; + $this->appRoot = $appRoot; + $this->themeHandler = $themeHandler; + $this->site = $site; + $this->stringConverter = $stringConverter; + parent::__construct(); + } + + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:theme') + ->setDescription($this->trans('commands.generate.theme.description')) + ->setHelp($this->trans('commands.generate.theme.help')) + ->addOption( + 'theme', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.theme.options.module') + ) + ->addOption( + 'machine-name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.theme.options.machine-name') + ) + ->addOption( + 'theme-path', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.theme.options.module-path') + ) + ->addOption( + 'description', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.theme.options.description') + ) + ->addOption('core', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.theme.options.core')) + ->addOption( + 'package', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.theme.options.package') + ) + ->addOption( + 'global-library', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.theme.options.global-library') + ) + ->addOption( + 'libraries', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.theme.options.libraries') + ) + ->addOption( + 'base-theme', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.theme.options.base-theme') + ) + ->addOption( + 'regions', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.theme.options.regions') + ) + ->addOption( + 'breakpoints', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.theme.options.breakpoints') + ) + ->setAliases(['gt']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $theme = $this->validator->validateModuleName($input->getOption('theme')); + $theme_path = $this->appRoot . $input->getOption('theme-path'); + $theme_path = $this->validator->validateModulePath($theme_path, true); + + $machine_name = $this->validator->validateMachineName($input->getOption('machine-name')); + $description = $input->getOption('description'); + $core = $input->getOption('core'); + $package = $input->getOption('package'); + $base_theme = $input->getOption('base-theme'); + $global_library = $input->getOption('global-library'); + $libraries = $input->getOption('libraries'); + $regions = $input->getOption('regions'); + $breakpoints = $input->getOption('breakpoints'); + + $this->generator->generate( + $theme, + $machine_name, + $theme_path, + $description, + $core, + $package, + $base_theme, + $global_library, + $libraries, + $regions, + $breakpoints + ); + + return 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 1; + } + + 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 1; + } + + if (!$machine_name) { + $machine_name = $io->ask( + $this->trans('commands.generate.theme.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); + } + + + // --libraries option. + $libraries = $input->getOption('libraries'); + if (!$libraries) { + if ($io->confirm( + $this->trans('commands.generate.theme.questions.library-add'), + true + ) + ) { + // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::libraryQuestion + $libraries = $this->libraryQuestion($io); + $input->setOption('libraries', $libraries); + } + } + + // --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); + } + } + } +} diff --git a/src/Command/Generate/TwigExtensionCommand.php b/src/Command/Generate/TwigExtensionCommand.php new file mode 100644 index 000000000..182f408b8 --- /dev/null +++ b/src/Command/Generate/TwigExtensionCommand.php @@ -0,0 +1,192 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->site = $site; + $this->stringConverter = $stringConverter; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('generate:twig:extension') + ->setDescription($this->trans('commands.generate.twig.extension.description')) + ->setHelp($this->trans('commands.generate.twig.extension.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.twig.extension.options.name') + ) + ->addOption( + 'class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.class') + ) + ->addOption( + 'services', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.common.options.services') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $name = $input->getOption('name'); + $class = $input->getOption('class'); + $services = $input->getOption('services'); + // Add renderer service as first parameter. + array_unshift($services, 'renderer'); + + // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices + $build_services = $this->buildServices($services); + + $this->generator->generate($module, $name, $class, $build_services); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); + + return 0; + } + + /** + * {@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); + } + + // --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($io); + $input->setOption('services', $services); + } + } +} diff --git a/src/Command/Generate/UpdateCommand.php b/src/Command/Generate/UpdateCommand.php new file mode 100644 index 000000000..923970a7e --- /dev/null +++ b/src/Command/Generate/UpdateCommand.php @@ -0,0 +1,199 @@ +extensionManager = $extensionManager; + $this->generator = $generator; + $this->site = $site; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('generate:update') + ->setDescription($this->trans('commands.generate.update.description')) + ->setHelp($this->trans('commands.generate.update.help')) + ->addOption( + 'module', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addOption( + 'update-n', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.generate.update.options.update-n') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration + if (!$this->confirmGeneration($io)) { + return 1; + } + + $module = $input->getOption('module'); + $updateNumber = $input->getOption('update-n'); + + $lastUpdateSchema = $this->getLastUpdate($module); + + if ($updateNumber <= $lastUpdateSchema) { + throw new \InvalidArgumentException( + sprintf( + $this->trans('commands.generate.update.messages.wrong-update-n'), + $updateNumber + ) + ); + } + + $this->generator->generate($module, $updateNumber); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); + + return 0; + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $this->site->loadLegacyFile('/core/includes/update.inc'); + $this->site->loadLegacyFile('/core/includes/schema.inc'); + + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + $lastUpdateSchema = $this->getLastUpdate($module); + $nextUpdateSchema = $lastUpdateSchema ? ($lastUpdateSchema + 1): 8001; + + $updateNumber = $input->getOption('update-n'); + if (!$updateNumber) { + $updateNumber = $io->ask( + $this->trans('commands.generate.update.questions.update-n'), + $nextUpdateSchema, + function ($updateNumber) use ($lastUpdateSchema) { + if (!is_numeric($updateNumber)) { + throw new \InvalidArgumentException( + sprintf( + $this->trans('commands.generate.update.messages.wrong-update-n'), + $updateNumber + ) + ); + } else { + if ($updateNumber <= $lastUpdateSchema) { + throw new \InvalidArgumentException( + sprintf( + $this->trans('commands.generate.update.messages.wrong-update-n'), + $updateNumber + ) + ); + } + return $updateNumber; + } + } + ); + + $input->setOption('update-n', $updateNumber); + } + } + + + protected function createGenerator() + { + return new UpdateGenerator(); + } + + protected function getLastUpdate($module) + { + $this->site->loadLegacyFile('/core/includes/update.inc'); + $this->site->loadLegacyFile('/core/includes/schema.inc'); + + $updates = update_get_update_list(); + + if (empty($updates[$module]['pending'])) { + $lastUpdateSchema = drupal_get_schema_versions($module); + $lastUpdateSchema = $lastUpdateSchema[0]; + } else { + $lastUpdateSchema = reset(array_keys($updates[$module]['pending'], max($updates[$module]['pending']))); + } + + return $lastUpdateSchema; + } +} diff --git a/src/Generator/AuthenticationProviderGenerator.php b/src/Generator/AuthenticationProviderGenerator.php new file mode 100644 index 000000000..4fd53df28 --- /dev/null +++ b/src/Generator/AuthenticationProviderGenerator.php @@ -0,0 +1,75 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Block. + * + * @param $module + * @param $class + * @param $provider_id + */ + public function generate($module, $class, $provider_id) + { + $parameters = [ + 'module' => $module, + 'class' => $class, + ]; + + $this->renderFile( + 'module/src/Authentication/Provider/authentication-provider.php.twig', + $this->extensionManager->getModule($module)->getAuthenticationPath('Provider'). '/' . $class . '.php', + $parameters + ); + + $parameters = [ + 'module' => $module, + 'class' => $class, + 'class_path' => sprintf('Drupal\%s\Authentication\Provider\%s', $module, $class), + 'name' => 'authentication.'.$module, + 'services' => [ + ['name' => 'config.factory'], + ['name' => 'entity_type.manager'], + ], + 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), + 'tags' => [ + 'name' => 'authentication_provider', + 'provider_id' => $provider_id, + 'priority' => '100', + ], + ]; + + $this->renderFile( + 'module/services.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/BreakPointGenerator.php b/src/Generator/BreakPointGenerator.php new file mode 100644 index 000000000..7e91e0e35 --- /dev/null +++ b/src/Generator/BreakPointGenerator.php @@ -0,0 +1,61 @@ +extensionManager = $extensionManager; + } + + + /** + * Generator BreakPoint. + * + * @param $theme + * @param $breakpoints + * @param $machine_name + */ + public function generate($theme, $breakpoints, $machine_name) + { + $parameters = [ + 'theme' => $theme, + 'breakpoints' => $breakpoints, + 'machine_name' => $machine_name + ]; + + $theme_path = $this->extensionManager->getTheme($theme)->getPath(); + + $this->renderFile( + 'theme/breakpoints.yml.twig', + $theme_path .'/'.$machine_name.'.breakpoints.yml', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/CacheContextGenerator.php b/src/Generator/CacheContextGenerator.php new file mode 100644 index 000000000..da87ee974 --- /dev/null +++ b/src/Generator/CacheContextGenerator.php @@ -0,0 +1,64 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Service. + * + * @param string $module Module name + * @param string $cache_context Cache context name + * @param string $class Class name + * @param array $services List of services + */ + public function generate($module, $cache_context, $class, $services) + { + $parameters = [ + 'module' => $module, + 'name' => 'cache_context.' . $cache_context, + 'class' => $class, + 'services' => $services, + 'class_path' => sprintf('Drupal\%s\CacheContext\%s', $module, $class), + 'tags' => ['name' => 'cache.context'], + 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), + ]; + + $this->renderFile( + 'module/src/cache-context.php.twig', + $this->extensionManager->getModule($module)->getSourcePath().'/CacheContext/'.$class.'.php', + $parameters + ); + + $this->renderFile( + 'module/services.yml.twig', + $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/CommandGenerator.php b/src/Generator/CommandGenerator.php new file mode 100644 index 000000000..ff01bd572 --- /dev/null +++ b/src/Generator/CommandGenerator.php @@ -0,0 +1,94 @@ +extensionManager = $extensionManager; + $this->translatorManager = $translatorManager; + } + + /** + * Generate. + * + * @param string $extension Extension name + * @param string $extensionType Extension type + * @param string $name Command name + * @param string $class Class name + * @param boolean $containerAware Container Aware command + * @param array $services Services array + */ + public function generate($extension, $extensionType, $name, $class, $containerAware, $services) + { + $command_key = str_replace(':', '.', $name); + + $extensionObject = $this->extensionManager->getDrupalExtension($extensionType, $extension); + + $parameters = [ + 'extension' => $extension, + 'extensionType' => $extensionType, + 'name' => $name, + 'class_name' => $class, + 'container_aware' => $containerAware, + 'command_key' => $command_key, + 'services' => $services, + 'tags' => ['name' => 'drupal.command'], + 'class_path' => sprintf('Drupal\%s\Command\%s', $extension, $class), + 'file_exists' => file_exists($extensionObject->getPath().'/console.services.yml'), + ]; + + $this->renderFile( + 'module/src/Command/command.php.twig', + $extensionObject->getCommandDirectory().$class.'.php', + $parameters + ); + + $parameters['name'] = $extension.'.'.str_replace(':', '_', $name); + + $this->renderFile( + 'module/services.yml.twig', + $extensionObject->getPath() .'/console.services.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/src/Command/console/translations/en/command.yml.twig', + $extensionObject->getPath().'/console/translations/en/'.$command_key.'.yml' + ); + } +} diff --git a/src/Generator/ControllerGenerator.php b/src/Generator/ControllerGenerator.php new file mode 100644 index 000000000..bb95974d8 --- /dev/null +++ b/src/Generator/ControllerGenerator.php @@ -0,0 +1,62 @@ +extensionManager = $extensionManager; + } + + public function generate($module, $class, $routes, $test, $services) + { + $parameters = [ + 'class_name' => $class, + 'services' => $services, + 'module' => $module, + 'routes' => $routes, + //'learning' => $this->isLearning(), + ]; + + $this->renderFile( + 'module/src/Controller/controller.php.twig', + $this->extensionManager->getModule($module)->getControllerPath().'/'.$class.'.php', + $parameters + ); + + $this->renderFile( + 'module/routing-controller.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.routing.yml', + $parameters, + FILE_APPEND + ); + + if ($test) { + $this->renderFile( + 'module/Tests/Controller/controller.php.twig', + $this->extensionManager->getModule($module)->getTestPath('Controller').'/'.$class.'Test.php', + $parameters + ); + } + } +} diff --git a/src/Generator/EntityBundleGenerator.php b/src/Generator/EntityBundleGenerator.php new file mode 100644 index 000000000..18e6ac6c5 --- /dev/null +++ b/src/Generator/EntityBundleGenerator.php @@ -0,0 +1,86 @@ +extensionManager = $extensionManager; + } + + public function generate($module, $bundleName, $bundleTitle) + { + $parameters = [ + 'module' => $module, + 'bundle_name' => $bundleName, + 'bundle_title' => $bundleTitle, + //TODO: + //'learning' => $this->isLearning(), + ]; + + /** + * Generate core.entity_form_display.node.{ bundle_name }.default.yml + */ + $this->renderFile( + 'module/src/Entity/Bundle/core.entity_form_display.node.default.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/config/install/core.entity_form_display.node.' . $bundleName . '.default.yml', + $parameters + ); + + /** + * Generate core.entity_view_display.node.{ bundle_name }.default.yml + */ + $this->renderFile( + 'module/src/Entity/Bundle/core.entity_view_display.node.default.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/config/install/core.entity_view_display.node.' . $bundleName . '.default.yml', + $parameters + ); + + /** + * Generate core.entity_view_display.node.{ bundle_name }.teaser.yml + */ + $this->renderFile( + 'module/src/Entity/Bundle/core.entity_view_display.node.teaser.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/config/install/core.entity_view_display.node.' . $bundleName . '.teaser.yml', + $parameters + ); + + /** + * Generate field.field.node.{ bundle_name }.body.yml + */ + $this->renderFile( + 'module/src/Entity/Bundle/field.field.node.body.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/config/install/field.field.node.' . $bundleName . '.body.yml', + $parameters + ); + + /** + * Generate node.type.{ bundle_name }.yml + */ + $this->renderFile( + 'module/src/Entity/Bundle/node.type.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/config/install/node.type.' . $bundleName . '.yml', + $parameters + ); + } +} diff --git a/src/Generator/EntityConfigGenerator.php b/src/Generator/EntityConfigGenerator.php new file mode 100644 index 000000000..3a4f752b2 --- /dev/null +++ b/src/Generator/EntityConfigGenerator.php @@ -0,0 +1,109 @@ +extensionManager = $extensionManager; + } + + + /** + * Generator Entity. + * + * @param string $module Module name + * @param string $entity_name Entity machine name + * @param string $entity_class Entity class name + * @param string $label Entity label + * @param string $base_path Base path + * @param string $bundle_of Entity machine name of the content entity this config entity acts as a bundle for. + */ + public function generate($module, $entity_name, $entity_class, $label, $base_path, $bundle_of = null) + { + $parameters = [ + 'module' => $module, + 'entity_name' => $entity_name, + 'entity_class' => $entity_class, + 'label' => $label, + 'bundle_of' => $bundle_of, + 'base_path' => $base_path, + ]; + + $this->renderFile( + 'module/config/schema/entity.schema.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/config/schema/'.$entity_name.'.schema.yml', + $parameters + ); + + $this->renderFile( + 'module/links.menu-entity-config.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.menu.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/links.action-entity.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.action.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/src/Entity/interface-entity.php.twig', + $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'Interface.php', + $parameters + ); + + $this->renderFile( + 'module/src/Entity/entity.php.twig', + $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'.php', + $parameters + ); + + $this->renderFile( + 'module/src/entity-route-provider.php.twig', + $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'HtmlRouteProvider.php', + $parameters + ); + + $this->renderFile( + 'module/src/Form/entity.php.twig', + $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'Form.php', + $parameters + ); + + $this->renderFile( + 'module/src/Form/entity-delete.php.twig', + $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'DeleteForm.php', + $parameters + ); + + $this->renderFile( + 'module/src/entity-listbuilder.php.twig', + $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'ListBuilder.php', + $parameters + ); + } +} diff --git a/src/Generator/EntityContentGenerator.php b/src/Generator/EntityContentGenerator.php new file mode 100644 index 000000000..3c9f98cce --- /dev/null +++ b/src/Generator/EntityContentGenerator.php @@ -0,0 +1,291 @@ +extensionManager = $extensionManager; + $this->site = $site; + $this->twigrenderer = $twigrenderer; + } + + public function setIo($io) + { + $this->io = $io; + } + + + /** + * Generator Entity. + * + * @param string $module Module name + * @param string $entity_name Entity machine name + * @param string $entity_class Entity class name + * @param string $label Entity label + * @param string $base_path Base path + * @param string $is_translatable Translation configuration + * @param string $bundle_entity_type (Config) entity type acting as bundle + * @param bool $revisionable Revision configuration + */ + public function generate($module, $entity_name, $entity_class, $label, $base_path, $is_translatable, $bundle_entity_type = null, $revisionable = false) + { + $parameters = [ + 'module' => $module, + 'entity_name' => $entity_name, + 'entity_class' => $entity_class, + 'label' => $label, + 'bundle_entity_type' => $bundle_entity_type, + 'base_path' => $base_path, + 'is_translatable' => $is_translatable, + 'revisionable' => $revisionable, + ]; + + $this->renderFile( + 'module/permissions-entity-content.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.permissions.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/links.menu-entity-content.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.menu.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/links.task-entity-content.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.task.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/links.action-entity-content.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.action.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/src/accesscontrolhandler-entity-content.php.twig', + $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'AccessControlHandler.php', + $parameters + ); + + if ($is_translatable) { + $this->renderFile( + 'module/src/entity-translation-handler.php.twig', + $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'TranslationHandler.php', + $parameters + ); + } + + $this->renderFile( + 'module/src/Entity/interface-entity-content.php.twig', + $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'Interface.php', + $parameters + ); + + $this->renderFile( + 'module/src/Entity/entity-content.php.twig', + $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'.php', + $parameters + ); + + $this->renderFile( + 'module/src/entity-content-route-provider.php.twig', + $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'HtmlRouteProvider.php', + $parameters + ); + + $this->renderFile( + 'module/src/Entity/entity-content-views-data.php.twig', + $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'ViewsData.php', + $parameters + ); + + $this->renderFile( + 'module/src/listbuilder-entity-content.php.twig', + $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'ListBuilder.php', + $parameters + ); + + $this->renderFile( + 'module/src/Entity/Form/entity-settings.php.twig', + $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'SettingsForm.php', + $parameters + ); + + $this->renderFile( + 'module/src/Entity/Form/entity-content.php.twig', + $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'Form.php', + $parameters + ); + + $this->renderFile( + 'module/src/Entity/Form/entity-content-delete.php.twig', + $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'DeleteForm.php', + $parameters + ); + + $this->renderFile( + 'module/entity-content-page.php.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$entity_name.'.page.inc', + $parameters + ); + + $this->renderFile( + 'module/templates/entity-html.twig', + $this->extensionManager->getModule($module)->getTemplatePath().'/'.$entity_name.'.html.twig', + $parameters + ); + + if ($revisionable) { + $this->renderFile( + 'module/src/Entity/Form/entity-content-revision-delete.php.twig', + $this->extensionManager->getModule($module)->getFormPath() .'/'.$entity_class.'RevisionDeleteForm.php', + $parameters + ); + $this->renderFile( + 'module/src/Entity/Form/entity-content-revision-revert-translation.php.twig', + $this->extensionManager->getModule($module)->getFormPath() .'/'.$entity_class.'RevisionRevertTranslationForm.php', + $parameters + ); + $this->renderFile( + 'module/src/Entity/Form/entity-content-revision-revert.php.twig', + $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'RevisionRevertForm.php', + $parameters + ); + $this->renderFile( + 'module/src/entity-storage.php.twig', + $this->extensionManager->getModule($module)->getSourcePath() .'/'.$entity_class.'Storage.php', + $parameters + ); + $this->renderFile( + 'module/src/interface-entity-storage.php.twig', + $this->extensionManager->getModule($module)->getSourcePath() .'/'.$entity_class.'StorageInterface.php', + $parameters + ); + $this->renderFile( + 'module/src/Controller/entity-controller.php.twig', + $this->extensionManager->getModule($module)->getControllerPath() .'/'.$entity_class.'Controller.php', + $parameters + ); + } + + if ($bundle_entity_type) { + $this->renderFile( + 'module/templates/entity-with-bundle-content-add-list-html.twig', + $this->extensionManager->getModule($module)->getTemplatePath().'/'.str_replace('_', '-', $entity_name).'-content-add-list.html.twig', + $parameters + ); + + // Check for hook_theme() in module file and warn ... + $module_filename = $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module'; + // Check if the module file exists. + if (!file_exists($module_filename)) { + $this->renderFile( + 'module/module.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module . '.module', + [ + 'machine_name' => $module, + 'description' => '', + ] + ); + } + $module_file_contents = file_get_contents($module_filename); + if (strpos($module_file_contents, 'function ' . $module . '_theme') !== false) { + $this->io->warning( + [ + "It looks like you have a hook_theme already declared", + "Please manually merge the two hook_theme() implementations in", + $module_filename + ] + ); + } + + $this->renderFile( + 'module/src/Entity/entity-content-with-bundle.theme.php.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module', + $parameters, + FILE_APPEND + ); + + if (strpos($module_file_contents, 'function ' . $module . '_theme_suggestions_' . $entity_name) !== false) { + $this->io->warning( + [ + "It looks like you have a hook_theme_suggestions_HOOK already declared", + "Please manually merge the two hook_theme_suggestions_HOOK() implementations in", + $module_filename + ] + ); + } + + $this->renderFile( + 'module/src/Entity/entity-content-with-bundle.theme_hook_suggestions.php.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module', + $parameters, + FILE_APPEND + ); + } + + $content = $this->twigrenderer->render( + 'module/src/Entity/entity-content.theme.php.twig', + $parameters + ); + + + //@TODO: + /** + if ($this->isLearning()) { + $this->io->commentBlock( + [ + 'Add this to your hook_theme:', + $content + ] + ); + } + */ + } +} diff --git a/src/Generator/EventSubscriberGenerator.php b/src/Generator/EventSubscriberGenerator.php new file mode 100644 index 000000000..f53178be2 --- /dev/null +++ b/src/Generator/EventSubscriberGenerator.php @@ -0,0 +1,66 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Service. + * + * @param string $module Module name + * @param string $name Service name + * @param string $class Class name + * @param string $events + * @param array $services List of services + */ + public function generate($module, $name, $class, $events, $services) + { + $parameters = [ + 'module' => $module, + 'name' => $name, + 'class' => $class, + 'class_path' => sprintf('Drupal\%s\EventSubscriber\%s', $module, $class), + 'events' => $events, + 'services' => $services, + 'tags' => ['name' => 'event_subscriber'], + 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), + ]; + + $this->renderFile( + 'module/src/event-subscriber.php.twig', + $this->extensionManager->getModule($module)->getSourcePath().'/EventSubscriber/'.$class.'.php', + $parameters + ); + + $this->renderFile( + 'module/services.yml.twig', + $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/FormAlterGenerator.php b/src/Generator/FormAlterGenerator.php new file mode 100644 index 000000000..19fba6d82 --- /dev/null +++ b/src/Generator/FormAlterGenerator.php @@ -0,0 +1,57 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Block. + * + * @param $module + * @param $form_id + * @param $inputs + * @param $metadata + */ + public function generate($module, $form_id, $inputs, $metadata) + { + $parameters = [ + 'module' => $module, + 'form_id' => $form_id, + 'inputs' => $inputs, + 'metadata' => $metadata + ]; + + $module_path = $this->extensionManager->getModule($module)->getPath(); + + $this->renderFile( + 'module/src/Form/form-alter.php.twig', + $module_path .'/'.$module.'.module', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/FormGenerator.php b/src/Generator/FormGenerator.php new file mode 100644 index 000000000..d19897480 --- /dev/null +++ b/src/Generator/FormGenerator.php @@ -0,0 +1,114 @@ +extensionManager = $extensionManager; + $this->stringConverter = $stringConverter; + } + + /** + * @param $module + * @param $class_name + * @param $services + * @param $config_file + * @param $inputs + * @param $form_id + * @param $form_type + * @param $path + * @param $menu_link_gen + * @param $menu_link_title + * @param $menu_parent + * @param $menu_link_desc + */ + public function generate($module, $class_name, $form_id, $form_type, $services, $config_file, $inputs, $path, $menu_link_gen, $menu_link_title, $menu_parent, $menu_link_desc) + { + $class_name_short = strtolower( + $this->stringConverter->removeSuffix($class_name) + ); + + $parameters = [ + 'class_name' => $class_name, + 'services' => $services, + 'config_file' => $config_file, + 'inputs' => $inputs, + 'module_name' => $module, + 'form_id' => $form_id, + 'path' => $path, + 'route_name' => $class_name, + 'menu_link_title' => $menu_link_title, + 'menu_parent' => $menu_parent, + 'menu_link_desc' => $menu_link_desc, + 'class_name_short' => $class_name_short + ]; + + if ($form_type == 'ConfigFormBase') { + $template = 'module/src/Form/form-config.php.twig'; + $parameters['config_form'] = true; + } else { + $template = 'module/src/Form/form.php.twig'; + $parameters['config_form'] = false; + } + + $this->renderFile( + 'module/routing-form.yml.twig', + $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.routing.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + $template, + $this->extensionManager->getModule($module)->getFormPath() .'/'.$class_name.'.php', + $parameters + ); + + // Render defaults YML file. + if ($config_file == true) { + $this->renderFile( + 'module/config/install/field.default.yml.twig', + $this->extensionManager->getModule($module)->getPath() .'/config/install/'.$module.'.'.$class_name_short.'.yml', + $parameters + ); + } + + if ($menu_link_gen == true) { + $this->renderFile( + 'module/links.menu.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.links.menu.yml', + $parameters, + FILE_APPEND + ); + } + } +} diff --git a/src/Generator/HelpGenerator.php b/src/Generator/HelpGenerator.php new file mode 100644 index 000000000..420240c19 --- /dev/null +++ b/src/Generator/HelpGenerator.php @@ -0,0 +1,54 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Post Update Name function. + * + * @param $module + * @param $description + */ + public function generate($module, $description) + { + $module_path = $this->extensionManager->getModule($module)->getPath(); + + $parameters = [ + 'machine_name' => $module, + 'description' => $description, + 'file_exists' => file_exists($module_path .'/'.$module.'.module'), + ]; + + $this->renderFile( + 'module/help.php.twig', + $module_path .'/'.$module.'.module', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/ModuleFileGenerator.php b/src/Generator/ModuleFileGenerator.php new file mode 100644 index 000000000..8f8e84e47 --- /dev/null +++ b/src/Generator/ModuleFileGenerator.php @@ -0,0 +1,53 @@ + $machine_name, + 'file_path' => $file_path , + ]; + + if ($machine_name) { + $this->renderFile( + 'module/module-file.twig', + $file_path . '/' . $machine_name . '.module', + $parameters + ); + } + } +} diff --git a/src/Generator/ModuleGenerator.php b/src/Generator/ModuleGenerator.php new file mode 100644 index 000000000..f7c2ed0a7 --- /dev/null +++ b/src/Generator/ModuleGenerator.php @@ -0,0 +1,188 @@ + $module, + 'machine_name' => $machineName, + 'type' => 'module', + 'core' => $core, + 'description' => $description, + 'package' => $package, + 'dependencies' => $dependencies, + 'test' => $test, + 'twigtemplate' => $twigtemplate, + ]; + + $this->renderFile( + 'module/info.yml.twig', + $dir.'/'.$machineName.'.info.yml', + $parameters + ); + + if (!empty($featuresBundle)) { + $this->renderFile( + 'module/features.yml.twig', + $dir.'/'.$machineName.'.features.yml', + [ + 'bundle' => $featuresBundle, + ] + ); + } + + if ($moduleFile) { + // Generate '.module' file. + $this->createModuleFile($dir, $parameters); + } + + if ($composer) { + $this->renderFile( + 'module/composer.json.twig', + $dir.'/'.'composer.json', + $parameters + ); + } + + if ($test) { + $this->renderFile( + 'module/src/Tests/load-test.php.twig', + $dir . '/tests/src/Functional/' . 'LoadTest.php', + $parameters + ); + } + if ($twigtemplate) { + // If module file is not created earlier, create now. + if (!$moduleFile) { + // Generate '.module' file. + $this->createModuleFile($dir, $parameters); + } + $this->renderFile( + 'module/module-twig-template-append.twig', + $dir .'/' . $machineName . '.module', + $parameters, + FILE_APPEND + ); + $dir .= '/templates/'; + if (file_exists($dir)) { + if (!is_dir($dir)) { + throw new \RuntimeException( + sprintf( + 'Unable to generate the templates directory as the target directory "%s" exists but is a file.', + realpath($dir) + ) + ); + } + $files = scandir($dir); + if ($files != ['.', '..']) { + throw new \RuntimeException( + sprintf( + 'Unable to generate the templates directory as the target directory "%s" is not empty.', + realpath($dir) + ) + ); + } + if (!is_writable($dir)) { + throw new \RuntimeException( + sprintf( + 'Unable to generate the templates directory as the target directory "%s" is not writable.', + realpath($dir) + ) + ); + } + } + $this->renderFile( + 'module/twig-template-file.twig', + $dir . str_replace("_", "-", $machineName) . '.html.twig', + $parameters + ); + } + } + + /** + * Generate the '.module' file. + * + * @param string $dir + * The directory name. + * @param array $parameters + * The parameter array. + */ + protected function createModuleFile($dir, $parameters) + { + $this->renderFile( + 'module/module.twig', + $dir . '/' . $parameters['machine_name'] . '.module', + $parameters + ); + } +} diff --git a/src/Generator/PermissionGenerator.php b/src/Generator/PermissionGenerator.php new file mode 100644 index 000000000..643b1f4ba --- /dev/null +++ b/src/Generator/PermissionGenerator.php @@ -0,0 +1,60 @@ +extensionManager = $extensionManager; + } + + /** + * @param $module + * @param $permissions + * @param $learning + */ + public function generate($module, $permissions, $learning) + { + $parameters = [ + 'module_name' => $module, + 'permissions' => $permissions, + ]; + + $this->renderFile( + 'module/permission.yml.twig', + $this->extensionManager->getModule($module)->getPath().'/'.$module.'.permissions.yml', + $parameters, + FILE_APPEND + ); + + $content = $this->renderer->render( + 'module/permission-routing.yml.twig', + $parameters + ); + + if ($learning) { + echo 'You can use this permission in the routing file like this:'.PHP_EOL; + echo $content; + } + } +} diff --git a/src/Generator/PluginBlockGenerator.php b/src/Generator/PluginBlockGenerator.php new file mode 100644 index 000000000..3755ae193 --- /dev/null +++ b/src/Generator/PluginBlockGenerator.php @@ -0,0 +1,89 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Block. + * + * @param $module + * @param $class_name + * @param $label + * @param $plugin_id + * @param $services + */ + public function generate($module, $class_name, $label, $plugin_id, $services, $inputs) + { + // Consider the type when determining a default value. Figure out what + // the code looks like for the default value tht we need to generate. + foreach ($inputs as &$input) { + $default_code = '$this->t(\'\')'; + if ($input['default_value'] == '') { + switch ($input['type']) { + case 'checkbox': + case 'number': + case 'weight': + case 'radio': + $default_code = 0; + break; + + case 'radios': + case 'checkboxes': + $default_code = 'array()'; + break; + } + } elseif (substr($input['default_value'], 0, 1) == '$') { + // If they want to put in code, let them, they're programmers. + $default_code = $input['default_value']; + } elseif (is_numeric($input['default_value'])) { + $default_code = $input['default_value']; + } elseif (preg_match('/^(true|false)$/i', $input['default_value'])) { + // Coding Standards + $default_code = strtoupper($input['default_value']); + } else { + $default_code = '$this->t(\'' . $input['default_value'] . '\')'; + } + $input['default_code'] = $default_code; + } + + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'services' => $services, + 'inputs' => $inputs, + ]; + + $this->renderFile( + 'module/src/Plugin/Block/block.php.twig', + $this->extensionManager->getPluginPath($module, 'Block').'/'.$class_name.'.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginCKEditorButtonGenerator.php b/src/Generator/PluginCKEditorButtonGenerator.php new file mode 100644 index 000000000..bcbef106b --- /dev/null +++ b/src/Generator/PluginCKEditorButtonGenerator.php @@ -0,0 +1,57 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin CKEditor Button. + * + * @param string $module Module name + * @param string $class_name Plugin Class name + * @param string $label Plugin label + * @param string $plugin_id Plugin id + * @param string $button_name Button name + */ + public function generate($module, $class_name, $label, $plugin_id, $button_name, $button_icon_path) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'button_name' => $button_name, + 'button_icon_path' => $button_icon_path, + ]; + + $this->renderFile( + 'module/src/Plugin/CKEditorPlugin/ckeditorbutton.php.twig', + $this->extensionManager->getPluginPath($module, 'CKEditorPlugin') . '/' . $class_name . '.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginConditionGenerator.php b/src/Generator/PluginConditionGenerator.php new file mode 100644 index 000000000..3b6fa9ad8 --- /dev/null +++ b/src/Generator/PluginConditionGenerator.php @@ -0,0 +1,66 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Field Formatter. + * + * @param string $module Module name + * @param string $class_name Plugin condition Class name + * @param string $label Plugin condition label + * @param string $plugin_id Plugin condition id + * @param string $context_definition_id Plugin condition context definition id + * @param string $context_definition_label Plugin condition context definition label + * @param bool $context_definition_required Plugin condition context definition required + */ + public function generate($module, $class_name, $label, $plugin_id, $context_definition_id, $context_definition_label, $context_definition_required) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'context_definition_id' => $context_definition_id, + 'context_definition_label' => $context_definition_label, + 'context_definition_required' => $context_definition_required, + 'context_id' => str_replace('entity:', '', $context_definition_id) + ]; + + $this->renderFile( + 'module/src/Plugin/Condition/condition.php.twig', + $this->extensionManager->getPluginPath($module, 'Condition') . '/' . $class_name . '.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginFieldFormatterGenerator.php b/src/Generator/PluginFieldFormatterGenerator.php new file mode 100644 index 000000000..b97fee7e3 --- /dev/null +++ b/src/Generator/PluginFieldFormatterGenerator.php @@ -0,0 +1,51 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Field Formatter. + * + * @param string $module Module name + * @param string $class_name Plugin Class name + * @param string $label Plugin label + * @param string $plugin_id Plugin id + * @param string $field_type Field type this formatter supports + */ + public function generate($module, $class_name, $label, $plugin_id, $field_type) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'field_type' => $field_type, + ]; + + $this->renderFile( + 'module/src/Plugin/Field/FieldFormatter/fieldformatter.php.twig', + $this->extensionManager->getPluginPath($module, 'Field/FieldFormatter') . '/' . $class_name . '.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginFieldTypeGenerator.php b/src/Generator/PluginFieldTypeGenerator.php new file mode 100644 index 000000000..75f832a9d --- /dev/null +++ b/src/Generator/PluginFieldTypeGenerator.php @@ -0,0 +1,55 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Field Type. + * + * @param string $module Module name + * @param string $class_name Plugin Class name + * @param string $label Plugin label + * @param string $plugin_id Plugin id + * @param string $description Plugin description + * @param string $default_widget Default widget this field type used supports + * @param string $default_formatter Default formatter this field type used supports + */ + public function generate($module, $class_name, $label, $plugin_id, $description, $default_widget, $default_formatter) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'description' => $description, + 'default_widget' => $default_widget, + 'default_formatter' => $default_formatter, + ]; + + $this->renderFile( + 'module/src/Plugin/Field/FieldType/fieldtype.php.twig', + $this->extensionManager->getPluginPath($module, 'Field/FieldType') . '/' . $class_name . '.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginFieldWidgetGenerator.php b/src/Generator/PluginFieldWidgetGenerator.php new file mode 100644 index 000000000..3e252e296 --- /dev/null +++ b/src/Generator/PluginFieldWidgetGenerator.php @@ -0,0 +1,51 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Field Formatter. + * + * @param string $module Module name + * @param string $class_name Plugin Class name + * @param string $label Plugin label + * @param string $plugin_id Plugin id + * @param string $field_type Field type this widget supports + */ + public function generate($module, $class_name, $label, $plugin_id, $field_type) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'field_type' => $field_type, + ]; + + $this->renderFile( + 'module/src/Plugin/Field/FieldWidget/fieldwidget.php.twig', + $this->extensionManager->getPluginPath($module, 'Field/FieldWidget') . '/' . $class_name . '.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginImageEffectGenerator.php b/src/Generator/PluginImageEffectGenerator.php new file mode 100644 index 000000000..fa56ef27b --- /dev/null +++ b/src/Generator/PluginImageEffectGenerator.php @@ -0,0 +1,51 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Image Effect. + * + * @param string $module Module name + * @param string $class_name Plugin Class name + * @param string $plugin_label Plugin label + * @param string $plugin_id Plugin id + * @param string $description Plugin description + */ + public function generate($module, $class_name, $label, $plugin_id, $description) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'description' => $description, + ]; + + $this->renderFile( + 'module/src/Plugin/ImageEffect/imageeffect.php.twig', + $this->extensionManager->getPluginPath($module, 'ImageEffect') .'/'.$class_name.'.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginImageFormatterGenerator.php b/src/Generator/PluginImageFormatterGenerator.php new file mode 100644 index 000000000..e71e739eb --- /dev/null +++ b/src/Generator/PluginImageFormatterGenerator.php @@ -0,0 +1,50 @@ +extensionManager = $extensionManager; + } + + + /** + * Generator Plugin Image Formatter. + * + * @param string $module Module name + * @param string $class_name Plugin Class name + * @param string $label Plugin label + * @param string $plugin_id Plugin id + */ + public function generate($module, $class_name, $label, $plugin_id) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + ]; + + $this->renderFile( + 'module/src/Plugin/Field/FieldFormatter/imageformatter.php.twig', + $this->extensionManager->getPluginPath($module, 'Field/FieldFormatter') . '/' . $class_name . '.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginMailGenerator.php b/src/Generator/PluginMailGenerator.php new file mode 100644 index 000000000..0c053b5d8 --- /dev/null +++ b/src/Generator/PluginMailGenerator.php @@ -0,0 +1,51 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Block. + * + * @param $module + * @param $class_name + * @param $label + * @param $plugin_id + * @param $services + */ + public function generate($module, $class_name, $label, $plugin_id, $services) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'services' => $services, + ]; + + $this->renderFile( + 'module/src/Plugin/Mail/mail.php.twig', + $this->extensionManager->getPluginPath($module, 'Mail') .'/'.$class_name.'.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginMigrateProcessGenerator.php b/src/Generator/PluginMigrateProcessGenerator.php new file mode 100644 index 000000000..227a5eda8 --- /dev/null +++ b/src/Generator/PluginMigrateProcessGenerator.php @@ -0,0 +1,52 @@ +extensionManager = $extensionManager; + } + + /** + * Generate Migrate Source plugin code. + * + * @param $module + * @param $class_name + * @param $plugin_id + */ + public function generate($module, $class_name, $plugin_id) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'plugin_id' => $plugin_id, + ]; + + $this->renderFile( + 'module/src/Plugin/migrate/process/process.php.twig', + $this->extensionManager->getPluginPath($module, 'migrate').'/process/'.$class_name.'.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginMigrateSourceGenerator.php b/src/Generator/PluginMigrateSourceGenerator.php new file mode 100644 index 000000000..123fab82c --- /dev/null +++ b/src/Generator/PluginMigrateSourceGenerator.php @@ -0,0 +1,60 @@ +extensionManager = $extensionManager; + } + + /** + * Generate Migrate Source plugin code. + * + * @param $module + * @param $class_name + * @param $plugin_id + * @param $table + * @param $alias + * @param $group_by + * @param fields + */ + public function generate($module, $class_name, $plugin_id, $table, $alias, $group_by, $fields) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'plugin_id' => $plugin_id, + 'table' => $table, + 'alias' => $alias, + 'group_by' => $group_by, + 'fields' => $fields, + ]; + + $this->renderFile( + 'module/src/Plugin/migrate/source/source.php.twig', + $this->extensionManager->getPluginPath($module, 'migrate').'/source/'.$class_name.'.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginRestResourceGenerator.php b/src/Generator/PluginRestResourceGenerator.php new file mode 100644 index 000000000..05518ce81 --- /dev/null +++ b/src/Generator/PluginRestResourceGenerator.php @@ -0,0 +1,59 @@ +extensionManager = $extensionManager; + } + + + /** + * Generator Plugin Block. + * + * @param $module + * @param $class_name + * @param $plugin_label + * @param $plugin_id + * @param $plugin_url + * @param $plugin_states + */ + public function generate($module, $class_name, $plugin_label, $plugin_id, $plugin_url, $plugin_states) + { + $parameters = [ + 'module_name' => $module, + 'class_name' => $class_name, + 'plugin_label' => $plugin_label, + 'plugin_id' => $plugin_id, + 'plugin_url' => $plugin_url, + 'plugin_states' => $plugin_states, + ]; + + $this->renderFile( + 'module/src/Plugin/Rest/Resource/rest.php.twig', + $this->extensionManager->getPluginPath($module, 'rest') .'/resource/'.$class_name.'.php', + $parameters + ); + } +} diff --git a/src/Generator/PluginRulesActionGenerator.php b/src/Generator/PluginRulesActionGenerator.php new file mode 100644 index 000000000..a60ee380c --- /dev/null +++ b/src/Generator/PluginRulesActionGenerator.php @@ -0,0 +1,65 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin RulesAction. + * + * @param $module + * @param $class_name + * @param $label + * @param $plugin_id + * @param $category + * @param $context + */ + public function generate($module, $class_name, $label, $plugin_id, $category, $context, $type) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'category' => $category, + 'context' => $context, + 'type' => $type, + ]; + + $this->renderFile( + 'module/src/Plugin/Action/rulesaction.php.twig', + $this->extensionManager->getPluginPath($module, 'Action').'/'.$class_name.'.php', + $parameters + ); + + $this->renderFile( + 'module/system.action.action.yml.twig', + $this->extensionManager->getModule($module)->getPath() .'/config/install/system.action.'.$plugin_id.'.yml', + $parameters + ); + } +} diff --git a/src/Generator/PluginSkeletonGenerator.php b/src/Generator/PluginSkeletonGenerator.php new file mode 100644 index 000000000..1e80864f4 --- /dev/null +++ b/src/Generator/PluginSkeletonGenerator.php @@ -0,0 +1,61 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Post Update Name function. + * + * @param $module + * @param $pluginId + * @param $plugin + * @param $className + * @param $pluginMetaData + * @param $services + */ + public function generate($module, $pluginId, $plugin, $className, $pluginMetaData, $services) + { + $module_path = $this->extensionManager->getModule($module)->getPath(); + + $parameters = [ + 'module' => $module, + 'plugin_id' => $pluginId, + 'plugin' => $plugin, + 'class_name' => $className, + 'services' => $services, + 'plugin_annotation' => array_pop(explode('\\', $pluginMetaData['pluginAnnotation'])), + 'plugin_interface' => array_pop(explode('\\', $pluginMetaData['pluginInterface'])) + ]; + + $this->renderFile( + 'module/src/Plugin/skeleton.php.twig', + $module_path .'/src/'. $pluginMetaData['subdir'] . '/' . $className .'.php', + array_merge($parameters, $pluginMetaData) + ); + } +} diff --git a/src/Generator/PluginTypeAnnotationGenerator.php b/src/Generator/PluginTypeAnnotationGenerator.php new file mode 100644 index 000000000..2a5181f17 --- /dev/null +++ b/src/Generator/PluginTypeAnnotationGenerator.php @@ -0,0 +1,85 @@ +extensionManager = $extensionManager; + } + + /** + * Generator for Plugin type with annotation discovery. + * + * @param $module + * @param $class_name + * @param $machine_name + * @param $label + */ + public function generate($module, $class_name, $machine_name, $label) + { + $parameters = [ + 'module' => $module, + 'class_name' => $class_name, + 'machine_name' => $machine_name, + 'label' => $label, + 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), + ]; + + $directory = $this->extensionManager->getModule($module)->getSourcePath() . '/Plugin/' . $class_name; + + if (!is_dir($directory)) { + mkdir($directory, 0777, true); + } + + $this->renderFile( + 'module/src/Annotation/plugin-type.php.twig', + $this->extensionManager->getModule($module)->getSourcePath() . '/Annotation/' . $class_name . '.php', + $parameters + ); + + $this->renderFile( + 'module/src/plugin-type-annotation-base.php.twig', + $this->extensionManager->getModule($module)->getSourcePath() .'/Plugin/' . $class_name . 'Base.php', + $parameters + ); + + $this->renderFile( + 'module/src/plugin-type-annotation-interface.php.twig', + $this->extensionManager->getModule($module)->getSourcePath() .'/Plugin/' . $class_name . 'Interface.php', + $parameters + ); + + $this->renderFile( + 'module/src/plugin-type-annotation-manager.php.twig', + $this->extensionManager->getModule($module)->getSourcePath() .'/Plugin/' . $class_name . 'Manager.php', + $parameters + ); + $this->renderFile( + 'module/plugin-annotation-services.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/PluginTypeYamlGenerator.php b/src/Generator/PluginTypeYamlGenerator.php new file mode 100644 index 000000000..8dd2807fb --- /dev/null +++ b/src/Generator/PluginTypeYamlGenerator.php @@ -0,0 +1,74 @@ +extensionManager = $extensionManager; + } + + /** + * Generator for Plugin type with Yaml discovery. + * + * @param $module + * @param $plugin_class + * @param $plugin_name + * @param $plugin_file_name + */ + public function generate($module, $plugin_class, $plugin_name, $plugin_file_name) + { + $parameters = [ + 'module' => $module, + 'plugin_class' => $plugin_class, + 'plugin_name' => $plugin_name, + 'plugin_file_name' => $plugin_file_name, + 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml'), + ]; + + $this->renderFile( + 'module/src/yaml-plugin-manager.php.twig', + $this->extensionManager->getModule($module)->getSourcePath() . '/' . $plugin_class . 'Manager.php', + $parameters + ); + + $this->renderFile( + 'module/src/yaml-plugin-manager-interface.php.twig', + $this->extensionManager->getModule($module)->getSourcePath() . '/' . $plugin_class . 'ManagerInterface.php', + $parameters + ); + + $this->renderFile( + 'module/plugin-yaml-services.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.services.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/plugin.yml.twig', + $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.' . $plugin_file_name . '.yml', + $parameters + ); + } +} diff --git a/src/Generator/PluginViewsFieldGenerator.php b/src/Generator/PluginViewsFieldGenerator.php new file mode 100644 index 000000000..3d0d03681 --- /dev/null +++ b/src/Generator/PluginViewsFieldGenerator.php @@ -0,0 +1,62 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Plugin Field Formatter. + * + * @param string $module Module name + * @param string $class_name Plugin Class name + * @param string $label Plugin label + * @param string $plugin_id Plugin id + * @param string $field_type Field type this formatter supports + */ + public function generate($module, $class_machine_name, $class_name, $title, $description) + { + $parameters = [ + 'module' => $module, + 'class_machine_name' => $class_machine_name, + 'class_name' => $class_name, + 'title' => $title, + 'description' => $description, + ]; + + $this->renderFile( + 'module/module.views.inc.twig', + $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.views.inc', + $parameters + ); + + $this->renderFile( + 'module/src/Plugin/Views/field/field.php.twig', + $this->extensionManager->getPluginPath($module, 'views/field') . '/' . $class_name . '.php', + $parameters + ); + } +} diff --git a/src/Generator/PostUpdateGenerator.php b/src/Generator/PostUpdateGenerator.php new file mode 100644 index 000000000..c3c10db7b --- /dev/null +++ b/src/Generator/PostUpdateGenerator.php @@ -0,0 +1,54 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Post Update Name function. + * + * @param $module + * @param $post_update_name + */ + public function generate($module, $post_update_name) + { + $module_path = $this->extensionManager->getModule($module)->getPath(); + + $parameters = [ + 'module' => $module, + 'post_update_name' => $post_update_name, + 'file_exists' => file_exists($module_path .'/'.$module.'.post_update.php'), + ]; + + $this->renderFile( + 'module/post-update.php.twig', + $module_path .'/'.$module.'.post_update.php', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/ProfileGenerator.php b/src/Generator/ProfileGenerator.php new file mode 100644 index 000000000..8d0857c1a --- /dev/null +++ b/src/Generator/ProfileGenerator.php @@ -0,0 +1,83 @@ + $profile, + 'machine_name' => $machine_name, + 'type' => 'profile', + 'core' => $core, + 'description' => $description, + 'dependencies' => $dependencies, + 'themes' => $themes, + 'distribution' => $distribution, + ]; + + $this->renderFile( + 'profile/info.yml.twig', + $dir . '/' . $machine_name . '.info.yml', + $parameters + ); + + $this->renderFile( + 'profile/profile.twig', + $dir . '/' . $machine_name . '.profile', + $parameters + ); + + $this->renderFile( + 'profile/install.twig', + $dir . '/' . $machine_name . '.install', + $parameters + ); + } +} diff --git a/src/Generator/RouteSubscriberGenerator.php b/src/Generator/RouteSubscriberGenerator.php new file mode 100644 index 000000000..388991f37 --- /dev/null +++ b/src/Generator/RouteSubscriberGenerator.php @@ -0,0 +1,62 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Service. + * + * @param string $module Module name + * @param string $name Service name + * @param string $class Class name + */ + public function generate($module, $name, $class) + { + $parameters = [ + 'module' => $module, + 'name' => $name, + 'class' => $class, + 'class_path' => sprintf('Drupal\%s\Routing\%s', $module, $class), + 'tags' => ['name' => 'event_subscriber'], + 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), + ]; + + $this->renderFile( + 'module/src/Routing/route-subscriber.php.twig', + $this->extensionManager->getModule($module)->getRoutingPath().'/'.$class.'.php', + $parameters + ); + + $this->renderFile( + 'module/services.yml.twig', + $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', + $parameters, + FILE_APPEND + ); + } +} diff --git a/src/Generator/ServiceGenerator.php b/src/Generator/ServiceGenerator.php new file mode 100644 index 000000000..855839f80 --- /dev/null +++ b/src/Generator/ServiceGenerator.php @@ -0,0 +1,102 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Service. + * + * @param string $module Module name + * @param string $name Service name + * @param string $class Class name + * @param string $interface If TRUE an interface for this service is generated + * @param array $services List of services + * @param string $path_service Path of services + */ + public function generate($module, $name, $class, $interface, $interface_name, $services, $path_service) + { + $interface = $interface ? ($interface_name ?: $class . 'Interface') : false; + $parameters = [ + 'module' => $module, + 'name' => $name, + 'class' => $class, + 'class_path' => sprintf('Drupal\%s\%s', $module, $class), + 'interface' => $interface, + 'services' => $services, + 'path_service' => $path_service, + 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), + ]; + + $this->renderFile( + 'module/services.yml.twig', + $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/src/service.php.twig', + $this->setDirectory($path_service, 'service.php.twig', $module, $class), + $parameters + ); + + if ($interface) { + $this->renderFile( + 'module/src/service-interface.php.twig', + $this->setDirectory($path_service, 'interface.php.twig', $module, $interface), + $parameters + ); + } + } + + protected function setDirectory($target, $template, $module, $class) + { + $default_path = '/modules/custom/' . $module . '/src/'; + $directory = ''; + + switch ($template) { + case 'service.php.twig': + $default_target = $this->extensionManager->getModule($module)->getPath() .'/src/'.$class.'.php'; + $custom_target = $this->extensionManager->getModule($module)->getPath() .'/'.$target.'/'.$class.'.php'; + + $directory = (strcmp($target, $default_path) == 0) ? $default_target : $custom_target; + break; + case 'interface.php.twig': + $default_target = $this->extensionManager->getModule($module)->getPath() .'/src/'.$class.'.php'; + $custom_target = $this->extensionManager->getModule($module)->getPath() .'/'.$target.'/'.$class.'.php'; + + $directory = (strcmp($target, $default_path) == 0) ? $default_target : $custom_target; + break; + default: + // code... + break; + } + + return $directory; + } +} diff --git a/src/Generator/ThemeGenerator.php b/src/Generator/ThemeGenerator.php new file mode 100644 index 000000000..78342bf98 --- /dev/null +++ b/src/Generator/ThemeGenerator.php @@ -0,0 +1,118 @@ +extensionManager = $extensionManager; + } + + public function generate( + $theme, + $machine_name, + $dir, + $description, + $core, + $package, + $base_theme, + $global_library, + $libraries, + $regions, + $breakpoints + ) { + $dir .= '/' . $machine_name; + if (file_exists($dir)) { + if (!is_dir($dir)) { + throw new \RuntimeException( + sprintf( + 'Unable to generate the bundle as the target directory "%s" exists but is a file.', + realpath($dir) + ) + ); + } + $files = scandir($dir); + if ($files != ['.', '..']) { + throw new \RuntimeException( + sprintf( + 'Unable to generate the bundle as the target directory "%s" is not empty.', + realpath($dir) + ) + ); + } + if (!is_writable($dir)) { + throw new \RuntimeException( + sprintf( + 'Unable to generate the bundle as the target directory "%s" is not writable.', + realpath($dir) + ) + ); + } + } + + $parameters = [ + 'theme' => $theme, + 'machine_name' => $machine_name, + 'type' => 'theme', + 'core' => $core, + 'description' => $description, + 'package' => $package, + 'base_theme' => $base_theme, + 'global_library' => $global_library, + 'libraries' => $libraries, + 'regions' => $regions, + 'breakpoints' => $breakpoints, + ]; + + $this->renderFile( + 'theme/info.yml.twig', + $dir . '/' . $machine_name . '.info.yml', + $parameters + ); + + $this->renderFile( + 'theme/theme.twig', + $dir . '/' . $machine_name . '.theme', + $parameters + ); + + if ($libraries) { + $this->renderFile( + 'theme/libraries.yml.twig', + $dir . '/' . $machine_name . '.libraries.yml', + $parameters + ); + } + + if ($breakpoints) { + $this->renderFile( + 'theme/breakpoints.yml.twig', + $dir . '/' . $machine_name . '.breakpoints.yml', + $parameters + ); + } + } +} diff --git a/src/Generator/TwigExtensionGenerator.php b/src/Generator/TwigExtensionGenerator.php new file mode 100644 index 000000000..91c522023 --- /dev/null +++ b/src/Generator/TwigExtensionGenerator.php @@ -0,0 +1,69 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Service. + * + * @param string $module Module name + * @param string $name Service name + * @param string $class Class name + * @param array $services List of services + */ + public function generate($module, $name, $class, $services) + { + $parameters = [ + 'module' => $module, + 'name' => $name, + 'class' => $class, + 'class_path' => sprintf('Drupal\%s\TwigExtension\%s', $module, $class), + 'services' => $services, + 'tags' => ['name' => 'twig.extension'], + 'file_exists' => file_exists($this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml'), + ]; + + $this->renderFile( + 'module/services.yml.twig', + $this->extensionManager->getModule($module)->getPath() .'/'.$module.'.services.yml', + $parameters, + FILE_APPEND + ); + + $this->renderFile( + 'module/src/TwigExtension/twig-extension.php.twig', + $this->extensionManager->getModule($module)->getPath() .'/src/TwigExtension/'.$class.'.php', + $parameters + ); + } +} diff --git a/src/Generator/UpdateGenerator.php b/src/Generator/UpdateGenerator.php new file mode 100644 index 000000000..55180668d --- /dev/null +++ b/src/Generator/UpdateGenerator.php @@ -0,0 +1,55 @@ +extensionManager = $extensionManager; + } + + /** + * Generator Update N function. + * + * @param $module + * @param $update_number + */ + public function generate($module, $update_number) + { + $modulePath = $this->extensionManager->getModule($module)->getPath(); + $updateFile = $modulePath .'/'.$module.'.install'; + + $parameters = [ + 'module' => $module, + 'update_number' => $update_number, + 'file_exists' => file_exists($updateFile) + ]; + + $this->renderFile( + 'module/update.php.twig', + $updateFile, + $parameters, + FILE_APPEND + ); + } +}