MDL-55656 theme_noname: Include advanced and required field markup
authorDamyon Wiese <damyon@moodle.com>
Mon, 22 Aug 2016 04:22:21 +0000 (12:22 +0800)
committerDan Poltawski <dan@moodle.com>
Fri, 23 Sep 2016 09:53:56 +0000 (10:53 +0100)
The new form elements were not including the markup for advanced
and required fields. I used an <abbr> tag in the label to give
and accessible indication of the advanced and required fields.

Part of MDL-55071

lib/form/group.php
lib/formslib.php
lib/outputrenderers.php
theme/noname/templates/core_form/element-template-inline.mustache
theme/noname/templates/core_form/element-template.mustache

index c19b31b..b060948 100644 (file)
@@ -178,7 +178,7 @@ class MoodleQuickForm_group extends HTML_QuickForm_group implements templatable
                 }
             }
 
-            $out = $OUTPUT->mform_element($element, false, '', true);
+            $out = $OUTPUT->mform_element($element, false, false, '', true);
 
             if (empty($out)) {
                 $renderer = new HTML_QuickForm_Renderer_Default();
index 51ca7b7..e8d9009 100644 (file)
@@ -2774,8 +2774,9 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
 
         // Update the ID.
         $group->updateAttributes(array('id' => $groupid));
+        $advanced = isset($this->_advancedElements[$group->getName()]);
 
-        $html = $OUTPUT->mform_element($group, $required, $error, false);
+        $html = $OUTPUT->mform_element($group, $required, $advanced, $error, false);
         $fromtemplate = !empty($html);
         if (!$fromtemplate) {
             if (method_exists($group, 'getElementTemplateType')) {
@@ -2833,8 +2834,9 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
 
         // Make sure the element has an id.
         $element->_generateId();
+        $advanced = isset($this->_advancedElements[$element->getName()]);
 
-        $html = $OUTPUT->mform_element($element, $required, $error, false);
+        $html = $OUTPUT->mform_element($element, $required, $advanced, $error, false);
         $fromtemplate = !empty($html);
         if (!$fromtemplate) {
             // Adding stuff to place holders in template
index d2fefd7..cd203f1 100644 (file)
@@ -4426,11 +4426,12 @@ EOD;
      *
      * @param HTML_QuickForm_element $element element
      * @param bool $required if input is required field
+     * @param bool $advanced if input is an advanced field
      * @param string $error error message to display
      * @param bool $ingroup True if this element is rendered as part of a group
      * @return mixed string|bool
      */
-    public function mform_element($element, $required, $error, $ingroup) {
+    public function mform_element($element, $required, $advanced, $error, $ingroup) {
         $templatename = 'core_form/element-' . $element->getType();
         if ($ingroup) {
             $templatename .= "-inline";
@@ -4456,6 +4457,7 @@ EOD;
                     'element' => $elementcontext,
                     'label' => $label,
                     'required' => $required,
+                    'advanced' => $advanced,
                     'helpbutton' => $helpbutton,
                     'error' => $error
                 );
index 08751af..bc20a80 100644 (file)
@@ -1,6 +1,8 @@
-<div class="form-group {{#error}}has-danger{{/error}} fitem">
+<div class="form-group {{#error}}has-danger{{/error}} fitem {{#advanced}}advanced{{/advanced}}">
     <label class="col-form-label {{#element.hiddenlabel}}sr-only{{/element.hiddenlabel}}" for="{{element.id}}">
         {{{label}}} {{{helpbutton}}}
+        {{#required}}<abbr class="initialism text-danger" title="{{#str}}required{{/str}}">✲</abbr>{{/required}}
+        {{#advanced}}<abbr class="initialism text-info" title="{{#str}}advanced{{/str}}">❗</abbr>{{/advanced}}
     </label>
         {{$ element }}
             <!-- Element goes here -->
index d6e9652..1411c42 100644 (file)
@@ -1,6 +1,11 @@
-<div class="form-group row {{#error}}has-danger{{/error}} fitem">
+<div class="form-group row {{#error}}has-danger{{/error}} fitem {{#advanced}}advanced{{/advanced}}">
     <label class="col-md-3 col-form-label {{#element.hiddenlabel}}sr-only{{/element.hiddenlabel}}" for="{{element.id}}">
-        {{{label}}} {{{helpbutton}}}
+        {{{label}}}
+        <span class="pull-xs-right">
+        {{{helpbutton}}}
+        {{#required}}<abbr class="initialism text-danger" title="{{#str}}required{{/str}}">✲</abbr>{{/required}}
+        {{#advanced}}<abbr class="initialism text-info" title="{{#str}}advanced{{/str}}">❗</abbr>{{/advanced}}
+        </span>
     </label>
     <div class="col-md-9 form-inline felement">
         {{$ element }}