From 8dbe7699882ea525c1d81db281b92b5bdf72a965 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Tue, 16 Apr 2019 10:51:43 +0800 Subject: [PATCH] MDL-65034 mod_forum: fix author for single discussion forum --- .../classes/local/factories/renderer.php | 9 ++++- mod/forum/lang/en/forum.php | 1 + .../templates/forum_discussion_post.mustache | 40 +++++++++++++------ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/mod/forum/classes/local/factories/renderer.php b/mod/forum/classes/local/factories/renderer.php index 20ca972a429..75c39a3153e 100644 --- a/mod/forum/classes/local/factories/renderer.php +++ b/mod/forum/classes/local/factories/renderer.php @@ -193,6 +193,7 @@ class renderer { if ($forum->get_type() == 'single' && !$exportedpost->hasparent) { // Remove the author from any posts that don't have a parent. unset($exportedpost->author); + unset($exportedpost->html['authorsubheading']); } $exportedpost->firstpost = false; @@ -221,7 +222,13 @@ class renderer { // Set the parent author name on the replies. This is used for screen // readers to help them identify the structure of the discussion. $sortedreplies = array_map(function($reply) use ($post) { - $reply->parentauthorname = $post->author->fullname; + if (isset($post->author)) { + $reply->parentauthorname = $post->author->fullname; + } else { + // The only time the author won't be set is for a single discussion + // forum. See above for where it gets unset. + $reply->parentauthorname = get_string('firstpost', 'mod_forum'); + } return $reply; }, $sortedreplies); $post->replies = $sortedreplies; diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 5a68c9b9bd2..0d40c174bcc 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -229,6 +229,7 @@ $string['everyoneissubscribed'] = 'Everyone is subscribed to this forum'; $string['existingsubscribers'] = 'Existing subscribers'; $string['exportdiscussion'] = 'Export whole discussion to portfolio'; $string['exportattachmentname'] = 'Export attachment {$a} to portfolio'; +$string['firstpost'] = 'First post'; $string['forcedreadtracking'] = 'Allow forced read tracking'; $string['forcedreadtracking_desc'] = 'Allows forums to be set to forced read tracking. Will result in decreased performance for some users, particularly on courses with many forums and posts. When off, any forums previously set to Forced are treated as optional.'; $string['forcesubscribed_help'] = 'This forum has been configured so that you cannot unsubscribe from discussions.'; diff --git a/mod/forum/templates/forum_discussion_post.mustache b/mod/forum/templates/forum_discussion_post.mustache index 33496180f58..aeb91bb180a 100644 --- a/mod/forum/templates/forum_discussion_post.mustache +++ b/mod/forum/templates/forum_discussion_post.mustache @@ -45,9 +45,9 @@ aria-label='{{#str}} postbyuser, mod_forum, {"post": "{{subject}}", "user": "{{author.fullname}}"} {{/str}}' > {{#isfirstunread}}{{/isfirstunread}} -
- {{^isdeleted}} - {{#author}} + {{^isdeleted}} + {{#author}} +
{{#urls.profileimage}} {{/urls.profileimage}} {{#groups}} - {{#str}} pictureof, core, {{name}} {{/str}} + {{#urls.image}} + {{#str}} pictureof, core, {{name}} {{/str}} + {{/urls.image}} {{/groups}} - {{/author}} - {{/isdeleted}} -
+
+ {{/author}} + {{/isdeleted}}
@@ -75,7 +77,12 @@

{{$subject}}{{{subject}}}{{/subject}}

{{^isdeleted}}
- {{{html.authorsubheading}}} + {{#html.authorsubheading}}{{{.}}}{{/html.authorsubheading}} + {{^html.authorsubheading}} + + {{/html.authorsubheading}}
{{/isdeleted}} {{#isprivatereply}} @@ -159,6 +166,7 @@ href="{{{urls.view}}}" class="btn btn-link" title="{{#str}} permanentlinktopost, mod_forum {{/str}}" + role="menuitem" > {{#str}} permalink, mod_forum {{/str}} @@ -169,6 +177,7 @@ data-region="post-action" href="{{{urls.markasread}}}" class="btn btn-link" + role="menuitem" > {{#str}} markread, mod_forum {{/str}} @@ -178,6 +187,7 @@ data-region="post-action" href="{{{urls.markasunread}}}" class="btn btn-link" + role="menuitem" > {{#str}} markunread, mod_forum {{/str}} @@ -189,6 +199,7 @@ href="{{{.}}}" class="btn btn-link" title="{{#str}} permanentlinktoparentpost, mod_forum {{/str}}" + role="menuitem" > {{#str}} parent, mod_forum {{/str}} @@ -198,6 +209,7 @@ data-region="post-action" href="{{{urls.edit}}}" class="btn btn-link" + role="menuitem" > {{#str}} edit, mod_forum {{/str}} @@ -207,6 +219,7 @@ data-region="post-action" href="{{{urls.split}}}" class="btn btn-link" + role="menuitem" > {{#str}} prune, mod_forum {{/str}} @@ -216,6 +229,7 @@ data-region="post-action" href="{{{urls.delete}}}" class="btn btn-link" + role="menuitem" > {{#str}} delete, mod_forum {{/str}} @@ -226,6 +240,7 @@ data-region="post-action" href="{{{urls.reply}}}" class="btn btn-link" + role="menuitem" > {{#str}} reply, mod_forum {{/str}} @@ -236,6 +251,7 @@ data-region="post-action" href="{{{urls.export}}}" class="btn btn-link" + role="menuitem" > {{#str}} addtoportfolio, core_portfolio {{/str}}