$newtemplate->listtemplateheader = $mytemplate->listtemplateheader; } if (isset($mytemplate->listtemplatefooter)) { $newtemplate->listtemplatefooter = $mytemplate->listtemplatefooter; } if (isset($mytemplate->rsstitletemplate)) { $newtemplate->rsstitletemplate = $mytemplate->rsstitletemplate; } // Check for multiple tags, only need to check for add template. if ($mode != 'addtemplate' or data_tags_check($data->id, $newtemplate->{$mode})) { // if disableeditor or enableeditor buttons click, don't save instance if (empty($disableeditor) && empty($enableeditor)) { $DB->update_record('data', $newtemplate); echo $OUTPUT->notification(get_string('templatesaved', 'data'), 'notifysuccess'); // Trigger an event for saving the templates. $event = \mod_data\event\template_updated::create(array('context' => $context, 'courseid' => $course->id, 'other' => array('dataid' => $data->id))); $event->trigger(); } } } } else { echo '<div class="template_heading">' . get_string('header' . $mode, 'data') . '</div>'; } /// If everything is empty then generate some defaults if (empty($data->addtemplate) and empty($data->singletemplate) and empty($data->listtemplate) and empty($data->rsstemplate)) { data_generate_default_template($data, 'singletemplate'); data_generate_default_template($data, 'listtemplate'); data_generate_default_template($data, 'addtemplate'); data_generate_default_template($data, 'asearchtemplate'); //Template for advanced searches. data_generate_default_template($data, 'rsstemplate');
/** * Test the template updated event. * * There is no external API for updating a template, so the unit test will simply create * and trigger the event and ensure the legacy log data is returned as expected. */ public function test_template_updated() { // Create a course we are going to add a data module to. $course = $this->getDataGenerator()->create_course(); // The generator used to create a data module. $generator = $this->getDataGenerator()->get_plugin_generator('mod_data'); // Create a data module. $data = $generator->create_instance(array('course' => $course->id)); // Trigger an event for updating this record. $event = \mod_data\event\template_updated::create(array('context' => context_module::instance($data->cmid), 'courseid' => $course->id, 'other' => array('dataid' => $data->id))); // Trigger and capture the event for updating the data record. $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $event = reset($events); // Check that the event data is valid. $this->assertInstanceOf('\\mod_data\\event\\template_updated', $event); $this->assertEquals(context_module::instance($data->cmid), $event->get_context()); $expected = array($course->id, 'data', 'templates saved', 'templates.php?id=' . $data->cmid . '&d=' . $data->id, $data->id, $data->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); $url = new moodle_url('/mod/data/templates.php', array('d' => $data->id)); $this->assertEquals($url, $event->get_url()); }