I am new to moodle development as well as php. I am trying to get some event listeners working in moodle 3.5. At this point I am just trying to get some output in the console when an event is triggered. My plugin is in the form of a block. Here is my file structure:
Here is the code in events.php:
defined('MOODLE_INTERNAL') || die();
$observers = array (
array (
'eventname' => '\core\event\user_loggedin',
'callback' => 'block_simplehtml_observer::update',
),
array (
'eventname' => '\core\event\user_loggedout',
'callback' => 'block_simplehtml_observer::update',
),
array (
'eventname' => '\core\event\course_module_created',
'callback' => 'block_simplehtml_observer::update',
),
);
Here is the code in observer.php
defined('MOODLE_INTERNAL') || die();
class block_simplehtml_observer {
public static function update(\core\event\base $event) {
// This code works when put inside the corresponding 'store' function in blocks/recent_activity/classes/observer.php
$json_data = json_encode($event->get_data());
echo("<script>console.log('EVENT: ".$json_data."');</script>");
}
}
The rest of the files directly follow the simplehtml block tutorial on moodles development site. I am not sure whether there is something that I need to do in another file to get this working or I am doing something incorrectly in these two files. I have been trying to debug this for a couple of hours by looking at existing events/observer files with no luck. Any help would be much appreciated.