Files
moodle/lib/classes/output/external.php
T
Damyon Wiese a26ce2482a MDL-40759 themes: font awesome support
We add a new theme config so the theme can say it supports font-awesome.
If this is true, the pix_icon renderer will call a mapping function to map
from the moodle style t/edit to a font-awesome style fa-cog icon name. Then the renderer
will either render an image tag for old icons - or an accessible font-awesome <i> tag.

This mostly works - but there are some places where we don't use the pix icon renderer, and
we directly create image tags with pix_url image sources. These will need updating (Atto icons,
drag and drop move icons, editpdf icons).
2017-03-17 15:51:28 +08:00

148 lines
4.8 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mustache helper to load strings from string_manager.
*
* @package core
* @category output
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\output;
use external_api;
use external_function_parameters;
use external_multiple_structure;
use external_single_structure;
use external_value;
use core_component;
use moodle_exception;
use context_system;
use theme_config;
/**
* This class contains a list of webservice functions related to output.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 2.9
*/
class external extends external_api {
/**
* Returns description of load_template() parameters.
*
* @return external_function_parameters
*/
public static function load_template_parameters() {
return new external_function_parameters(
array('component' => new external_value(PARAM_COMPONENT, 'component containing the template'),
'template' => new external_value(PARAM_ALPHANUMEXT, 'name of the template'),
'themename' => new external_value(PARAM_ALPHANUMEXT, 'The current theme.'),
)
);
}
/**
* Return a mustache template, and all the strings it requires.
*
* @param string $component The component that holds the template.
* @param string $templatename The name of the template.
* @param string $themename The name of the current theme.
* @return string the template
*/
public static function load_template($component, $template, $themename) {
global $DB, $CFG, $PAGE;
$params = self::validate_parameters(self::load_template_parameters(),
array('component' => $component,
'template' => $template,
'themename' => $themename));
$component = $params['component'];
$template = $params['template'];
$themename = $params['themename'];
$templatename = $component . '/' . $template;
// Will throw exceptions if the template does not exist.
$filename = mustache_template_finder::get_template_filepath($templatename, $themename);
$templatestr = file_get_contents($filename);
return $templatestr;
}
/**
* Returns description of load_template() result value.
*
* @return external_description
*/
public static function load_template_returns() {
return new external_value(PARAM_RAW, 'template');
}
/**
* Returns description of load_fontawesome_iconmap() parameters.
*
* @return external_function_parameters
*/
public static function load_fontawesome_iconmap_parameters() {
return new external_function_parameters([]);
}
/**
* Return a mapping of icon names to icons.
*
* @return array the mapping
*/
public static function load_fontawesome_iconmap() {
$context = context_system::instance();
self::validate_context($context);
$map = theme_get_fontawesome_icon_map();
$result = [];
foreach ($map as $from => $to) {
list($component, $pix) = explode(':', $from);
$one = [];
$one['component'] = $component;
$one['pix'] = $pix;
$one['to'] = $to;
$result[] = $one;
}
return $result;
}
/**
* Returns description of load_template() result value.
*
* @return external_description
*/
public static function load_fontawesome_iconmap_returns() {
return new external_multiple_structure(new external_single_structure(
array(
'component' => new external_value(PARAM_COMPONENT, 'The component for the icon.'),
'pix' => new external_value(PARAM_RAW, 'Value to map the icon from.'),
'to' => new external_value(PARAM_RAW, 'Value to map the icon to.')
)
));
}
}