I am building a new service, an event subscriber in a custom module. My class which extends EventSubscriberInterface is not being found.
[error] Class Drupal\fivewire_commerce\EventSubscriber\fivewire_commerce_orderStateSubscriber does not exist
I am not sure why and am struggling to debug what I have done wrong.
My module is 'fivewire_commerce'.
/modules/custom/fivewire_commerce
I have created a file to delare my service.
/modules/custom/fivewire_commerce/fivewire_commerce.services.yml
services:
fivewire_commerce.order_subscriber:
class: Drupal\fivewire_commerce\EventSubscriber\fivewire_commerce_orderStateSubscriber
tags:
- { name: 'event_subscriber' }
And this is my class
/modules/custom/fivewire_commerce/EventSubscriber/fivewire_commerce_orderStateSubscriber.php
<?php
/**
* @file
* Contains \Drupal\fivewire_commerce\EventSubscriber\fivewire_commerce_orderStateSubscriber
*/
namespace Drupal\fivewire_commerce\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\state_machine\Event\WorkflowTransitionEvent;
/**
* Event Subscriber MyEventSubscriber.
*/
class fivewire_commerce_orderStateSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// Trigger after an order is made
$events['commerce_order.place.post_transition'][] = ['onCompletedOrders'];
return $events;
}
/**
* Code that should be triggered when an order is placed.
* This is the order state 'validation' according to our chosen workflow.
*/
public function onCompletedOrders(WorkflowTransitionEvent $event) {
$test =true;
// if ($event->getToState()->getId() == 'validation') {
//
// }
}
}
And if I try to rebuild my cache I get:
[error] Class Drupal\fivewire_commerce\EventSubscriber\fivewire_commerce_orderStateSubscriber does not exist