mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Merge branch 'MDL-79102-master' of https://github.com/sarjona/moodle
This commit is contained in:
commit
3b167a177b
@ -83,13 +83,17 @@ class core_course_bulk_activity_completion_renderer extends plugin_renderer_base
|
|||||||
// Only create the form if it's different from the one that has been sent.
|
// Only create the form if it's different from the one that has been sent.
|
||||||
$modform = $form;
|
$modform = $form;
|
||||||
if (empty($form) || !in_array($module->id, array_keys($modules))) {
|
if (empty($form) || !in_array($module->id, array_keys($modules))) {
|
||||||
$modform = new \core_completion_defaultedit_form(null, [
|
$modform = new \core_completion_defaultedit_form(
|
||||||
'course' => $course,
|
null,
|
||||||
'modules' => [
|
[
|
||||||
$module->id => $module,
|
'course' => $course,
|
||||||
|
'modules' => [
|
||||||
|
$module->id => $module,
|
||||||
|
],
|
||||||
|
'displaycancel' => false,
|
||||||
|
'forceuniqueid' => true,
|
||||||
],
|
],
|
||||||
'displaycancel' => false,
|
);
|
||||||
]);
|
|
||||||
$module->modulecollapsed = true;
|
$module->modulecollapsed = true;
|
||||||
}
|
}
|
||||||
$module->formhtml = $modform->render();
|
$module->formhtml = $modform->render();
|
||||||
|
@ -72,7 +72,10 @@ foreach ($allmodules->modules as $module) {
|
|||||||
|
|
||||||
$form = null;
|
$form = null;
|
||||||
if (!empty($modules)) {
|
if (!empty($modules)) {
|
||||||
$form = new core_completion_defaultedit_form(null, ['course' => $course, 'modules' => $modules, 'displaycancel' => false]);
|
$form = new core_completion_defaultedit_form(
|
||||||
|
null,
|
||||||
|
['course' => $course, 'modules' => $modules, 'displaycancel' => false, 'forceuniqueid' => true]
|
||||||
|
);
|
||||||
if (!$form->is_cancelled() && $data = $form->get_data()) {
|
if (!$form->is_cancelled() && $data = $form->get_data()) {
|
||||||
$data->modules = $modules;
|
$data->modules = $modules;
|
||||||
$manager->apply_default_completion($data, $form->has_custom_completion_rules(), $form->get_suffix());
|
$manager->apply_default_completion($data, $form->has_custom_completion_rules(), $form->get_suffix());
|
||||||
|
@ -146,6 +146,9 @@ abstract class moodleform {
|
|||||||
/** @var bool|null stores the validation result of this form or null if not yet validated */
|
/** @var bool|null stores the validation result of this form or null if not yet validated */
|
||||||
protected $_validated = null;
|
protected $_validated = null;
|
||||||
|
|
||||||
|
/** @var int Unique identifier to be used for action buttons. */
|
||||||
|
static protected $uniqueid = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor function calls the abstract function definition() and it will then
|
* The constructor function calls the abstract function definition() and it will then
|
||||||
* process and clean and attempt to validate incoming data.
|
* process and clean and attempt to validate incoming data.
|
||||||
@ -1359,22 +1362,36 @@ abstract class moodleform {
|
|||||||
* @param string $submitlabel label for submit button, defaults to get_string('savechanges')
|
* @param string $submitlabel label for submit button, defaults to get_string('savechanges')
|
||||||
*/
|
*/
|
||||||
public function add_action_buttons($cancel = true, $submitlabel = null) {
|
public function add_action_buttons($cancel = true, $submitlabel = null) {
|
||||||
if (is_null($submitlabel)){
|
if (is_null($submitlabel)) {
|
||||||
$submitlabel = get_string('savechanges');
|
$submitlabel = get_string('savechanges');
|
||||||
}
|
}
|
||||||
$mform =& $this->_form;
|
$mform = $this->_form;
|
||||||
if ($cancel){
|
// Only use uniqueid if the form defines it needs to be used.
|
||||||
//when two elements we need a group
|
$forceuniqueid = false;
|
||||||
$buttonarray=array();
|
if (is_array($this->_customdata)) {
|
||||||
$buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
|
$forceuniqueid = $this->_customdata['forceuniqueid'] ?? false;
|
||||||
$buttonarray[] = &$mform->createElement('cancel');
|
}
|
||||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
// Keep the first action button as submitbutton (without uniqueid) because single forms pages expect this to happen.
|
||||||
|
$submitbuttonname = $forceuniqueid && $this::$uniqueid > 0 ? 'submitbutton_' . $this::$uniqueid : 'submitbutton';
|
||||||
|
if ($cancel) {
|
||||||
|
// When two elements we need a group.
|
||||||
|
$buttonarray = [
|
||||||
|
$mform->createElement('submit', $submitbuttonname, $submitlabel),
|
||||||
|
$mform->createElement('cancel'),
|
||||||
|
];
|
||||||
|
$buttonarname = $forceuniqueid && $this::$uniqueid > 0 ? 'buttonar_' . $this::$uniqueid : 'buttonar';
|
||||||
|
$mform->addGroup($buttonarray, $buttonarname, '', [' '], false);
|
||||||
$mform->closeHeaderBefore('buttonar');
|
$mform->closeHeaderBefore('buttonar');
|
||||||
} else {
|
} else {
|
||||||
//no group needed
|
// No group needed.
|
||||||
$mform->addElement('submit', 'submitbutton', $submitlabel);
|
$mform->addElement('submit', $submitbuttonname, $submitlabel);
|
||||||
$mform->closeHeaderBefore('submitbutton');
|
$mform->closeHeaderBefore('submitbutton');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increase the uniqueid so that we can have multiple forms with different ids for the action buttons on the same page.
|
||||||
|
if ($forceuniqueid) {
|
||||||
|
$this::$uniqueid++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user