From 9c3e3a904be73b0d78aab6ba8a63d4dbb0862b72 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 17 Jun 2019 11:57:02 +0800 Subject: [PATCH] MDL-65469 mod_forum: Use the formchange checker initializer --- mod/forum/post.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mod/forum/post.php b/mod/forum/post.php index ec2fa052275..0cf58cd62de 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -35,6 +35,8 @@ $name = optional_param('name', '', PARAM_CLEAN); $confirm = optional_param('confirm', 0, PARAM_INT); $groupid = optional_param('groupid', null, PARAM_INT); $subject = optional_param('subject', '', PARAM_TEXT); + +// Values posted via the inpage reply form. $prefilledpost = optional_param('post', '', PARAM_TEXT); $prefilledpostformat = optional_param('postformat', FORMAT_MOODLE, PARAM_INT); $prefilledprivatereply = optional_param('privatereply', false, PARAM_BOOL); @@ -778,6 +780,25 @@ $mformpost->set_data( (isset($discussion->id) ? array('discussion' => $discussion->id) : array()) ); +// If we are being redirected via a no_submit_button press OR if the message is being prefilled. +// then set the initial 'dirty' state. +// - A prefilled post will exist when being redirected from the inpage reply form. +// - A no_submit_button press occurs when being redirected from the inpage add new discussion post form. +$dirty = $prefilledpost ? true : false; +if ($mformpost->no_submit_button_pressed()) { + $data = $mformpost->get_submitted_data(); + + // If a no submit button has been pressed but the default values haven't been then reset the form change. + if (!$dirty && !empty(trim($data->message['text']))) { + $dirty = true; + } + + if (!$dirty && !empty(trim($data->message['message']))) { + $dirty = true; + } +} +$mformpost->set_initial_dirty_state($dirty); + if ($mformpost->is_cancelled()) { if (!isset($discussion->id) || $forum->type === 'single') { // Single forums don't have a discussion page.