How to trigger EntityTypeEvents::UPDATE event in Drupal 8?

by Max28   Last Updated September 11, 2019 10:07 AM

I tried to trigger event on each entity update. This is my src/EventSubscriber/MySub.php

    use Drupal\Core\Entity\EntityTypeEvents;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;

    class MySub implements EventSubscriberInterface{

      public function onEntityTypeUpdate(EntityTypeEvents $event)  {
            drupal_set_message("returned from onEntityTypeUpdate"); 

      public static function getSubscribedEvents() {

          $events[EntityTypeEvents::UPDATE][] = array('onEntityTypeUpdate');

    return $events;

This is my services.yml file

    class: '\Drupal\custom_sub\EventSubscriber\MySub'
    arguments: ['@entity.manager']
      - { name: 'event_subscriber' }

But the message is not displaying after updating the content or content type. Please guide.

Related Questions

Caching Event Subcriber

Updated March 13, 2016 08:03 AM

How can an event subscriber have access to entity type?

Updated November 17, 2017 23:07 PM

Event Subscriber Drupal8

Updated January 11, 2019 06:07 AM