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.
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user