MDL-79281 core_question: Remove 'deleteall' param from edit page.

This removes the setting of the 'deleteall' param to every link
on the question edit page and inserts it into the url based
on if we actually want to delete all versions or not.
This commit is contained in:
Conn Warwicker
2025-01-20 14:16:28 +00:00
parent ddc7c93a3c
commit 03af18d503
8 changed files with 35 additions and 10 deletions
@@ -18,6 +18,7 @@ namespace qbank_bulkmove;
use core_question\local\bank\bulk_action_base;
use core_question\local\bank\plugin_features_base;
use core_question\local\bank\view;
/**
* Class plugin_feature is the entrypoint for the features.
@@ -28,7 +29,8 @@ 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(): array {
#[\Override]
public function get_bulk_actions(?view $qbank = null): array {
return [
new bulk_move_action(),
];
@@ -16,6 +16,8 @@
namespace qbank_deletequestion;
use core_question\local\bank\view;
/**
* Class bulk_delete_action is the base class for delete bulk actions ui.
*
@@ -26,6 +28,19 @@ namespace qbank_deletequestion;
*/
class bulk_delete_action extends \core_question\local\bank\bulk_action_base {
/**
* @var view Question bank view object
*/
protected $qbank;
/**
* Construct the deletequestion plugin feature object
* @param view $qbank
*/
public function __construct(view $qbank) {
$this->qbank = $qbank;
}
public function get_bulk_action_title(): string {
return get_string('delete');
}
@@ -35,7 +50,11 @@ class bulk_delete_action extends \core_question\local\bank\bulk_action_base {
}
public function get_bulk_action_url(): \moodle_url {
return new \moodle_url('/question/bank/deletequestion/delete.php');
$params = [];
if ($this->qbank && !$this->qbank->is_listing_specific_versions()) {
$params['deleteall'] = 1;
}
return new \moodle_url('/question/bank/deletequestion/delete.php', $params);
}
public function get_bulk_action_capabilities(): ?array {
@@ -96,7 +96,7 @@ class delete_action extends question_action_base {
'q' . $question->id => 1,
'sesskey' => sesskey());
$deleteparams = array_merge($deleteparams, $this->returnparams);
if ($this->qbank->base_url()->get_param('deleteall')) {
if (!$this->qbank->is_listing_specific_versions()) {
$deleteparams['deleteall'] = 1;
}
$url = new \moodle_url($this->deletequestionurl, $deleteparams);
@@ -44,9 +44,10 @@ class plugin_feature extends plugin_features_base {
];
}
public function get_bulk_actions(): array {
#[\Override]
public function get_bulk_actions(?view $qbank = null): array {
return [
new bulk_delete_action(),
new bulk_delete_action($qbank),
];
}
@@ -74,9 +74,10 @@ class plugin_features_base {
/**
* This method will return the array objects for the bulk actions ui.
*
* @param view|null $qbank Question bank object or null if not needed
* @return bulk_action_base[]
*/
public function get_bulk_actions() {
public function get_bulk_actions(?view $qbank = null) {
return [];
}
+1 -1
View File
@@ -321,7 +321,7 @@ class view {
*/
protected function init_bulk_actions(): void {
foreach ($this->plugins as $componentname => $plugin) {
$bulkactions = $plugin->get_bulk_actions();
$bulkactions = $plugin->get_bulk_actions($this);
if (!is_array($bulkactions)) {
debugging("The method {$componentname}::get_bulk_actions() must return an " .
"array of bulk actions instead of a single bulk action. " .
-1
View File
@@ -43,7 +43,6 @@ if ($PAGE->course->id == $SITE->id) {
$PAGE->set_primary_active_tab('home');
}
$thispageurl->param('deleteall', 1);
$questionbank = new view($contexts, $thispageurl, $COURSE, $cm, $pagevars);
$context = $contexts->lowest();
+5 -2
View File
@@ -66,6 +66,11 @@ function core_question_output_fragment_question_data(array $args): string {
$viewclass = empty($args['view']) ? \core_question\local\bank\view::class : clean_param($args['view'], PARAM_NOTAGS);
// Make sure the class passed through is valid (exists and is view or subclass of view).
if (!class_exists($viewclass) || !is_a($viewclass, \core_question\local\bank\view::class, true)) {
throw new invalid_parameter_exception('view parameter must be a valid view class');
}
if (!empty($args['lastchanged'])) {
$thispageurl->param('lastchanged', clean_param($args['lastchanged'], PARAM_INT));
}
@@ -75,8 +80,6 @@ function core_question_output_fragment_question_data(array $args): string {
if (!empty($args['extraparams'])) {
$thispageurl->param('extraparams', clean_param($args['extraparams'], PARAM_RAW));
}
// This is highly suspicious, but it is the same approach taken in /question/edit.php. See MDL-79281.
$thispageurl->param('deleteall', 1);
$questionbank = new $viewclass($contexts, $thispageurl, $course, $cm, $pagevars, $extraparams);
$questionbank->add_standard_search_conditions();
ob_start();