mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
Merge branch 'MDL-75875-main' of https://github.com/laurentdavid/moodle
This commit is contained in:
commit
a4b3cf493d
8
.upgradenotes/MDL-75875-2025020411413438.yml
Normal file
8
.upgradenotes/MDL-75875-2025020411413438.yml
Normal 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
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user