Skip to content
Snippets Groups Projects
Commit 83c61c9c authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Revert "Issue #3384786 by jurgenhaas: Update plugin templates for code generator"

This reverts commit da32adc8.
parent da32adc8
No related branches found
No related merge requests found
......@@ -19,13 +19,15 @@ use DrupalCodeGenerator\GeneratorType;
)]
class ActionGenerator extends BaseGenerator {
use EcaGeneratorTrait;
/**
* {@inheritdoc}
*/
protected function generate(array &$vars, Assets $assets): void {
$ir = $this->prepareGenerator($vars);
$ir = $this->createInterviewer($vars);
$vars['machine_name'] = $ir->askMachineName();
$vars['phpprefix'] = '<?php';
$vars['purpose'] = $ir->ask('Purpose of the action (typically 1 to 3 words)', 'Print object');
$vars['description'] = $ir->ask('Description', '');
$vars['type'] = $ir->ask('Type (e.g. "entity" or "node" or "user", normally empty)', '');
$vars['id'] = mb_strtolower(str_replace([':', ' ', '-', '.', ',', '__'], '_', $vars['purpose']));
$vars['class'] = '{id|camelize}Action';
......
......@@ -19,13 +19,15 @@ use DrupalCodeGenerator\GeneratorType;
)]
class ConditionGenerator extends BaseGenerator {
use EcaGeneratorTrait;
/**
* {@inheritdoc}
*/
protected function generate(array &$vars, Assets $assets): void {
$ir = $this->prepareGenerator($vars);
$ir = $this->createInterviewer($vars);
$vars['machine_name'] = $ir->askMachineName();
$vars['phpprefix'] = '<?php';
$vars['purpose'] = $ir->ask('Purpose of the consition (typically 1 to 3 words)', 'Object: is printable');
$vars['description'] = $ir->ask('Description', '');
$vars['context'] = explode(',', $ir->ask('Supported context (comma separated list, e.g. "node,user")', ''));
$vars['id'] = mb_strtolower(str_replace([':', ' ', '-', '.', ',', '__'], '_', $vars['purpose']));
$vars['class'] = '{id|camelize}Condition';
......
<?php
namespace Drupal\eca_development\Drush\Generators;
use DrupalCodeGenerator\InputOutput\Interviewer;
/**
* Provides general methods for all ECA generators.
*/
trait EcaGeneratorTrait {
/**
* Prepares the generator for all plugins.
*
* @param array $vars
* The variables.
*
* @return \DrupalCodeGenerator\InputOutput\Interviewer
* The interviewer.
*/
protected function prepareGenerator(array &$vars): Interviewer {
$ir = $this->createInterviewer($vars);
$vars['machine_name'] = $ir->askMachineName();
$vars['phpprefix'] = '<?php';
$vars['purpose'] = $ir->ask('Purpose of the plugin (typically 1 to 3 words)', 'Do someting');
$vars['description'] = $ir->ask('Description', '');
$vars['module_version'] = $ir->ask('Module version when this plugin gets published', '1.0.0');
return $ir;
}
}
......@@ -19,13 +19,13 @@ use DrupalCodeGenerator\GeneratorType;
)]
class EventsGenerator extends BaseGenerator {
use EcaGeneratorTrait;
/**
* {@inheritdoc}
*/
protected function generate(array &$vars, Assets $assets): void {
$this->prepareGenerator($vars);
$ir = $this->createInterviewer($vars);
$vars['machine_name'] = $ir->askMachineName();
$vars['phpprefix'] = '<?php';
$assets->addFile('src/Event/MyEvent.php', 'event.twig');
$assets->addFile('src/Plugin/ECA/Event/EcaEvent.php', 'plugin.twig');
$assets->addFile('src/Plugin/ECA/Event/EcaEventDeriver.php', 'deriver.twig');
......
......@@ -13,9 +13,7 @@ use Drupal\eca\Plugin\Action\ConfigurableActionBase;
*
* @Action(
* id = "{{ machine_name }}_{{ id }}",
* label = @Translation("{{ purpose }}"),
* description = @Translation("{{ description }}"),
* eca_version_introduced = "{{ module_version }}"{% if type %},
* label = @Translation("{{ purpose }}"){% if type %},
* type = "{{ type }}"{% endif %}
* )
*/
......
......@@ -12,7 +12,6 @@ use Drupal\eca\Plugin\ECA\Condition\ConditionBase;
* id = "{{ machine_name }}_{{ id }}",
* label = @Translation("{{ purpose }}"),
* description = @Translation("{{ description }}"),
* eca_version_introduced = "{{ module_version }}",
{% if context %}
* context_definitions = {
{% for i,item in context %}
......
......@@ -8,7 +8,7 @@ namespace Drupal\{{ machine_name }};
final class EcaEvents {
/**
* Identifies \Drupal\{{ machine_name }}\Event\MyEvent event.
* Describes the event.
*
* @Event
*
......
......@@ -2,25 +2,19 @@
namespace Drupal\{{ machine_name }}\Plugin\ECA\Event;
use Drupal\Core\Form\FormStateInterface;
use Drupal\eca\Event\Tag;
use Drupal\eca\Plugin\CleanupInterface;
use Drupal\eca\Plugin\ECA\Event\EventBase;
use Drupal\{{ machine_name }}\EcaEvents;
use Drupal\{{ machine_name }}\Event\MyEvent;
use Symfony\Contracts\EventDispatcher\Event;
/**
* Plugin implementation of the ECA Events for {{ machine_name }}.
*
* @EcaEvent(
* id = "{{ machine_name }}",
* deriver = "Drupal\{{ machine_name }}\Plugin\ECA\Event\EcaEventDeriver",
* description = @Translation(""),
* eca_version_introduced = "{{ module_version }}"
* deriver = "Drupal\{{ machine_name }}\Plugin\ECA\Event\EcaEventDeriver"
* )
*/
class EcaEvent extends EventBase implements CleanupInterface {
class EcaEvent extends EventBase {
/**
* {@inheritdoc}
......@@ -28,109 +22,11 @@ class EcaEvent extends EventBase implements CleanupInterface {
public static function definitions(): array {
$definitions = [];
$definitions['event1'] = [
'label' => '{{ purpose }}',
'description' => '{{ description }}',
'label' => 'Label for the first event',
'event_name' => EcaEvents::IDENTIFIER1,
'event_class' => MyEvent::class,
'tags' => Tag::CONTENT | Tag::WRITE | Tag::RUNTIME | Tag::AFTER,
];
return $definitions;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration(): array {
return [] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
$form = parent::buildConfigurationForm($form, $form_state);
if ($this->eventClass() === MyEvent::class) {
// @todo Extend the form for this event.
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
parent::submitConfigurationForm($form, $form_state);
if ($this->eventClass() === MyEvent::class) {
// @@todo Provide the submit functionality for this event.
}
}
/**
* {@inheritdoc}
*/
public function generateWildcard(string $eca_config_id, EcaEvent $ecaEvent): string {
/** @var \Drupal\eca\Plugin\ECA\Event\EventBase $plugin */
$plugin = $ecaEvent->getPlugin();
switch ($plugin->getDerivativeId()) {
case 'event1':
return '*';
default:
return '*';
}
}
/**
* {@inheritdoc}
*/
public static function appliesForWildcard(Event $event, string $event_name, string $wildcard): bool {
if ($event instanceof MyEvent) {
return TRUE;
}
return TRUE;
}
/**
* {@inheritdoc}
*/
public function cleanupAfterSuccessors(): void {
switch ($this->getDerivativeId()) {
case 'event1':
// @todo Do something if necessary.
}
}
}
/**
* {@inheritdoc}
*/
protected function buildEventData(): array {
$event = $this->event;
$data = [];
if ($event instanceof MyEvent) {
$data += [
'my_event_token' => 'Some data',
];
}
$data += parent::buildEventData();
return $data;
}
/**
* {@inheritdoc}
*/
public function getData(string $key): mixed {
$event = $this->event;
if ($key === 'another_token' && $event instanceof MyEvent) {
return 'some other data';
}
return parent::getData($key);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment