MDL-61620 output: New action_menu options
authorDavid Monllao <davidm@moodle.com>
Thu, 8 Mar 2018 17:27:46 +0000 (18:27 +0100)
committerDavid Monllao <davidm@moodle.com>
Wed, 14 Mar 2018 10:38:08 +0000 (11:38 +0100)
lib/outputcomponents.php
lib/templates/action_menu_trigger.mustache
theme/boost/templates/core/action_menu_trigger.mustache

index c696d60..db773a6 100644 (file)
@@ -4139,6 +4139,12 @@ class action_menu implements renderable, templatable {
      */
     public $menutrigger = '';
 
+    /**
+     * Any extra classes for toggling to the secondary menu.
+     * @var triggerextraclasses
+     */
+    public $triggerextraclasses = '';
+
     /**
      * Place the action menu before all other actions.
      * @var prioritise
@@ -4178,8 +4184,16 @@ class action_menu implements renderable, templatable {
         }
     }
 
-    public function set_menu_trigger($trigger) {
+    /**
+     * Sets the menu trigger text.
+     *
+     * @param string $trigger The text
+     * @param string $extraclasses Extra classes to style the secondary menu toggle.
+     * @return null
+     */
+    public function set_menu_trigger($trigger, $extraclasses = '') {
         $this->menutrigger = $trigger;
+        $this->triggerextraclasses = $extraclasses;
     }
 
     /**
@@ -4457,6 +4471,7 @@ class action_menu implements renderable, templatable {
         $actionicon = $this->actionicon;
         if (!empty($this->menutrigger)) {
             $primary->menutrigger = $this->menutrigger;
+            $primary->triggerextraclasses = $this->triggerextraclasses;
         } else {
             $primary->title = get_string('actions');
             $actionicon = new pix_icon('t/edit_menu', '', 'moodle', ['class' => 'iconsmall actionmenu', 'title' => '']);
index 9328510..fce1a8b 100644 (file)
@@ -23,7 +23,8 @@
     {
         "instance": "1",
         "title": "Trigger me!",
-        "menutrigger": true
+        "menutrigger": true,
+        "triggerextraclasses": ""
     }
 }}
-<a href="#" class="toggle-display {{#menutrigger}}textmenu{{/menutrigger}}" id="action-menu-toggle-{{instance}}" title="{{title}}" role="menuitem">{{{actiontext}}}{{{menutrigger}}}{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{#rawicon}}{{{.}}}{{/rawicon}}{{#menutrigger}}<b class="caret"></b>{{/menutrigger}}</a>
+<a href="#" class="{{triggerextraclasses}} toggle-display {{#menutrigger}}textmenu{{/menutrigger}}" id="action-menu-toggle-{{instance}}" title="{{title}}" role="menuitem">{{{actiontext}}}{{{menutrigger}}}{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{#rawicon}}{{{.}}}{{/rawicon}}{{#menutrigger}}<b class="caret"></b>{{/menutrigger}}</a>
index 7eab503..bf68279 100644 (file)
@@ -26,6 +26,7 @@
         "url": "http://example.com/link",
         "classes": "icon menu-action",
         "instance": "1",
+        "triggerextraclasses": "",
         "attributes": [
             {"name": "role", "value": "menuitem" },
             {"name": "data-title", "value": "mymoodle,admin" }
@@ -77,7 +78,7 @@
     }
 }}
 <div class="dropdown d-inline">
-    <a href="#" class="dropdown-toggle" id="dropdown-{{instance}}" title="{{title}}" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{{actiontext}}}{{{menutrigger}}}{{#icon}}{{#pix}}{{key}},{{component}},{{title}}{{/pix}}{{/icon}}{{#rawicon}}{{{.}}}{{/rawicon}}{{#menutrigger}}<b class="caret"></b>{{/menutrigger}}</a>
+    <a href="#" class="{{triggerextraclasses}} dropdown-toggle" id="dropdown-{{instance}}" title="{{title}}" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{{actiontext}}}{{{menutrigger}}}{{#icon}}{{#pix}}{{key}},{{component}},{{title}}{{/pix}}{{/icon}}{{#rawicon}}{{{.}}}{{/rawicon}}{{#menutrigger}}<b class="caret"></b>{{/menutrigger}}</a>
     {{#secondary}}
         <div class="dropdown-menu dropdown-menu-right {{classes}}"{{#attributes}} {{name}}="{{value}}"{{/attributes}}>
             {{#items}}{{!