mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-40759 icons: Fix icons in action menus and links
Always use the pix icon helper in templates.
This commit is contained in:
parent
c266d256e7
commit
7cf6ef7bbb
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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']);
|
||||
|
@ -52,11 +52,11 @@
|
||||
}
|
||||
}}
|
||||
{{^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}}
|
||||
|
@ -27,5 +27,5 @@
|
||||
{{#actionmenulink}}{{> core/action_menu_link }}{{/actionmenulink}}
|
||||
{{#actionmenufiller}}<span class="filler"> </span>{{/actionmenufiller}}
|
||||
{{#actionlink}}{{> core/action_link }}{{/actionlink}}
|
||||
{{#pixicon}}{{> core/pix_icon }}{{/pixicon}}
|
||||
{{#rawhtml}}{{{.}}}{{/rawhtml}}
|
||||
{{#pixicon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/pixicon}}
|
||||
{{#rawhtml}}{{{.}}}{{/rawhtml}}
|
||||
|
@ -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}}
|
||||
|
@ -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>
|
||||
<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>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -27,5 +27,5 @@
|
||||
{{#actionmenulink}}{{> core/action_menu_link }}{{/actionmenulink}}
|
||||
{{#actionmenufiller}}<span class="filler"> </span>{{/actionmenufiller}}
|
||||
{{#actionlink}}{{> core/action_link }}{{/actionlink}}
|
||||
{{#pixicon}}{{> core/pix_icon }}{{/pixicon}}
|
||||
{{#rawhtml}}{{{.}}}{{/rawhtml}}
|
||||
{{#pixicon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/pixicon}}
|
||||
{{#rawhtml}}{{{.}}}{{/rawhtml}}
|
||||
|
@ -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}}
|
||||
|
@ -17,12 +17,12 @@
|
||||
{{!
|
||||
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}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user