I've been reading for days, trying several examples but I'm just not getting it.
I have the Rules module as well as the H5P module. I'm attempting to create a Rules event from the existing H5PFinished event (which may or may not be the way to go about this).
Their function constructs an array of five fields, which then update in the GDB.
// which fields to update
$fields = [
'content_id' => $content_id,
'uid' => $uid,
'finished' => time(),
'points' => $score,
'max_points' => $max_score,
];
They then invoke an event.
$this->eventDispatcher->dispatch(FinishedEvent::FINISHED_EVENT, new FinishedEvent($fields));
In the FinishedEvent.php file, they name the event and return the fields as an array.
class FinishedEvent extends Event {
const FINISHED_EVENT = 'h5p.finished';
/**
* @var array
*/
protected $quizData;
/**
* Constructs a FinishedEvent object.
*
* @param array $quiz_data
* Database connection service.
*/
public function __construct(array $quiz_data) {
$this->quizData = $quiz_data;
}
/**
* @return array
* Quiz data.
*/
public function getQuizFields() {
return $this->quizData;
}
}
I'd like to be able to have a custom rule event which basically is fired when the database is updated, and if the user has score == max_score, a data value is set in their user profile (I do have the actions working fine. I tested using a simple "if page is viewed). I'm just super lost.
I've created the custom module to add the Event to Rules. I've used the event name defined in and subscribed to in H5P ("h5p.finished") and added four integer type context_definitions (which worked earlier, but now throws an error that the data needs to be of type array, string given).
mymodule.rules.events.yml
h5p.finished:
label: 'Interactive Content is Solved'
category: 'H5P'
context_definitions:
content_id:
type:'integer'
label:'Content ID'
max_score:
type:'integer'
label:'Max Score'
score:
type:'integer'
label:'Score'