Skip to content

Commit

Permalink
MDL-83601 mod_lti: Adding multilang to LTI category restriction config.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaboesch committed Jan 31, 2025
1 parent 07881a5 commit 1be8dd2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions mod/lti/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,11 @@ public function lti_build_category_tree(array $elements, int $parentid = 0): arr
if ($children) {
$element['nodes'] = $children;
$element['haschildren'] = true;
$element['name'] = format_string($element['name'], false, ["context" => \core\context\system::instance()]);
} else {
$element['nodes'] = null;
$element['haschildren'] = false;
$element['name'] = format_string($element['name'], false, ["context" => \core\context\system::instance()]);
}
$branch[] = $element;
}
Expand Down
5 changes: 3 additions & 2 deletions mod/lti/tests/course_categories_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function setup_course_categories(): array {

$topcatdbrecord = $DB->get_record('course_categories', ['parent' => 0]);

$subcata = $this->getDataGenerator()->create_category(['parent' => $topcatdbrecord->id, 'name' => 'cata']);
$subcata = $this->getDataGenerator()->create_category(['parent' => $topcatdbrecord->id,
'name' => '<span lang="en" class="multilang">cata</span><span lang="de" class="multilang">kata</span>']);
$subcatadbrecord = $DB->get_record('course_categories', ['id' => $subcata->id]);

$subcatca = $this->getDataGenerator()->create_category(['parent' => $subcata->id, 'name' => 'catca']);
Expand All @@ -50,7 +51,7 @@ public function setup_course_categories(): array {
'topcat' => $topcatdbrecord,
'subcata' => $subcatadbrecord,
'subcatca' => $subcatcadbrecord,
'subcatb' => $subcatb,
'subcatb' => $subcatbdbrecord,
'subcatcb' => $subcatcbdbrecord
];
}
Expand Down
10 changes: 9 additions & 1 deletion mod/lti/tests/mod_lti_edit_types_form_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function test_set_nested_categories(): void {
$this->resetAfterTest(true);
$this->setAdminUser();

// Enable multilang filter to on content and heading.
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', 1);

$ltiform = new test_edit_form(null);
$ltiform->definition_after_data();

Expand All @@ -66,7 +70,8 @@ public function test_set_nested_categories(): void {
[
"id" => $coursecategories['subcata']->id,
"parent" => $coursecategories['topcat']->id,
"name" => $coursecategories['subcata']->name,
"name" => format_string($coursecategories['subcata']->name, false,
["context" => \core\context\system::instance()]),
"nodes" => [
[
"id" => $coursecategories['subcatca']->id,
Expand Down Expand Up @@ -98,6 +103,9 @@ public function test_set_nested_categories(): void {
];

$records = $DB->get_records('course_categories', [], 'sortorder, id', 'id, parent, name');
foreach ($records as &$record) {
$record->name = format_string($record->name, false, ["context" => \core\context\system::instance()]);
}
$allcategories = json_decode(json_encode($records), true);
$coursecategoriesarray = $ltiform->lti_build_category_tree($allcategories);

Expand Down

0 comments on commit 1be8dd2

Please sign in to comment.