MDL-59528 core: Add option to display fullname beside user picture
authorJun Pataleta <jun@moodle.com>
Tue, 18 Jul 2017 09:11:59 +0000 (17:11 +0800)
committerJun Pataleta <jun@moodle.com>
Fri, 21 Jul 2017 00:45:31 +0000 (08:45 +0800)
lib/outputcomponents.php
lib/outputrenderers.php
lib/upgrade.txt

index a1be437..e237ba5 100644 (file)
@@ -201,6 +201,11 @@ class user_picture implements renderable {
      */
     public $visibletoscreenreaders = true;
 
+    /**
+     * @var bool Whether to include the fullname in the user picture link.
+     */
+    public $includefullname = false;
+
     /**
      * User picture constructor.
      *
index 139e6f9..08e917b 100644 (file)
@@ -2368,6 +2368,7 @@ class core_renderer extends renderer_base {
      *     - alttext=true (add image alt attribute)
      *     - class = image class attribute (default 'userpicture')
      *     - visibletoscreenreaders=true (whether to be visible to screen readers)
+     *     - includefullname=false (whether to include the user's full name together with the user picture)
      * @return string HTML fragment
      */
     public function user_picture(stdClass $user, array $options = null) {
@@ -2425,6 +2426,11 @@ class core_renderer extends renderer_base {
         // get the image html output fisrt
         $output = html_writer::empty_tag('img', $attributes);
 
+        // Show fullname together with the picture when desired.
+        if ($userpicture->includefullname) {
+            $output .= fullname($userpicture->user);
+        }
+
         // then wrap it in link if needed
         if (!$userpicture->link) {
             return $output;
index 58881af..ef21b43 100644 (file)
@@ -24,6 +24,7 @@ information provided here is intended especially for developers.
   used to perform implicit validation of submitted values - without the need to explicitly add the validation rules to
   every form. The method should accept a single parameter with the submitted value. It should return a string with the
   eventual validation error, or an empty value if the validation passes.
+* New user_picture attribute $includefullname to determine whether to include the user's full name with the user's picture.
 
 === 3.3.1 ===