From 81b900ae0541d35a17f9b77dcc04a812f45ee9f4 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 24 Sep 2021 00:58:05 -0500 Subject: [PATCH] Forum: Fix filter by language - refs BT#19044 --- public/main/forum/index.php | 12 ++++++++---- public/main/template/default/forum/list.html.twig | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/public/main/forum/index.php b/public/main/forum/index.php index 6a2830d619..8c7ec31f73 100644 --- a/public/main/forum/index.php +++ b/public/main/forum/index.php @@ -245,9 +245,10 @@ if (!empty($allCourseForums)) { $actions = Display::toolbarAction('toolbar-forum', [$actionLeft]); $languages = api_get_language_list_for_flag(); -$defaultUserLanguage = 'en'; +$defaultUserLanguage = 'english'; if (null !== $user) { - $defaultUserLanguage = $user->getLocale(); + $langInfo = api_get_language_from_iso($user->getLocale()); + $defaultUserLanguage = $langInfo->getEnglishName(); } $extraFieldValues = new ExtraFieldValue('user'); @@ -259,7 +260,7 @@ if ($value && isset($value['value']) && !empty($value['value'])) { // Create a search-box $searchFilter = ''; -$translate = api_get_configuration_value('translate_html'); +$translate = 'true' === api_get_setting('editor.translate_html'); if ($translate) { $form = new FormValidator('search_simple', 'get', api_get_self().'?'.api_get_cidreq(), null, null, 'inline'); $form->addHidden('cid', api_get_course_int_id()); @@ -281,7 +282,7 @@ if ($translate) { [], true //$addEmptyOptionSelects = false, ); - $form->setDefaults(['extra_language' => $defaultUserLanguage]); + $form->setDefault('extra_language', $defaultUserLanguage); $searchFilter = $form->returnForm(); } @@ -596,6 +597,9 @@ if (is_array($forumCategories)) { $forumCategoryInfo['forums'] = $forumsDetailsList; } + // It set the languages by category + $extraFieldValue = new ExtraFieldValue('forum_category'); + $forumCategoryInfo['extra_fields'] = $extraFieldValue->getAllValuesByItem($categoryId); // Don't show empty categories (for students) if (!api_is_allowed_to_edit()) { if (empty($forumCategoryInfo['forums'])) { diff --git a/public/main/template/default/forum/list.html.twig b/public/main/template/default/forum/list.html.twig index 1b5aa6b3eb..d549ee8937 100644 --- a/public/main/template/default/forum/list.html.twig +++ b/public/main/template/default/forum/list.html.twig @@ -58,7 +58,9 @@ {% set panel_title %} {{ item.title }}{{ item.icon_session }} {% for category_language_item in category_language_array %} + {% if languages[category_language_item | lower] is defined %} + {% endif %} {% endfor %} {% endset %} {% else %} @@ -68,7 +70,9 @@ {{ item.title }}{{ item.icon_session }} {% for category_language_item in category_language_array %} + {% if languages[category_language_item | lower] is defined %} + {% endif %} {% endfor %}
{{ item.tools }}