Skip to content

Commit

Permalink
Bugfix: Custom course fields of type "Textarea" were not conditionall…
Browse files Browse the repository at this point in the history
…y hidden in the smart menu configuration, resolves moodle-an-hochschulen#576.
  • Loading branch information
SimonThornett authored Mar 13, 2024
1 parent 4c0832b commit afad96e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes

### Unreleased

* 2024-03-13 - Bugfix: Custom course fields of type "Textarea" were not conditionally hidden in the smart menu configuration, resolves #576.
* 2024-03-01 - Improvement: implement new setting to show starred courses in a popover menu in navbar, solves #289.

### v4.3-r8
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ Moodle an Hochschulen e.V. would like to thank these main contributors (in alpha
* bdecent GmbH, Stefan Scholz: Code, Ideating, Funding
* Bern University of Applied Sciences (BFH), Luca Bösch: Code, Peer Review, Ideating
* Carinthia University of Applied Sciences, Mario Wehr: Code
* Catalyst IT Europe, Simon Thornett: Code
* ELAN e.V., Farbod Zamani: Code
* FernUniversität in Hagen, Daniel Poggenpohl: Code, Ideating
* Hochschule Hannover - University of Applied Sciences and Arts: Code, Funding, Ideating
Expand Down
18 changes: 17 additions & 1 deletion classes/smartmenu_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,10 +1224,21 @@ public static function load_custom_field_config(&$mform) {
$fieldid = $field->get('id');
$field = \core_customfield\field_controller::create($fieldid);
$data = \core_customfield\api::get_instance_fields_data([$fieldid => $field], 0);
// If this field is a textarea, adjust the shortname to include _editor.
$istextarea = $field->get('type') == 'textarea';
if ($istextarea) {
$shortname .= "_editor";
}
if (isset($data[$fieldid])) {
$data = $data[$fieldid];
$data->instance_form_definition($mform);
$elem = $mform->getElement("customfield_".$shortname);
// If this field is a textarea, we'll remove the element and re-add
// it in a group as textareas can't be conditionally hidden due to a limitation in Moodle core.
if ($istextarea) {
$mform->removeElement("customfield_" . $shortname);
$mform->addGroup([$elem], "group_customfield_" . $shortname, $elem->getLabel());
}
// Remove the rules for custom fields.
if (isset($mform->_rules["customfield_".$shortname])) {
unset($mform->_rules["customfield_".$shortname]);
Expand All @@ -1252,7 +1263,12 @@ public static function load_custom_field_config(&$mform) {
$mform->setDefault("customfield_".$shortname, 0);
}

$mform->hideif("customfield_".$shortname, 'type', 'neq', self::TYPEDYNAMIC);
// Hide the field if needed (and distinguish between textareas and other fields here as explained above).
if ($istextarea) {
$mform->hideif("group_customfield_" . $shortname, 'type', 'neq', self::TYPEDYNAMIC);
} else {
$mform->hideif("customfield_" . $shortname, 'type', 'neq', self::TYPEDYNAMIC);
}
}
}

Expand Down

0 comments on commit afad96e

Please sign in to comment.