Skip to content

Commit e4a3e0f

Browse files
authored
Merge pull request #250 from srobotta/hide_subject_in_reply
Subjects make sense for new discussions only, not in replies.
2 parents 52fe004 + 46e51e2 commit e4a3e0f

File tree

7 files changed

+13
-17
lines changed

7 files changed

+13
-17
lines changed

classes/post/post_control.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,6 @@ private function build_prepost_reply(int $replypostid): void {
265265
throw new moodle_exception('activityiscurrentlyhidden');
266266
}
267267

268-
// Append 'RE: ' to the discussions subject.
269-
$strre = get_string('re', 'moodleoverflow');
270-
if (!(str_starts_with($this->prepost->subject, $strre))) {
271-
$this->prepost->subject = $strre . ' ' . $this->prepost->subject;
272-
}
273-
274268
// Unset where the user is coming from.
275269
// Allows to calculate the correct return url later.
276270
unset($SESSION->fromdiscussion);

classes/post_form.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ public function definition() {
5151
// Fill in the data depending on page params later using set_data.
5252
$modform->addElement('header', 'general', '');
5353

54-
// The subject.
55-
$modform->addElement('text', 'subject', get_string('subject', 'moodleoverflow'), 'size="48"');
56-
$modform->setType('subject', PARAM_TEXT);
57-
$modform->addRule('subject', get_string('required'), 'required', null, 'client');
58-
$modform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
54+
// Show the subject only when this is a new post.
55+
if (empty($post->parentid)) {
56+
$modform->addElement('text', 'subject', get_string('subject', 'moodleoverflow'), 'size="48"');
57+
$modform->setType('subject', PARAM_TEXT);
58+
$modform->addRule('subject', get_string('required'), 'required', null, 'client');
59+
$modform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
60+
}
5961

6062
// The message.
6163
$modform->addElement(
@@ -125,7 +127,8 @@ public function validation($data, $files) {
125127
if (empty($data['message']['text'])) {
126128
$errors['message'] = get_string('erroremptymessage', 'moodleoverflow');
127129
}
128-
if (empty($data['subject'])) {
130+
// Subject must not be empty when creating a new discussion only.
131+
if (empty($data['subject']) && empty($this->_customdata['post']->parentid)) {
129132
$errors['subject'] = get_string('erroremptysubject', 'moodleoverflow');
130133
}
131134

tests/behat/delete_file.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Feature: Delete attachments
2222
And I follow "Forum post 1"
2323
And I click on "Answer" "link"
2424
And I set the following fields to these values:
25-
| Subject | A reply post |
2625
| Message | This is the message of the answer post |
2726
And I upload "mod/moodleoverflow/tests/fixtures/NH.jpg" file to "Attachment" filemanager
2827
And I press "Post to forum"

tests/behat/delete_post.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Feature: Teachers and students can delete posts
2727
And I log out
2828
And I navigate as "student1" to "Course 1" "Moodleoverflow 1" "Discussion 1"
2929
And I try to delete moodleoverflow post "Answer from student"
30-
Then I should see "You are not allowed to delete this post because it already has replies."
30+
Then I should see "You are not allowed to delete this post because it already has replies."

tests/behat/limitedanswer.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Feature: Moodleoverflows can start in a limited answer mode, where answers from
2727
And I click on "Answer" "text"
2828
Then I should see "Your reply"
2929
And I set the following fields to these values:
30-
| Subject | Re: Forum post 1 |
3130
| Message | This is the answer message |
3231
And I press "Post to forum"
3332
Then I should "" see the elements:

tests/behat/reply_post.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ Feature: Replying to posts in a moodleoverflow
99
When I click on "#moodleoverflow_showpost" "css_element"
1010
Then I should see "Message from teacher"
1111
When I click on "#moodleoverflow_showpost" "css_element"
12-
Then I should not see "Message from teacher"
12+
Then I should not see "Message from teacher"
13+
And I should not see "Subject"
14+
And I should see "Message"

tests/behat/track_read_posts.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,3 @@ Feature: A teacher can set one of 3 possible options for tracking read moodleove
8080
When I click on "Mark all posts as read" "link"
8181
And I am on "Course 1" course homepage
8282
Then I should not see "2 unread post"
83-

0 commit comments

Comments
 (0)