Conversation
ccailly
left a comment
There was a problem hiding this comment.
I tried it and it works pretty well.
However, I think you forgot to handle the advanced configuration of the extended question type.
If I choose an item other than the default root as the root, it seems to break.
By the way, it would probably be more relevant to extend QuestionTypeItemDropdown rather than QuestionTypeItem. Certain specific behaviors are required for CommonTreeDropdown (this case, for example: glpi-project/glpi#19967).
The QuestionTypeItemDropdown class probably cannot be extended at present; a fix would need to be made to the core to remove the final attribute.
Co-authored-by: Clément Cailly <42278610+ccailly@users.noreply.github.com>
| $html = $twig->render( | ||
| '@advancedforms/tree_cascade_dropdown_children.html.twig', | ||
| [ | ||
| 'select_id' => $select_id, | ||
| 'children' => $children, | ||
| 'final_field_name' => $field_name, | ||
| 'aria_label' => $aria_label, | ||
| 'itemtype' => $itemtype, | ||
| 'condition_param' => $condition_param, | ||
| 'ajax_limit_count' => is_numeric($CFG_GLPI['ajax_limit_count'] ?? 10) ? (int) ($CFG_GLPI['ajax_limit_count'] ?? 10) : 10, | ||
| ], | ||
| ); | ||
|
|
||
| return new Response($html, Response::HTTP_OK, ['Content-Type' => 'text/html; charset=UTF-8']); |
There was a problem hiding this comment.
You can use $this->render() directly, which will handle the response creation for you.
| #[Override] | ||
| public function prepareEndUserAnswer(Question $question, mixed $answer): mixed | ||
| { | ||
| $question->fields['type'] = QuestionTypeItemDropdown::class; |
There was a problem hiding this comment.
This looks weird, what is the reason for setting the type to the parent like that?
Co-authored-by: Adrien Clairembault <42734840+AdrienClairembault@users.noreply.github.com>


Checklist before requesting a review
Please delete options that are not relevant.
Description
Added a new question type called Tree Cascade Dropdown, allowing the names of ITIL Locations and Categories to be separated into several dropdowns. (As the splitcat plugin did).
Screenshots (if appropriate):
Before

After
