MDL-40759 icons: Fix icons in action menus and links
authorDamyon Wiese <damyon@moodle.com>
Fri, 20 Jan 2017 06:56:28 +0000 (14:56 +0800)
committerDamyon Wiese <damyon@moodle.com>
Fri, 17 Mar 2017 07:51:29 +0000 (15:51 +0800)
Always use the pix icon helper in templates.

lib/classes/output/icon_system.php
lib/classes/output/mustache_pix_helper.php
lib/outputcomponents.php
lib/templates/action_link.mustache
lib/templates/action_menu_item.mustache
lib/templates/action_menu_link.mustache
lib/templates/action_menu_trigger.mustache
theme/boost/classes/output/core_renderer.php
theme/boost/templates/core/action_menu_item.mustache
theme/boost/templates/core/action_menu_link.mustache
theme/boost/templates/core/action_menu_trigger.mustache

index 9615e9d..e8b1211 100644 (file)
@@ -109,7 +109,7 @@ abstract class icon_system {
         if ($this->map === null) {
             $this->map = $this->get_icon_name_map();
         }
-        if ($component == null) {
+        if ($component == null || $component == 'moodle') {
             $component = 'core';
         } else if ($component != 'theme') {
             $component = \core_component::normalize_componentname($component);
index 3b0d261..cc07f33 100644 (file)
@@ -63,11 +63,13 @@ class mustache_pix_helper {
         // Split the text into an array of variables.
         $key = strtok($text, ",");
         $key = trim($key);
+        $key = $helper->render($key);
         $component = strtok(",");
         $component = trim($component);
         if (!$component) {
             $component = '';
         }
+        $component = $helper->render($component);
         $text = strtok("");
         // Allow mustache tags in the last argument.
         $text = $helper->render($text);
index 2ef36e4..6f93fa5 100644 (file)
@@ -626,11 +626,6 @@ class pix_icon implements renderable, templatable {
      */
     var $attributes = array();
 
-    /**
-     * @var bool True if this is a font-awesome icon.
-     */
-    protected $fontawesome;
-
     /**
      * Constructor
      *
@@ -703,6 +698,24 @@ class pix_icon implements renderable, templatable {
 
         return $data;
     }
+
+    /**
+     * Much simpler version of export that will produce the data required to render this pix with the
+     * pix helper in a mustache tag.
+     *
+     * @return array
+     */
+    public function export_for_pix() {
+        $title = isset($this->attributes['title']) ? $this->attributes['title'] : '';
+        if (empty($title)) {
+            $title = isset($this->attributes['alt']) ? $this->attributes['alt'] : '';
+        }
+        return [
+            'key' => $this->pix,
+            'component' => $this->component,
+            'title' => $title
+        ];
+    }
 }
 
 /**
@@ -1509,7 +1522,7 @@ class action_link implements renderable {
 
         $data->text = $this->text instanceof renderable ? $output->render($this->text) : (string) $this->text;
         $data->url = $this->url ? $this->url->out(false) : '';
-        $data->icon = $this->icon ? $this->icon->export_for_template($output) : null;
+        $data->icon = $this->icon ? $this->icon->export_for_pix() : null;
         $data->classes = isset($attributes['class']) ? $attributes['class'] : '';
         unset($attributes['class']);
 
@@ -4295,7 +4308,7 @@ class action_menu implements renderable, templatable {
         }
 
         if ($actionicon instanceof pix_icon) {
-            $primary->icon = $actionicon->export_for_template($output);
+            $primary->icon = $actionicon->export_for_pix();
             $primary->title = !empty($actionicon->attributes['alt']) ? $this->actionicon->attributes['alt'] : '';
         } else {
             $primary->iconraw = $actionicon ? $output->render($actionicon) : '';
@@ -4451,7 +4464,7 @@ class action_menu_link extends action_link implements renderable {
                     unset($icon->attributes['title']);
                 }
             }
-            $data->icon = $icon ? $icon->export_for_template($output) : null;
+            $data->icon = $icon ? $icon->export_for_pix() : null;
         }
 
         $data->disabled = !empty($attributes['disabled']);
index 11617bc..0616c63 100644 (file)
     }
 }}
 {{^disabled}}
-    <a href="{{{url}}}" id="{{id}}" class="{{classes}}"{{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}}{{/attributes}}>{{#icon}}{{>core/pix_icon}}{{/icon}}{{{text}}}</a>
+    <a href="{{{url}}}" id="{{id}}" class="{{classes}}" {{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}} {{/attributes}}>{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{{text}}}</a>
     {{#hasactions}}
         {{> core/actions }}
     {{/hasactions}}
 {{/disabled}}
 {{#disabled}}
-    <span class="currentlink {{classes}}"{{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}}{{/attributes}}>{{#icon}}{{>core/pix_icon}}{{/icon}}{{{text}}}</span>
+    <span class="currentlink {{classes}}" {{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}} {{/attributes}}>{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{{text}}}</span>
 {{/disabled}}
index bbbf864..a2d00da 100644 (file)
@@ -27,5 +27,5 @@
 {{#actionmenulink}}{{> core/action_menu_link }}{{/actionmenulink}}
 {{#actionmenufiller}}<span class="filler">&nbsp;</span>{{/actionmenufiller}}
 {{#actionlink}}{{> core/action_link }}{{/actionlink}}
-{{#pixicon}}{{> core/pix_icon }}{{/pixicon}}
-{{#rawhtml}}{{{.}}}{{/rawhtml}}
\ No newline at end of file
+{{#pixicon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/pixicon}}
+{{#rawhtml}}{{{.}}}{{/rawhtml}}
index d8d3462..ade499f 100644 (file)
@@ -29,8 +29,8 @@
     }
 }}
 {{^disabled}}
-    <a href="{{url}}" class="{{classes}}"{{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}}{{/attributes}} {{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>{{#icon}}{{>core/pix_icon}}{{/icon}}{{#showtext}}<span class="menu-action-text" id="actionmenuaction-{{instance}}">{{{text}}}</span>{{/showtext}}</a>
+    <a href="{{url}}" class="{{classes}}" {{#attributes}}{{name}}={{#quote}}{{value}}{{/quote}}{{/attributes}} {{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{#showtext}}<span class="menu-action-text" id="actionmenuaction-{{instance}}">{{{text}}}</span>{{/showtext}}</a>
 {{/disabled}}
 {{#disabled}}
-    <span class="currentlink" role="menuitem">{{#icon}}{{>core/pix_icon}}{{/icon}}{{{text}}}</span>
+    <span class="currentlink" role="menuitem">{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{{text}}}</span>
 {{/disabled}}
index 2068373..9328510 100644 (file)
@@ -26,4 +26,4 @@
         "menutrigger": true
     }
 }}
-<a href="#" class="toggle-display {{#menutrigger}}textmenu{{/menutrigger}}" id="action-menu-toggle-{{instance}}" title="{{title}}" role="menuitem">{{{actiontext}}}{{{menutrigger}}}{{#icon}}{{> core/pix_icon}}{{/icon}}{{#rawicon}}{{{.}}}{{/rawicon}}{{#menutrigger}}<b class="caret"></b>{{/menutrigger}}</a>
\ No newline at end of file
+<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>
index ada3c09..4e5835e 100644 (file)
@@ -406,20 +406,6 @@ class core_renderer extends \core_renderer {
         }
         $context = $menu->export_for_template($this);
 
-        // We do not want the icon with the caret, the caret is added by Bootstrap.
-        if (empty($context->primary->menutrigger)) {
-            $newurl = $this->pix_url('t/edit', 'moodle');
-            $context->primary->icon['attributes'] = array_reduce($context->primary->icon['attributes'],
-                function($carry, $item) use ($newurl) {
-                    if ($item['name'] === 'src') {
-                        $item['value'] = $newurl->out(false);
-                    }
-                    $carry[] = $item;
-                    return $carry;
-                }, []
-            );
-        }
-
         return $this->render_from_template('core/action_menu', $context);
     }
 
index bbbf864..a2d00da 100644 (file)
@@ -27,5 +27,5 @@
 {{#actionmenulink}}{{> core/action_menu_link }}{{/actionmenulink}}
 {{#actionmenufiller}}<span class="filler">&nbsp;</span>{{/actionmenufiller}}
 {{#actionlink}}{{> core/action_link }}{{/actionlink}}
-{{#pixicon}}{{> core/pix_icon }}{{/pixicon}}
-{{#rawhtml}}{{{.}}}{{/rawhtml}}
\ No newline at end of file
+{{#pixicon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/pixicon}}
+{{#rawhtml}}{{{.}}}{{/rawhtml}}
index 34108f7..4a96ccd 100644 (file)
@@ -27,8 +27,8 @@
     }
 }}
 {{^disabled}}
-    <a href="{{url}}" class="{{classes}}"{{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}}{{/attributes}} {{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>{{#icon}}{{>core/pix_icon}}{{/icon}}{{#showtext}}<span class="menu-action-text" id="actionmenuaction-{{instance}}">{{{text}}}</span>{{/showtext}}</a>
+    <a href="{{url}}" class="{{classes}}" {{#attributes}}{{name}}={{#quote}}{{value}}{{/quote}}{{/attributes}} {{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{#showtext}}<span class="menu-action-text" id="actionmenuaction-{{instance}}">{{{text}}}</span>{{/showtext}}</a>
 {{/disabled}}
 {{#disabled}}
-    <span class="currentlink" role="menuitem">{{#icon}}{{>core/pix_icon}}{{/icon}}{{{text}}}</span>
+    <span class="currentlink" role="menuitem">{{#icon}}{{#pix}}{{key}},{{component}},{{title}}{{/pix}}{{/icon}}{{{text}}}</span>
 {{/disabled}}
index f785cb5..e6de51a 100644 (file)
 {{!
     Action menu trigger.
 }}
-<div class="dropdown">
-    <a href="#" class="dropdown-toggle" id="action-menu-toggle-{{instance}}" title="{{title}}" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{{actiontext}}}{{{menutrigger}}}{{#icon}}{{> core/pix_icon}}{{/icon}}{{#rawicon}}{{{.}}}{{/rawicon}}{{#menutrigger}}<b class="caret"></b>{{/menutrigger}}</a>
+<span class="dropdown">
+    <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>
     {{#secondary}}
         <div class="dropdown-menu dropdown-menu-right {{classes}}"{{#attributes}} {{name}}="{{value}}"{{/attributes}}>
             {{#items}}{{!
-                }}{{#actionmenulink}}<a href="{{url}}" class="dropdown-item {{classes}}"{{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}}{{/attributes}} {{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>{{#icon}}{{>core/pix_icon}}{{/icon}}{{#showtext}}<span class="menu-action-text" id="actionmenuaction-{{instance}}">{{{text}}}</span>{{/showtext}}</a>{{/actionmenulink}}{{!
+                }}{{#actionmenulink}}<a href="{{url}}" class="dropdown-item {{classes}}" {{#attributes}}{{name}}={{#quote}}{{value}}{{/quote}}{{/attributes}} {{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>{{#icon}}{{#pix}}{{key}},{{component}},{{title}}{{/pix}}{{/icon}}{{#showtext}}<span class="menu-action-text" id="actionmenuaction-{{instance}}">{{{text}}}</span>{{/showtext}}</a>{{/actionmenulink}}{{!
                 }}{{#actionmenufiller}}<div class="dropdown-divider"></div>{{/actionmenufiller}}{{!
                 }}{{^actionmenulink}}{{^actionmenufiller}}<div class="dropdown-item">{{> core/action_menu_item }}</div>{{/actionmenufiller}}{{/actionmenulink}}{{!
             }}{{/items}}