From 53d743741e2eadb3f808566ec01028f0aeb703bf Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Mon, 18 Mar 2019 15:14:09 +0800 Subject: [PATCH] MDL-65034 forum: add aria attributes to forum post --- mod/forum/classes/local/exporters/author.php | 16 ++- .../classes/local/factories/renderer.php | 13 +- mod/forum/lang/en/forum.php | 6 + .../templates/forum_discussion_post.mustache | 115 +++++++++++++++--- 4 files changed, 128 insertions(+), 22 deletions(-) diff --git a/mod/forum/classes/local/exporters/author.php b/mod/forum/classes/local/exporters/author.php index bd6e34d2bd8..fb648463e20 100644 --- a/mod/forum/classes/local/exporters/author.php +++ b/mod/forum/classes/local/exporters/author.php @@ -82,9 +82,22 @@ class author extends exporter { 'null' => NULL_ALLOWED ], 'groups' => [ - 'type' => group_exporter::read_properties_definition(), 'multiple' => true, 'optional' => true, + 'type' => [ + 'id' => ['type' => PARAM_INT], + 'name' => ['type' => PARAM_TEXT], + 'urls' => [ + 'type' => [ + 'image' => [ + 'type' => PARAM_URL, + 'optional' => true, + 'default' => null, + 'null' => NULL_ALLOWED + ] + ] + ] + ] ], 'urls' => [ 'type' => [ @@ -122,6 +135,7 @@ class author extends exporter { $imageurl = get_group_picture_url($group, $group->courseid); return [ 'id' => $group->id, + 'name' => $group->name, 'urls' => [ 'image' => $imageurl ? $imageurl->out(false) : null ] diff --git a/mod/forum/classes/local/factories/renderer.php b/mod/forum/classes/local/factories/renderer.php index dada4e0e4a3..20ca972a429 100644 --- a/mod/forum/classes/local/factories/renderer.php +++ b/mod/forum/classes/local/factories/renderer.php @@ -187,6 +187,7 @@ class renderer { function($exportedposts, $forums) use ($displaymode, $readonly, $exportedpostssorter) { $forum = array_shift($forums); $seenfirstunread = false; + $postcount = count($exportedposts); $exportedposts = array_map( function($exportedpost) use ($forum, $readonly, $seenfirstunread) { if ($forum->get_type() == 'single' && !$exportedpost->hasparent) { @@ -196,6 +197,7 @@ class renderer { $exportedpost->firstpost = false; $exportedpost->readonly = $readonly; + $exportedpost->hasreplycount = false; $exportedpost->hasreplies = false; $exportedpost->replies = []; @@ -215,7 +217,14 @@ class renderer { $sortintoreplies = function($nestedposts) use (&$sortintoreplies) { return array_map(function($postdata) use (&$sortintoreplies) { [$post, $replies] = $postdata; - $post->replies = $sortintoreplies($replies); + $sortedreplies = $sortintoreplies($replies); + // 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; + return $reply; + }, $sortedreplies); + $post->replies = $sortedreplies; $post->hasreplies = !empty($post->replies); return $post; }, $nestedposts); @@ -232,6 +241,8 @@ class renderer { if (!empty($exportedposts)) { // Need to identify the first post so that we can use it in behat tests. $exportedposts[0]->firstpost = true; + $exportedposts[0]->hasreplycount = true; + $exportedposts[0]->replycount = $postcount - 1; } return $exportedposts; diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 7ae8c1c2886..5a68c9b9bd2 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -39,6 +39,7 @@ $string['anyfile'] = 'Any file'; $string['areaattachment'] = 'Attachments'; $string['areapost'] = 'Messages'; $string['attachment'] = 'Attachment'; +$string['attachmentname'] = 'Attachment {$a}'; $string['attachment_help'] = 'You can optionally attach one or more files to a forum post. If you attach an image, it will be displayed after the message.'; $string['attachmentnopost'] = 'You cannot export attachments without a post id'; $string['attachments'] = 'Attachments'; @@ -227,6 +228,7 @@ $string['everyoneisnowsubscribed'] = 'Everyone is now subscribed to this forum'; $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['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.'; @@ -290,6 +292,7 @@ $string['indicator:cognitivedepth_help'] = 'This indicator is based on the cogni $string['indicator:socialbreadth'] = 'Forum social'; $string['indicator:socialbreadth_help'] = 'This indicator is based on the social breadth reached by the student in a Forum activity.'; $string['inforum'] = 'in {$a}'; +$string['inreplyto'] = 'In reply to {$a}'; $string['introblog'] = 'The posts in this forum were copied here automatically from blogs of users in this course because those blog entries are no longer available'; $string['intronews'] = 'General news and announcements'; $string['introsocial'] = 'An open forum for chatting about anything you want to'; @@ -408,6 +411,7 @@ $string['nownottracking'] = '{$a->name} is no longer tracking \'{$a->forum}\'.'; $string['nowsubscribed'] = '{$a->name} will be notified of new posts in \'{$a->forum}\''; $string['nowtracking'] = '{$a->name} is now tracking \'{$a->forum}\'.'; $string['numposts'] = '{$a} posts'; +$string['numberofreplies'] = 'Number of replies: {$a}'; $string['olderdiscussions'] = 'Older discussions'; $string['oldertopics'] = 'Older topics'; $string['oldpostdays'] = 'Read after days'; @@ -419,6 +423,8 @@ $string['page-mod-forum-discuss'] = 'Forum module discussion thread page'; $string['parent'] = 'Show parent'; $string['parentofthispost'] = 'Parent of this post'; $string['permalink'] = 'Permalink'; +$string['permanentlinktopost'] = 'Permanent link to this post'; +$string['permanentlinktoparentpost'] = 'Permanent link to the parent of this post'; $string['postisprivatereply'] = 'This post was made privately and is not visible to all users.'; $string['posttomygroups'] = 'Post a copy to all groups'; $string['posttomygroups_help'] = 'Posts a copy of this message to all groups you have access to. Participants in groups you do not have access to will not see this post'; diff --git a/mod/forum/templates/forum_discussion_post.mustache b/mod/forum/templates/forum_discussion_post.mustache index ce437f8732c..cbeff0d6a5f 100644 --- a/mod/forum/templates/forum_discussion_post.mustache +++ b/mod/forum/templates/forum_discussion_post.mustache @@ -29,32 +29,51 @@ { } }} -