From 7ef7aaecac7def504e360a6e6fc5f9e132a2fa00 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 27 Aug 2020 13:17:45 +0800 Subject: [PATCH 1/2] MDL-69262 core: Make instance count variable as a static class variable With the static function variable $instance, calls to \action_menu_link::export_for_template() from its subclasses are stored in different variables. This causes duplicate IDs when different implementations of action menu links are rendered on the action menu trigger/link template. (e.g. action_menu_link and action_menu_link_secondary both rendered on the same page). To make the incrementing uniform for the action_menu_link class and its implementations, the $instance variable is moved out of the export_to_template() method and is now made to a static class variable. --- lib/outputcomponents.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index e08b3d3ab97..b6277cb1cf8 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -4682,6 +4682,12 @@ class action_menu_link extends action_link implements renderable { */ public $actionmenu = null; + /** + * The number of instances of this action menu link (and its subclasses). + * @var int + */ + protected static $instance = 1; + /** * Constructs the object. * @@ -4705,10 +4711,8 @@ class action_menu_link extends action_link implements renderable { * @return stdClass */ public function export_for_template(renderer_base $output) { - static $instance = 1; - $data = parent::export_for_template($output); - $data->instance = $instance++; + $data->instance = self::$instance++; // Ignore what the parent did with the attributes, except for ID and class. $data->attributes = []; From 6d0a5559eeadf512161b010c999668b8562ea8f4 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 27 Aug 2020 13:23:24 +0800 Subject: [PATCH 2/2] MDL-69262 core: Use core/action_menu_link in core/action_menu_trigger * Introduce the "actionmenulinkclasses" block in the action_menu_link template so other templates importing it can have the option to override its classes. * Have the action menu trigger template use the action menu link template to reduce code duplication. --- lib/templates/action_menu_link.mustache | 9 ++++++++- lib/templates/action_menu_trigger.mustache | 13 +++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/templates/action_menu_link.mustache b/lib/templates/action_menu_link.mustache index 0184d49bbe4..a57beb2e0fb 100644 --- a/lib/templates/action_menu_link.mustache +++ b/lib/templates/action_menu_link.mustache @@ -27,7 +27,14 @@ } }} {{^disabled}} - {{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{#showtext}}{{{text}}}{{/showtext}} + + {{#icon}} + {{#pix}}{{key}}, {{component}}, {{title}}{{/pix}} + {{/icon}} + {{#showtext}} + {{{text}}} + {{/showtext}} + {{/disabled}} {{#disabled}} {{#icon}}{{#pix}}{{key}},{{component}},{{title}}{{/pix}}{{/icon}}{{{text}}} diff --git a/lib/templates/action_menu_trigger.mustache b/lib/templates/action_menu_trigger.mustache index 8a172c9dfad..9c009fcdb1d 100644 --- a/lib/templates/action_menu_trigger.mustache +++ b/lib/templates/action_menu_trigger.mustache @@ -95,16 +95,9 @@