Events 2.0, Descriptions, and Event Names

Events 2.0, Descriptions, and Event Names

by Karl Morey -
Number of replies: 7

Afternoon, folks.

Can anybody point me to what actually *calls* the get_name() or get_description() functions in each <event_name>.php file, utilizing Events 2.0 in Moodle 2.7?

I have crafted events for my plugin for support purposes, and the events are popping in to the Live Log, but the Event Name and Event Description columns say "Unknown Event."

I have, I believe, appropriate strings defined in the plugin's en language file. I have *not* implemented my own observer class because the system's log is all I need for now.


Thanks in advance.

Average of ratings: -
In reply to Karl Morey

Re: Events 2.0, Descriptions, and Event Names

by Karl Morey -

Figured it out, never mind smile

In reply to Karl Morey

Re: Events 2.0, Descriptions, and Event Names

by Caio Santana Magalhães -

Sorry Karl, but I didn't.


And I am finding this new Moodle Events/Logging API very poorly documented and overcomplicated.


Could you explain what you did figure out?

In reply to Caio Santana Magalhães

Re: Events 2.0, Descriptions, and Event Names

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Unfortunately, Karl did not follow this forum rule: if you solve your own problem, do post the solution, as it may help others who experienced the same problem as yours.

Joseph

In reply to Karl Morey

Re: Events 2.0, Descriptions, and Event Names

by Bharath Parlapalli -

I am pulling out my hair trying to figure this out right now. Can you please share the way to change te event name from "unkwown" to customized name?


Thank you

In reply to Karl Morey

Re: Events 2.0, Descriptions, and Event Names

by Gerald Albion -
Great that you've figured it out, but it would have been nice to share your findings.

I have also encountered this problem, and found that the cause was that we had created the event class in classes/events (plural).  It has to be in classes/event (singular!).  As soon as this was fixed, the logs showed the correct component, event name, and description for the event, including log entries that had previously indicated an unknown event.

---
Gerald Albion
Royal Roads University.
Average of ratings: Useful (1)
In reply to Karl Morey

Re: Events 2.0, Descriptions, and Event Names

by Jonathan Castillo -
I also encountered this, but got it working.


The get_name function requires that the returned string is defined in the language string and must have a proper key. It's easier to explain by code.


Event File: plugin_folder\classes\event\something_happened.php

class something_happened extends \core\event\base {

    ...

    public static function get_name() {

        return get_string('eventsomethinghappened', 'plugin_name'); //<-- the language string key is very important. Note that it should start with the word 'event' followed by the event name without the underscore.

    }

    ...

}


Language File: plugin_folder\lang\en\plugin_name.php

$string['eventsomethinghappened'] = 'Something has happened';


I hope this will help.

In reply to Jonathan Castillo

Re: Events 2.0, Descriptions, and Event Names

by Marjan Milošević -

Well, that really helped. 

Although I do a lot copy/paste/fix in order to reuse code and learn, I neglected this detail. 

Thanks