This commit is contained in:
Andrew Nicols 2025-03-05 14:25:26 +08:00
commit a4b3cf493d
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
3 changed files with 14 additions and 84 deletions

View File

@ -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

View File

@ -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;
}
/**

View File

@ -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.
*/