diff --git a/admin/tool/templatelibrary/amd/build/display.min.js b/admin/tool/templatelibrary/amd/build/display.min.js index 503f280e20f..7b5108c7f68 100644 --- a/admin/tool/templatelibrary/amd/build/display.min.js +++ b/admin/tool/templatelibrary/amd/build/display.min.js @@ -1 +1 @@ -define(["jquery","core/ajax","core/log","core/notification","core/templates","core/config","core/str"],function(a,b,c,d,e,f,g){var h=function(a,b){var c="@template "+b,d=0,e=[];if(e=a.match(/{{!([\s\S]*?)}}/g),null!==e)for(d=0;d * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates'], - function($, ajax, log, notification, templates) { +define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates', 'core/config'], + function($, ajax, log, notification, templates, config) { /** * The ajax call has returned with a new list of templates. @@ -42,15 +42,14 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates' * * @method refreshSearch */ - var refreshSearch = function() { + var refreshSearch = function(themename) { var componentStr = $('[data-field="component"]').val(); var searchStr = $('[data-field="search"]').val(); // Trigger the search. - ajax.call([ { methodname: 'tool_templatelibrary_list_templates', - args: { component: componentStr, search: searchStr }, + args: { component: componentStr, search: searchStr, themename: themename }, done: reloadListTemplate, fail: notification.exception } ], true, false); @@ -78,12 +77,12 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates' }; var changeHandler = function() { - queueRefresh(refreshSearch, 400); + queueRefresh(refreshSearch.bind(this, config.theme), 400); }; // Add change handlers to refresh the list. $('[data-region="list-templates"]').on('change', '[data-field="component"]', changeHandler); $('[data-region="list-templates"]').on('input', '[data-field="search"]', changeHandler); - refreshSearch(); + refreshSearch(config.theme); return {}; }); diff --git a/admin/tool/templatelibrary/classes/api.php b/admin/tool/templatelibrary/classes/api.php index 23b7dcf793a..b86fa5217d6 100644 --- a/admin/tool/templatelibrary/classes/api.php +++ b/admin/tool/templatelibrary/classes/api.php @@ -47,7 +47,12 @@ class api { * @return array[string] Where each template is in the form "component/templatename". */ public static function list_templates($component = '', $search = '', $themename = '') { - global $CFG; + global $CFG, $PAGE; + + if (empty($themename)) { + $themename = $PAGE->theme->name; + } + $themeconfig = \theme_config::load($themename); $templatedirs = array(); $results = array(); @@ -77,6 +82,9 @@ class api { foreach ($plugintypes as $type => $dir) { $plugins = core_component::get_plugin_list_with_file($type, 'templates', false); foreach ($plugins as $plugin => $dir) { + if ($type == 'theme' && $plugin != $themename && !in_array($plugin, $themeconfig->parents)) { + continue; + } if (!empty($dir) && is_dir($dir)) { $pluginname = $type . '_' . $plugin; $dirs = mustache_template_finder::get_template_directories_for_component($pluginname, $themename); diff --git a/admin/tool/templatelibrary/classes/external.php b/admin/tool/templatelibrary/classes/external.php index be583a27a4e..62e605609cf 100644 --- a/admin/tool/templatelibrary/classes/external.php +++ b/admin/tool/templatelibrary/classes/external.php @@ -59,7 +59,13 @@ class external extends external_api { VALUE_DEFAULT, '' ); - $params = array('component' => $component, 'search' => $search); + $themename = new external_value( + PARAM_COMPONENT, + 'The current theme', + VALUE_DEFAULT, + '' + ); + $params = array('component' => $component, 'search' => $search, 'themename' => $themename); return new external_function_parameters($params); } @@ -69,14 +75,15 @@ class external extends external_api { * @param string $search The search string. * @return array[string] */ - public static function list_templates($component, $search) { + public static function list_templates($component, $search, $themename) { $params = self::validate_parameters(self::list_templates_parameters(), array( 'component' => $component, 'search' => $search, + 'themename' => $themename, )); - return api::list_templates($component, $search); + return api::list_templates($component, $search, $themename); } /**