Must implement interface > Drupal\Core\Entity\EntityTypeManagerInterface, none given in __construct() function I am trying to write a custom eventsubscriber for commerce 2.x for an event after a successful checkout. Everything works and now I want to create a __construct function to initialize an object, but then I get the following error:


  TypeError: Argument 1 passed to
  Drupal\custom_module\EventSubscriber\OrderCompleteEventSubscriber::__construct()
  must implement interface
  Drupal\Core\Entity\EntityTypeManagerInterface, none given, called in
  /home/user/websiteName/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php
  on line 264 in Drupal\custom_module\EventSubscriber\OrderCompleteEventSubscriber->__construct() 


I've tried explicitly defining the EntityTypeManagerInterface within the class, but everything is resulting in this error. Not finding anyone with any similar issues, and this particular block of code works for other people, just wondering what I am missing or If I am doing something incorrect. This code runs great if I don't construct an object with EntityTypeManagerInterfaceas the argument ... any ideas?

namespace Drupal\custom_module\EventSubscriber;

use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\rng\RegistrantFactoryInterface;
use Drupal\state_machine\Event\WorkflowTransitionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;


class OrderCompleteEventSubscriber implements EventSubscriberInterface {

  use StringTranslationTrait;

  /**
   * The registration entity storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $registrationStorage;

  /**
   * The user entity storage.
   *
   * @var \Drupal\user\UserStorage
   */
  protected $userStorage;

  /**
   * The registration access handler.
   *
   * @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface
   */
  protected $registrationAccessHandler;

  /**
   * The registrant factory.
   *
   * @var \Drupal\rng\RegistrantFactoryInterface
   */
  protected $registrantFactory;

  /**
   * Drupal\Core\Session\AccountProxyInterface definition.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * Constructs a new OrderCompleteEventSubscriber object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   * @param \Drupal\rng\RegistrantFactoryInterface $registrantFactory
   * @param \Drupal\Core\Session\AccountProxyInterface $current_user
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, RegistrantFactoryInterface $registrantFactory, AccountProxyInterface $current_user) {
    $this-&gt;registrationStorage = $entity_type_manager-&gt;getStorage('registration');
    $this-&gt;registrationAccessHandler = $entity_type_manager-&gt;getAccessControlHandler('registration');
    $this-&gt;userStorage = $entity_type_manager-&gt;getStorage('user');
    $this-&gt;registrantFactory = $registrantFactory;
    $this-&gt;currentUser = $current_user;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      'commerce_order.place.post_transition' =&gt; ['buildRegistration'],
    ];
  }

  /**
   *
   * @param \Drupal\state_machine\Event\WorkflowTransitionEvent $event
   */
  public function buildRegistration(WorkflowTransitionEvent $event) {
    $order = $event-&gt;getEntity();
    // do stuff
      }
    }
  }

}


Services.yml File

services:
   custom_module_event_subscriber:
      class: '\Drupal\custom_module\EventSubscriber\OrderCompleteEventSubscriber'
      tags:
        - { name: 'event_subscriber' }
A bit late but the code from EventSubscriber has three arguments so your services.yml file should read:

services:
  custom_module.order_complete:
    class: Drupal\custom_module\EventSubscriber\PurchaseBuildRegistration
    arguments: ['@entity_type.manager', '@rng.registrant.factory', '@current_user']
tags:
  - { name: event_subscriber }