mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
Merge branch 'master_MDL-75126-allow-multiple-bulk-action-41' of https://github.com/catalyst/moodle-MDL-72752
This commit is contained in:
commit
8013961452
@ -30,7 +30,7 @@ class bulk_move_action extends \core_question\local\bank\bulk_action_base {
|
||||
return get_string('movetobulkaction', 'qbank_bulkmove');
|
||||
}
|
||||
|
||||
public function get_bulk_action_key(): string {
|
||||
public function get_key(): string {
|
||||
return 'move';
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,9 @@ use core_question\local\bank\plugin_features_base;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class plugin_feature extends plugin_features_base {
|
||||
public function get_bulk_actions(): ?bulk_action_base {
|
||||
return new bulk_move_action();
|
||||
public function get_bulk_actions(): array {
|
||||
return [
|
||||
new bulk_move_action(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class bulk_delete_action extends \core_question\local\bank\bulk_action_base {
|
||||
return get_string('delete');
|
||||
}
|
||||
|
||||
public function get_bulk_action_key(): string {
|
||||
public function get_key(): string {
|
||||
return 'deleteselected';
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,9 @@ class plugin_feature extends plugin_features_base {
|
||||
];
|
||||
}
|
||||
|
||||
public function get_bulk_actions(): ?bulk_action_base {
|
||||
return new bulk_delete_action();
|
||||
public function get_bulk_actions(): array {
|
||||
return [
|
||||
new bulk_delete_action(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ abstract class bulk_action_base {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_bulk_action_key(): string;
|
||||
abstract function get_key(): string;
|
||||
|
||||
/**
|
||||
* URL of the bulk action redirect page.
|
||||
@ -68,4 +68,19 @@ abstract class bulk_action_base {
|
||||
public function get_bulk_action_capabilities(): ?array {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A unique key for the bulk action, this will be used in the api to identify the action data.
|
||||
* Every bulk must have a unique key to perform the action as a part of the form post in the base view.
|
||||
* When questions are selected, it will post according to the key its selected from the dropdown.
|
||||
*
|
||||
* @return string
|
||||
* @deprecated since Moodle 4.1
|
||||
* @see get_key()
|
||||
* @todo Final deprecation on Moodle 4.5 MDL-72438
|
||||
*/
|
||||
public function get_bulk_action_key() {
|
||||
debugging(__FUNCTION__ . " is deprecated and should no longer be used. Please use get_key() instead.", DEBUG_DEVELOPER);
|
||||
return $this->get_key();
|
||||
}
|
||||
}
|
||||
|
@ -59,10 +59,10 @@ class plugin_features_base {
|
||||
/**
|
||||
* This method will return the array objects for the bulk actions ui.
|
||||
*
|
||||
* @return null|bulk_action_base
|
||||
* @return bulk_action_base[]
|
||||
*/
|
||||
public function get_bulk_actions(): ?bulk_action_base {
|
||||
return null;
|
||||
public function get_bulk_actions() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -202,22 +202,28 @@ class view {
|
||||
protected function init_bulk_actions(): void {
|
||||
$plugins = \core_component::get_plugin_list_with_class('qbank', 'plugin_feature', 'plugin_feature.php');
|
||||
foreach ($plugins as $componentname => $plugin) {
|
||||
$pluginentrypoint = new $plugin();
|
||||
$pluginentrypointobject = $pluginentrypoint->get_bulk_actions();
|
||||
// Don't need the plugins without bulk actions.
|
||||
if ($pluginentrypointobject === null) {
|
||||
unset($plugins[$componentname]);
|
||||
continue;
|
||||
}
|
||||
if (!\core\plugininfo\qbank::is_plugin_enabled($componentname)) {
|
||||
unset($plugins[$componentname]);
|
||||
continue;
|
||||
}
|
||||
$this->bulkactions[$pluginentrypointobject->get_bulk_action_key()] = [
|
||||
'title' => $pluginentrypointobject->get_bulk_action_title(),
|
||||
'url' => $pluginentrypointobject->get_bulk_action_url(),
|
||||
'capabilities' => $pluginentrypointobject->get_bulk_action_capabilities()
|
||||
];
|
||||
|
||||
$pluginentrypoint = new $plugin();
|
||||
$bulkactions = $pluginentrypoint->get_bulk_actions();
|
||||
if (!is_array($bulkactions)) {
|
||||
debugging("The method {$componentname}::get_bulk_actions() must return an " .
|
||||
"array of bulk actions instead of a single bulk action. " .
|
||||
"Please update your implementation of get_bulk_actions() to return an array. " .
|
||||
"Check out the qbank_bulkmove plugin for a working example.", DEBUG_DEVELOPER);
|
||||
$bulkactions = [$bulkactions];
|
||||
}
|
||||
|
||||
foreach ($bulkactions as $bulkactionobject) {
|
||||
$this->bulkactions[$bulkactionobject->get_key()] = [
|
||||
'title' => $bulkactionobject->get_bulk_action_title(),
|
||||
'url' => $bulkactionobject->get_bulk_action_url(),
|
||||
'capabilities' => $bulkactionobject->get_bulk_action_capabilities()
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,14 @@
|
||||
This files describes API changes for code that uses the question API.
|
||||
|
||||
=== 4.1 ===
|
||||
|
||||
1) get_bulk_action_key() in core_question\local\bank\bulk_action_base class is deprecated and renamed to get_key().
|
||||
|
||||
=== 4.0.5 ===
|
||||
|
||||
1) Question bank plugins can now define more than one bulk action. Therefore, plugin_features_base::get_bulk_actions has been
|
||||
changed to return an array, rather than a single bulk action class. Please update the plugin_features class in your plugin if necessary.
|
||||
|
||||
=== 4.0 ===
|
||||
|
||||
Moodle 4.0 included the results of a major project to re-work the question bank.
|
||||
|
Loading…
x
Reference in New Issue
Block a user