I want to do something when a node gets updated. To keep it simple, lets say display a drupal message.
hello_world.routing.yml
hello_world: path: /node/{node} defaults: _controller: Drupalhello_worldControllerHelloWorldController::hello_world_entity_update requirements: _permission: 'access content'
Not sure if the path should be /node/{node}/edit
instead.
HelloWorldController.php
<?php /** * @file * Contains Drupalhello_worldControllerHelloController. */ namespace Drupalhello_worldController; use DrupalCoreControllerControllerBase; class HelloWorldController extends ControllerBase { public function hello_world_entity_update(DrupalCoreEntityEntityInterface $entity) { drupal_set_message(t('Something @var just happened.', array('@var' => 'cool'))); } }
Since hook_node_update() was depreciated, I assume we now have to use hook_entity_update().
I am not getting the message upon updating a node, what I’m I missing or doing wrong?
Update
Just so I don’t confuse anyone. I was brainwashed into thinking I needed a routing file and a controller. All the D8 examples out there use them.
Since I was not creating any pages, turns out I did not need a routing.yml file nor a Controller.php file nor the /src folder. All I had to do is approach this like Drupal 7, all that I needed was the .info.yml file and a .module file to put the hook.