Differences Between: [Versions 311 and 402] [Versions 311 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * A web service to load the mapping of moodle pix names to fontawesome icon names. 19 * 20 * @package core 21 * @category external 22 * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace core\external\output\icon_system; 27 28 use external_api; 29 use external_function_parameters; 30 use external_multiple_structure; 31 use external_single_structure; 32 use external_value; 33 use core\output\icon_system_fontawesome; 34 use theme_config; 35 36 /** 37 * Web service to load font awesome icon maps. 38 * 39 * @package core 40 * @category external 41 * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk> 42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 43 */ 44 class load_fontawesome_map extends external_api { 45 46 /** 47 * Description of the parameters suitable for the `execute` function. 48 * 49 * @return external_function_parameters 50 */ 51 public static function execute_parameters() { 52 return new external_function_parameters([ 53 'themename' => new external_value(PARAM_ALPHANUMEXT, 'The theme to fetch the map for'), 54 ]); 55 } 56 57 /** 58 * Return a mapping of icon names to icons. 59 * 60 * @param string $themename The theme to fetch icons for 61 * @return array the mapping 62 */ 63 public static function execute(string $themename) { 64 [ 65 'themename' => $themename, 66 ] = self::validate_parameters(self::execute_parameters(), [ 67 'themename' => $themename, 68 ]); 69 70 $theme = theme_config::load($themename); 71 $instance = icon_system_fontawesome::instance($theme->get_icon_system()); 72 73 $result = []; 74 foreach ($instance->get_icon_name_map() as $from => $to) { 75 [$component, $pix] = explode(':', $from); 76 $result[] = [ 77 'component' => $component, 78 'pix' => $pix, 79 'to' => $to, 80 ]; 81 } 82 83 return $result; 84 } 85 86 /** 87 * Description of the return value for the `execute` function. 88 * 89 * @return external_description 90 */ 91 public static function execute_returns() { 92 return new external_multiple_structure(new external_single_structure([ 93 'component' => new external_value(PARAM_COMPONENT, 'The component for the icon.'), 94 'pix' => new external_value(PARAM_RAW, 'Value to map the icon from.'), 95 'to' => new external_value(PARAM_RAW, 'Value to map the icon to.'), 96 ])); 97 } 98 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body