MDL-65034 mod_forum: fix author for single discussion forum
authorRyan Wyllie <ryan@ryanwyllie.com>
Tue, 16 Apr 2019 02:51:43 +0000 (10:51 +0800)
committerRyan Wyllie <ryan@ryanwyllie.com>
Tue, 16 Apr 2019 02:51:43 +0000 (10:51 +0800)
mod/forum/classes/local/factories/renderer.php
mod/forum/lang/en/forum.php
mod/forum/templates/forum_discussion_post.mustache

index 20ca972..75c39a3 100644 (file)
@@ -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;
index 5a68c9b..0d40c17 100644 (file)
@@ -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.';
index 3349618..aeb91bb 100644 (file)
@@ -45,9 +45,9 @@
         aria-label='{{#str}} postbyuser, mod_forum, {"post": "{{subject}}", "user": "{{author.fullname}}"} {{/str}}'
     >
         {{#isfirstunread}}<a id="unread" aria-hidden="true"></a>{{/isfirstunread}}
-        <div style="width: 45px;">
-            {{^isdeleted}}
-                {{#author}}
+        {{^isdeleted}}
+            {{#author}}
+                <div style="width: 45px;">
                     {{#urls.profileimage}}
                         <img
                             class="rounded-circle w-100"
                         >
                     {{/urls.profileimage}}
                     {{#groups}}
-                        <img
-                            class="rounded-circle w-100"
-                            src="{{{urls.image}}}"
-                            alt="{{#str}} pictureof, core, {{name}} {{/str}}"
-                        >
+                        {{#urls.image}}
+                            <img
+                                class="rounded-circle w-100"
+                                src="{{{.}}}"
+                                alt="{{#str}} pictureof, core, {{name}} {{/str}}"
+                            >
+                        {{/urls.image}}
                     {{/groups}}
-                {{/author}}
-            {{/isdeleted}}
-        </div>
+                </div>
+            {{/author}}
+        {{/isdeleted}}
 
         <div class="d-flex flex-column ml-2 w-100">
             <header id="post-header-{{id}}" class="mb-2 header row">
                 <h3 class="h6 font-weight-bold mb-0">{{$subject}}{{{subject}}}{{/subject}}</h3>
                 {{^isdeleted}}
                     <address tabindex="-1">
-                        {{{html.authorsubheading}}}
+                        {{#html.authorsubheading}}{{{.}}}{{/html.authorsubheading}}
+                        {{^html.authorsubheading}}
+                            <time>
+                                {{#userdate}} {{timecreated}}, {{#str}} strftimedaydatetime, core_langconfig {{/str}} {{/userdate}}
+                            </time>
+                        {{/html.authorsubheading}}
                     </address>
                 {{/isdeleted}}
                 {{#isprivatereply}}
                                         href="{{{urls.view}}}"
                                         class="btn btn-link"
                                         title="{{#str}} permanentlinktopost, mod_forum {{/str}}"
+                                        role="menuitem"
                                     >
                                         {{#str}} permalink, mod_forum {{/str}}
                                     </a>
                                             data-region="post-action"
                                             href="{{{urls.markasread}}}"
                                             class="btn btn-link"
+                                            role="menuitem"
                                         >
                                             {{#str}} markread, mod_forum {{/str}}
                                         </a>
                                             data-region="post-action"
                                             href="{{{urls.markasunread}}}"
                                             class="btn btn-link"
+                                            role="menuitem"
                                         >
                                             {{#str}} markunread, mod_forum {{/str}}
                                         </a>
                                         href="{{{.}}}"
                                         class="btn btn-link"
                                         title="{{#str}} permanentlinktoparentpost, mod_forum {{/str}}"
+                                        role="menuitem"
                                     >
                                         {{#str}} parent, mod_forum {{/str}}
                                     </a>
                                         data-region="post-action"
                                         href="{{{urls.edit}}}"
                                         class="btn btn-link"
+                                        role="menuitem"
                                     >
                                         {{#str}} edit, mod_forum {{/str}}
                                     </a>
                                         data-region="post-action"
                                         href="{{{urls.split}}}"
                                         class="btn btn-link"
+                                        role="menuitem"
                                     >
                                         {{#str}} prune, mod_forum {{/str}}
                                     </a>
                                         data-region="post-action"
                                         href="{{{urls.delete}}}"
                                         class="btn btn-link"
+                                        role="menuitem"
                                     >
                                         {{#str}} delete, mod_forum {{/str}}
                                     </a>
                                             data-region="post-action"
                                             href="{{{urls.reply}}}"
                                             class="btn btn-link"
+                                            role="menuitem"
                                         >
                                             {{#str}} reply, mod_forum {{/str}}
                                         </a>
                                         data-region="post-action"
                                         href="{{{urls.export}}}"
                                         class="btn btn-link"
+                                        role="menuitem"
                                     >
                                         {{#str}} addtoportfolio, core_portfolio {{/str}}
                                     </a>