MDL-81648 course: Add a method to retrieve delegate section parent

- New 'get_parent_section()' function added to sectiondelegate abstract class
This commit is contained in:
Mikel Martín 2024-05-17 09:41:45 +02:00
parent bcd8e0d6ed
commit b4ecd9d805
2 changed files with 26 additions and 0 deletions

View File

@ -124,4 +124,13 @@ abstract class sectiondelegate {
): ?action_menu {
return $controlmenu->get_default_action_menu($output);
}
/**
* Get the parent section of the current delegated section if any.
*
* @return section_info|null
*/
public function get_parent_section(): ?section_info {
return null;
}
}

View File

@ -141,4 +141,21 @@ class sectiondelegate_test extends \advanced_testcase {
$result = $delegated->get_section_action_menu($format, $controlmenu, $renderer);
$this->assertNull($result);
}
/**
* Test get_parent_section().
*
* @covers ::get_parent_section
*/
public function test_get_parent_section(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
$sectioninfo = formatactions::section($course)->create_delegated('test_component', 1);
/** @var testsectiondelegate */
$delegated = $sectioninfo->get_component_instance();
$this->assertNull($delegated->get_parent_section());
}
}