From 917bd02be5e47a49c3f653e4dae3f229fe354e93 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Mon, 4 May 2015 13:16:52 +0800 Subject: [PATCH] MDL-49870 tool_templatelibrary: Allow docs in parent template only. If the mustache comment containing the docs for the template is not found in the theme overridden template, search the original core/plugin template for the docs. --- .../templatelibrary/amd/build/display.min.js | 2 +- admin/tool/templatelibrary/amd/src/display.js | 69 ++++++++++++++----- admin/tool/templatelibrary/classes/api.php | 38 +++++++++- .../tool/templatelibrary/classes/external.php | 51 ++++++++++++++ admin/tool/templatelibrary/db/services.php | 7 ++ .../tests/externallib_test.php | 14 ++++ admin/tool/templatelibrary/version.php | 2 +- .../core/notification_message.mustache | 16 +---- .../core/notification_problem.mustache | 16 +---- .../core/notification_redirect.mustache | 16 +---- .../core/notification_success.mustache | 16 +---- 11 files changed, 167 insertions(+), 80 deletions(-) diff --git a/admin/tool/templatelibrary/amd/build/display.min.js b/admin/tool/templatelibrary/amd/build/display.min.js index 3bc7ab408de..a5bf8ab0ec3 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(b,f){g.get_string("templateselected","tool_templatelibrary",b).done(function(b){a('[data-region="displaytemplateheader"]').text(b)}).fail(d.exception);var h="@template "+b,i=f.match(/{{!([\s\S]*?)}}/g),j=0;if(null!==i)for(j=0;j new external_value(PARAM_COMPONENT, 'component containing the template'), + 'template' => new external_value(PARAM_ALPHANUMEXT, 'name of the template')) + ); + } + + /** + * Can this function be called directly from ajax? + * + * @return boolean + * @since Moodle 2.9 + */ + public static function load_canonical_template_is_allowed_from_ajax() { + return true; + } + + /** + * Return a mustache template. + * Note - this function differs from the function core_output_load_template + * because it will never return a theme overridden version of a template. + * + * @param string $component The component that holds the template. + * @param string $template The name of the template. + * @return string the template + */ + public static function load_canonical_template($component, $template) { + $params = self::validate_parameters(self::load_canonical_template_parameters(), + array('component' => $component, + 'template' => $template)); + + $component = $params['component']; + $template = $params['template']; + + return api::load_canonical_template($component, $template); + } + + /** + * Returns description of load_canonical_template() result value. + * + * @return external_description + */ + public static function load_canonical_template_returns() { + return new external_value(PARAM_RAW, 'template'); + } } diff --git a/admin/tool/templatelibrary/db/services.php b/admin/tool/templatelibrary/db/services.php index fdecc01cac5..c1a9479180d 100644 --- a/admin/tool/templatelibrary/db/services.php +++ b/admin/tool/templatelibrary/db/services.php @@ -33,5 +33,12 @@ $functions = array( 'type' => 'read', 'capabilities'=> '', ), + 'tool_templatelibrary_load_canonical_template' => array( + 'classname' => 'tool_templatelibrary\external', + 'methodname' => 'load_canonical_template', + 'description' => 'Load a canonical template by name (not the theme overidden one).', + 'type' => 'read' + ), + ); diff --git a/admin/tool/templatelibrary/tests/externallib_test.php b/admin/tool/templatelibrary/tests/externallib_test.php index db9d4df59bb..9b09541f4d7 100644 --- a/admin/tool/templatelibrary/tests/externallib_test.php +++ b/admin/tool/templatelibrary/tests/externallib_test.php @@ -65,5 +65,19 @@ class tool_templatelibrary_external_testcase extends externallib_advanced_testca $this->assertEquals($result[0], "tool_templatelibrary/list_templates_page"); } + public function test_load_canonical_template() { + global $CFG; + $originaltheme = $CFG->theme; + // Change the theme to 'base' because it overrides these templates. + $CFG->theme = 'base'; + + $template = external::load_canonical_template('core', 'notification_problem'); + + // Only the base template should contain the docs. + $this->assertContains('@template core/notification_problem', $template); + + // Restore the original theme. + $CFG->theme = $originaltheme; + } } diff --git a/admin/tool/templatelibrary/version.php b/admin/tool/templatelibrary/version.php index 085d3477608..398b4cf352d 100644 --- a/admin/tool/templatelibrary/version.php +++ b/admin/tool/templatelibrary/version.php @@ -21,6 +21,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2015021623; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2015050401; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2014110400; // Requires this Moodle version. $plugin->component = 'tool_templatelibrary'; // Full name of the plugin (used for diagnostics). diff --git a/theme/base/templates/core/notification_message.mustache b/theme/base/templates/core/notification_message.mustache index ac0e3fa4752..d3889426880 100644 --- a/theme/base/templates/core/notification_message.mustache +++ b/theme/base/templates/core/notification_message.mustache @@ -14,18 +14,4 @@ You should have received a copy of the GNU General Public License along with Moodle. If not, see . }} -{{! - Moodle notification template. - - The purpose of this template is to render a message notification. - - Classes required for JS: - * none - - Data attributes required for JS: - * none - - Context variables required for this template: - * message A cleaned string (use clean_text()) to display. -}} -
{{{message}}}
\ No newline at end of file +
{{{message}}}
diff --git a/theme/base/templates/core/notification_problem.mustache b/theme/base/templates/core/notification_problem.mustache index f87ce3573c8..6349e702ff0 100644 --- a/theme/base/templates/core/notification_problem.mustache +++ b/theme/base/templates/core/notification_problem.mustache @@ -14,18 +14,4 @@ You should have received a copy of the GNU General Public License along with Moodle. If not, see . }} -{{! - Moodle notification template. - - The purpose of this template is to render a problem notification. - - Classes required for JS: - * none - - Data attributes required for JS: - * none - - Context variables required for this template: - * message A cleaned string (use clean_text()) to display. -}} -
{{{message}}}
\ No newline at end of file +
{{{message}}}
diff --git a/theme/base/templates/core/notification_redirect.mustache b/theme/base/templates/core/notification_redirect.mustache index af5cb5b14f9..2c07a4829ab 100644 --- a/theme/base/templates/core/notification_redirect.mustache +++ b/theme/base/templates/core/notification_redirect.mustache @@ -14,18 +14,4 @@ You should have received a copy of the GNU General Public License along with Moodle. If not, see . }} -{{! - Moodle notification template. - - The purpose of this template is to render a message notification. - - Classes required for JS: - * none - - Data attributes required for JS: - * none - - Context variables required for this template: - * message A cleaned string (use clean_text()) to display. -}} -
{{{message}}}
\ No newline at end of file +
{{{message}}}
diff --git a/theme/base/templates/core/notification_success.mustache b/theme/base/templates/core/notification_success.mustache index 3b841616ea9..3040cda95dd 100644 --- a/theme/base/templates/core/notification_success.mustache +++ b/theme/base/templates/core/notification_success.mustache @@ -14,18 +14,4 @@ You should have received a copy of the GNU General Public License along with Moodle. If not, see . }} -{{! - Moodle notification template. - - The purpose of this template is to render a success notification. - - Classes required for JS: - * none - - Data attributes required for JS: - * none - - Context variables required for this template: - * message A cleaned string (use clean_text()) to display. -}} -
{{{message}}}
\ No newline at end of file +
{{{message}}}