Skip to content

[ILIAS 10] [FIX] TestQuestionPool: Translate plugin question types#11642

Open
Saaweel wants to merge 2 commits into
ILIAS-eLearning:release_10from
surlabs:ilias10_TA_fix_QPL_labels
Open

[ILIAS 10] [FIX] TestQuestionPool: Translate plugin question types#11642
Saaweel wants to merge 2 commits into
ILIAS-eLearning:release_10from
surlabs:ilias10_TA_fix_QPL_labels

Conversation

@Saaweel

@Saaweel Saaweel commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Fix: Plugin question type is not translated in question pool

Mantis: #0047758

Problem

The question list in a question pool was not translating the type name of plugin questions. The ilAssQuestionList::load function was calling $this->lng->txt($row['question_type']) directly, bypassing the plugin's own translation mechanism. The same issue existed in assQuestionGUI::outQuestionType(), used by ilTestCorrectionsGUI::populatePageTitleAndDescription.

Solution

Added a getQuestionTypeTranslation() helper method in both ilAssQuestionList and assQuestionGUI that checks whether the question belongs to a plugin and, if so, delegates to $plugin->getQuestionTypeTranslation(). Otherwise it falls back to the standard language translation.

Files changed

  • components/ILIAS/TestQuestionPool/classes/class.ilAssQuestionList.php
  • components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php

How to test

  1. Install a question type plugin.
  2. Add a question of that plugin to a question pool.
  3. Open the question list in the pool — the type column should now show the plugin's translated type name.
  4. Also verify the question type label in the test corrections view (ilTestCorrectionsGUI).

@Saaweel Saaweel self-assigned this Jun 3, 2026
@Saaweel Saaweel added bugfix php Pull requests that update Php code labels Jun 3, 2026
@Saaweel Saaweel changed the title [FIX] TestQuestionPool: Translate plugin question types [ILIAS 10] [FIX] TestQuestionPool: Translate plugin question types Jun 3, 2026
@dsstrassner

Copy link
Copy Markdown
Contributor

PR for 11: #11643 Trunk: #11644

@kergomard kergomard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Saaweel

Thank you very much for the PR. I would kindly ask you to implement the following changes:

  • Please do not introduce any variable in lowerCamelCase. All variables MUST be in snake_case.
  • Please do not introduce any usages of the $DIC in classes that fully rely on dependency injection and never introduce a usage of the $DIC in the middle of the class (if there absolutely needs to be a usage of the $DIC it must be in the constructor). In this case it should be injected between ilComponentsRepository and ?ilNotesService.

Thanks again and best,
@kergomard

@Saaweel

Saaweel commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kergomard, thanks for the feedback!

  • Renamed $questionData to $question_data in the new method to follow snake_case convention.
  • Removed the global $DIC usage from getQuestionTypeTranslation() and moved it to the constructor, where ilComponentFactory is now resolved and stored as a private property.

Regarding the injection as a constructor parameter: ilAssQuestionList is instantiated in numerous files across several components, and adding a required parameter would require changes in all of them. Since I am not the maintainer of those components, I preferred to keep the impact minimal and resolve the dependency in the constructor instead.

Regards,
@Saaweel

@matheuszych

Copy link
Copy Markdown
Contributor

Hello @Saaweel ,

first of all, thank you for analyzing the issue and implementing the fix!

Could we reuse the same implementation that assQuestionGUI::getQuestionTypeTranslation uses inside ilAssQuestionList::getQuestionTypeTranslation as well? That would streamline the approach and keep the translation logic consistent in both places.

Something like this:

    private function getQuestionTypeTranslation(array $question_data): string
    {
        $local_dic = \ILIAS\TestQuestionPool\QuestionPoolDIC::dic();
        $this->questionrepository = $local_dic['question.general_properties.repository'];

        $question_properties = $this->questionrepository->getForQuestionId($question_data['obj_fi']);
        
        $type_name = $question_properties?->getTypeName($this->lng);
        if ($type_name !== null && $type_name !== '') {
            return $type_name;
        }

        return $this->lng->txt($question_data['type_tag']);
    }

Of course without the $local_dic inside of the method itself.

Best regards
@matheuszych

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix php Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants