d8rules integration draft. #452

Merged
merged 1 commit into from Feb 25, 2015
Jump to file or symbol
Failed to load files and symbols.
+221 −0
Diff settings

Always

Just for now

@@ -0,0 +1,141 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\AppConsole\Command\GeneratorPluginBlockCommand.
+ */
+
+namespace Drupal\AppConsole\Command;
+
+use Drupal\AppConsole\Generator\PluginRulesActionGenerator;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Drupal\AppConsole\Generator\PluginBlockGenerator;
+use Drupal\AppConsole\Command\Helper\ServicesTrait;
+use Drupal\AppConsole\Command\Helper\ModuleTrait;
+use Drupal\AppConsole\Command\Helper\FormTrait;
+use Drupal\AppConsole\Command\Helper\ConfirmationTrait;
+
+class GeneratorPluginRulesActionCommand extends GeneratorCommand
+{
+ use ServicesTrait;
+ use ModuleTrait;
+ use FormTrait;
+ use ConfirmationTrait;
+
+ protected function configure()
+ {
+ $this
+ ->setName('generate:plugin:rulesaction')
+ ->setDescription($this->trans('commands.generate.plugin.block.description'))
+ ->setHelp($this->trans('commands.generate.plugin.block.help'))
+ ->addOption('module','',InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
+ ->addOption('class-name','',InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.block.options.class-name'))
+ ->addOption('label','',InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.block.options.label'))
+ ->addOption('plugin-id','',InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.block.options.plugin-id'))
+ ->addOption('category','',InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.common.options.category'))
+ ->addOption('context','',InputOption::VALUE_OPTIONAL, $this->trans('commands.common.options.context'))
+ ;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $dialog = $this->getDialogHelper();
+
+ // @see use Drupal\AppConsole\Command\Helper\ConfirmationTrait::confirmationQuestion
+ if ($this->confirmationQuestion($input, $output, $dialog)) {
+ return;
+ }
+
+ $module = $input->getOption('module');
+ $class_name = $input->getOption('class-name');
+ $label = $input->getOption('label');
+ $plugin_id = $input->getOption('plugin-id');
+ $category = $input->getOption('category');
+ $context = $input->getOption('context');
+
+ $this
+ ->getGenerator()
+ ->generate($module, $class_name, $label, $plugin_id, $category, $context)
+ ;
+ }
+
+ protected function interact(InputInterface $input, OutputInterface $output)
+ {
+ $dialog = $this->getDialogHelper();
+
+ // --module option
+ $module = $input->getOption('module');
+ if (!$module) {
+ // @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion
+ $module = $this->moduleQuestion($output, $dialog);
+ }
+ $input->setOption('module', $module);
+
+ // --class-name option
+ $class_name = $input->getOption('class-name');
+ if (!$class_name) {
+ $class_name = $dialog->ask(
+ $output,
+ $dialog->getQuestion($this->trans('commands.generate.plugin.block.options.class-name'), 'DefaultBlock'),
+ 'DefaultBlock'
+ );
+ }
+ $input->setOption('class-name', $class_name);
+
+ $machine_name = $this->getStringUtils()->camelCaseToUnderscore($class_name);
+
+ // --label option
+ $label = $input->getOption('label');
+ if (!$label) {
+ $label = $dialog->ask(
+ $output,
+ $dialog->getQuestion($this->trans('commands.generate.plugin.block.options.label'), $machine_name),
+ $machine_name
+ );
+ }
+ $input->setOption('label', $label);
+
+ // --plugin-id option
+ $plugin_id = $input->getOption('plugin-id');
+ if (!$plugin_id) {
+ $plugin_id = $dialog->ask(
+ $output,
+ $dialog->getQuestion($this->trans('commands.generate.plugin.block.options.plugin-id'),$machine_name),
+ $machine_name
+ );
+ }
+ $input->setOption('plugin-id', $plugin_id);
+
+ // --category option
+ $category = $input->getOption('category');
+ if (!$category) {
+ $category = $dialog->ask(
+ $output,
+ $dialog->getQuestion($this->trans('commands.generate.plugin.block.options.category'),$machine_name),
+ $machine_name
+ );
+ }
+ $input->setOption('category', $category);
+
+ // --context option
+ $context = $input->getOption('context');
+ if (!$context) {
+ $context = $dialog->ask(
+ $output,
+ $dialog->getQuestion($this->trans('commands.generate.plugin.block.options.context'),$machine_name),
+ $machine_name
+ );
+ }
+ $input->setOption('context', $context);
+ }
+
+ protected function createGenerator()
+ {
+ return new PluginRulesActionGenerator();
+ }
+
+}
@@ -0,0 +1,37 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\AppConsole\Generator\PluginBlockGenerator.
+ */
+
+namespace Drupal\AppConsole\Generator;
+
+class PluginRulesActionGenerator extends Generator
+{
+ /**
+ * 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)
+ {
+ $parameters = [
+ 'module' => $module,
+ 'class_name' => $class_name,
+ 'label' => $label,
+ 'plugin_id' => $plugin_id,
+ 'category' => $category,
+ 'context' => $context,
+ ];
+
+ $this->renderFile(
+ 'module/src/Plugin/RulesAction/rulesaction.php.twig',
+ $this->getPluginPath($module, 'RulesAction').'/'.$class_name.'.php',
+ $parameters
+ );
+ }
+}
@@ -0,0 +1,43 @@
+{% extends "base/class.php.twig" %}
+
+{% block file_path %}
+Drupal\{{module}}\Plugin\Action\{{class_name}}.
+{% endblock %}
+
+{% block namespace_class %}
+namespace Drupal\{{module}}\Plugin\Action;
+{% endblock %}
+
+{% block use_class %}
+use Drupal\rules\Engine\RulesActionBase;
+{% endblock %}
+
+{% block class_declaration %}
+/**
+ * Provides a '{{class_name}}' action.
+ *
+ * @Action(
+ * id = "{{plugin_id}}",
+ * label = @Translation("{{label}}"),
+ * category = @Translation("{{category}}"),
+ * context = {{context}}
+ * )
+ */
+class {{class_name}} extends RulesActionBase
+{% endblock %}
+
+{% block class_methods %}
+ /**
+ * {@inheritdoc}
+ */
+ public function summary() {
+ return $this->t('{{label}}');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function execute() {
+ // Insert code here.
+ }
+{% endblock %}