From 072f74c843e1e8dcc0294a51756a93d6c0ee754d Mon Sep 17 00:00:00 2001 From: aanabit Date: Wed, 12 Jul 2023 10:10:15 +0200 Subject: [PATCH] Adding a section title Co-authored-by: Sara Arjona --- docs/devupdate.md | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/docs/devupdate.md b/docs/devupdate.md index 99f9595f70..c531c9b005 100644 --- a/docs/devupdate.md +++ b/docs/devupdate.md @@ -281,6 +281,8 @@ MyModal.registerModalType(); ## Forms API +### add_sticky_action_buttons + A new method `add_sticky_action_buttons()` has been added to [Forms API](./apis/subsystems/form/index.md#add_sticky_action_buttons) to enable sticky footer. ```php @@ -290,16 +292,45 @@ public function add_sticky_action_buttons( ); ``` -A new method `filter_shown_headers() is created to [Forms API](./apis/subsystems/form/index.md#filter_shown_headers) to show some expanded headers only and hide the rest. +### filter_shown_headers + +A new method `filter_shown_headers()` has been added to to [Forms API](./apis/subsystems/form/index.md#filter_shown_headers) to show some expanded headers only and hide the rest. + +This method adds values to `_shownonlyelements` array to decide whether a header should be shown or hidden. +Only header names would be accepted and added to `_shownonlyelements` array. +Headers included in `_shownonlyelements` will be shown expanded in the form. The rest of the headers will be hidden. ```php - public function filter_shown_headers(array $shownonly): void { - $toshow = []; - foreach ($shownonly as $show) { - if ($this->_form->elementExists($show) && $this->_form->getElementType($show) == 'header') { - $toshow[] = $show; - } +public function filter_shown_headers(array $shownonly): void { + $this->_shownonlyelements = []; + if (empty($shownonly)) { + return; + } + foreach ($shownonly as $headername) { + $element = $this->getElement($headername); + if ($element->getType() == 'header') { + $this->_shownonlyelements[] = $headername; + $this->setExpanded($headername); } - $this->_form->filter_shown_headers($toshow); } +} +``` + +Empty `_shownonlyelements` array doesn't affect header's status or visibility. + +```php title="/course/editsection.php" +$showonly = optional_param('showonly', 0, PARAM_TAGLIST); + +[...] + +$mform = $courseformat->editsection_form($PAGE->url, $customdata); + +$initialdata = convert_to_array($sectioninfo); +if (!empty($CFG->enableavailability)) { + $initialdata['availabilityconditionsjson'] = $sectioninfo->availability; +} +$mform->set_data($initialdata); +if (!empty($showonly)) { + $mform->filter_shown_headers(explode(',', $showonly)); +} ```