From 0803d255d52338a947e3358f280822af293281f1 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Tue, 4 Feb 2025 12:46:17 +0100 Subject: [PATCH] MDL-75875 core: Remove Single Button primary parameter * Final deprecation for the use of a boolean as 'primary' parameter (4th parameter of the constructor), used before to specify a button was a primary button. This has been replaced by a wider range of choices. --- .upgradenotes/MDL-75875-2025020411413438.yml | 8 ++++ lib/classes/output/single_button.php | 42 +++-------------- lib/tests/outputcomponents_test.php | 48 -------------------- 3 files changed, 14 insertions(+), 84 deletions(-) create mode 100644 .upgradenotes/MDL-75875-2025020411413438.yml diff --git a/.upgradenotes/MDL-75875-2025020411413438.yml b/.upgradenotes/MDL-75875-2025020411413438.yml new file mode 100644 index 00000000000..1eb8cb6b673 --- /dev/null +++ b/.upgradenotes/MDL-75875-2025020411413438.yml @@ -0,0 +1,8 @@ +issueNumber: MDL-75875 +notes: + core: + - message: >- + Remove support deprecated boolean 'primary' parameter in + \core\output\single_button. The 4th parameter is now a string and not a + boolean (the use was to set it to true to have a primary button) + type: removed diff --git a/lib/classes/output/single_button.php b/lib/classes/output/single_button.php index 853f8d83f08..fe53a4be0f2 100644 --- a/lib/classes/output/single_button.php +++ b/lib/classes/output/single_button.php @@ -93,12 +93,6 @@ class single_button implements renderable { */ protected $type; - /** - * @var bool True if button is primary button. Used for styling. - * @deprecated since Moodle 4.2 - */ - private $primary = false; - /** * @var bool True if button disabled, false if normal */ @@ -147,14 +141,9 @@ class single_button implements renderable { moodle_url $url, $label, $method = 'post', - $type = self::BUTTON_SECONDARY, + string $type = self::BUTTON_SECONDARY, $attributes = [] ) { - if (is_bool($type)) { - debugging('The boolean $primary is deprecated and replaced by $type, - use single_button::BUTTON_PRIMARY or self::BUTTON_SECONDARY instead'); - $type = $type ? self::BUTTON_PRIMARY : self::BUTTON_SECONDARY; - } $this->url = clone($url); $this->label = $label; $this->method = $method; @@ -194,44 +183,25 @@ class single_button implements renderable { /** * Magic setter method. * - * This method manages access to some properties and will display deprecation message when accessing 'primary' property. - * * @param string $name * @param mixed $value */ public function __set($name, $value) { - switch ($name) { - case 'primary': - debugging('The primary field is deprecated, use the type field instead'); - // Here just in case we modified the primary field from outside {@see \mod_quiz_renderer::summary_page_controls}. - $this->type = $value ? self::BUTTON_PRIMARY : self::BUTTON_SECONDARY; - break; - case 'type': - $this->type = in_array($value, self::BUTTON_TYPES) ? $value : self::BUTTON_SECONDARY; - break; - default: - $this->$name = $value; + if ($name === 'type') { + $this->type = in_array($value, self::BUTTON_TYPES) ? $value : self::BUTTON_SECONDARY; + } else { + $this->$name = $value; } } /** * Magic method getter. * - * This method manages access to some properties and will display deprecation message when accessing 'primary' property. - * * @param string $name * @return mixed */ public function __get($name) { - switch ($name) { - case 'primary': - debugging('The primary field is deprecated, use type field instead'); - return $this->type == self::BUTTON_PRIMARY; - case 'type': - return $this->type; - default: - return $this->$name; - } + return $this->$name; } /** diff --git a/lib/tests/outputcomponents_test.php b/lib/tests/outputcomponents_test.php index bc4b79d58bd..384a1dc5cdb 100644 --- a/lib/tests/outputcomponents_test.php +++ b/lib/tests/outputcomponents_test.php @@ -612,54 +612,6 @@ EOF; $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']); } - /** - * Test for checking the template context data for the single_select element legacy API. - * @covers \single_button - */ - public function test_single_button_deprecated(): void { - global $PAGE; - $url = new \moodle_url('/'); - $realname = 'realname'; - $attributes = [ - 'data-dummy' => 'dummy', - ]; - - // Test that when we use a true boolean value for the 4th parameter this is set as primary type. - $singlebutton = new single_button($url, $realname, 'post', single_button::BUTTON_PRIMARY, $attributes); - $renderer = $PAGE->get_renderer('core'); - $data = $singlebutton->export_for_template($renderer); - $this->assertEquals($realname, $data->label); - $this->assertEquals('post', $data->method); - $this->assertEquals('singlebutton', $data->classes); - $this->assertEquals('primary', $data->type); - $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']); - - // Test that when we use a false boolean value for the 4th parameter this is set as secondary type. - $singlebutton = new single_button($url, $realname, 'post', false, $attributes); - $this->assertDebuggingCalled(); - $renderer = $PAGE->get_renderer('core'); - $data = $singlebutton->export_for_template($renderer); - $this->assertEquals($realname, $data->label); - $this->assertEquals('post', $data->method); - $this->assertEquals('singlebutton', $data->classes); - $this->assertEquals('secondary', $data->type); - $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']); - - // Test that when we set the primary value, then this is reflected in the type. - $singlebutton->primary = false; - $this->assertDebuggingCalled(); - $this->assertEquals(single_button::BUTTON_SECONDARY, $singlebutton->type); - $singlebutton->primary = true; - $this->assertDebuggingCalled(); - $this->assertEquals(single_button::BUTTON_PRIMARY, $singlebutton->type); - // Then set the type directly. - - $singlebutton->type = single_button::BUTTON_DANGER; - $data = $singlebutton->export_for_template($renderer); - $this->assertEquals('danger', $data->type); - - } - /** * Test for checking the template context data for the url_select element. */