Skip to content

Feat split tree dropdown question#22

Open
Lainow wants to merge 20 commits intomainfrom
feat-split-tree-dropdown-question
Open

Feat split tree dropdown question#22
Lainow wants to merge 20 commits intomainfrom
feat-split-tree-dropdown-question

Conversation

@Lainow
Copy link

@Lainow Lainow commented Feb 12, 2026

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !41364
  • Here is a brief description of what this PR does
    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
image

After
image

@Lainow Lainow self-assigned this Feb 12, 2026
Copy link
Contributor

@ccailly ccailly left a comment

Choose a reason for hiding this comment

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

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.

Image Image Image

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.

@Lainow Lainow requested a review from ccailly March 3, 2026 13:48
Lainow and others added 2 commits March 4, 2026 13:47
Co-authored-by: Clément Cailly <42278610+ccailly@users.noreply.github.com>
@Lainow Lainow removed the request for review from AdrienClairembault March 4, 2026 14:03
@Lainow Lainow requested review from AdrienClairembault and removed request for AdrienClairembault March 4, 2026 14:19
@Lainow Lainow requested a review from stonebuzz March 12, 2026 15:15
Comment on lines +126 to +139
$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']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use $this->render() directly, which will handle the response creation for you.

Copy link
Author

@Lainow Lainow Mar 18, 2026

Choose a reason for hiding this comment

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

Without the return new Response() statement, it doesn't seem to work.

image

#[Override]
public function prepareEndUserAnswer(Question $question, mixed $answer): mixed
{
$question->fields['type'] = QuestionTypeItemDropdown::class;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks weird, what is the reason for setting the type to the parent like that?

Copy link
Author

Choose a reason for hiding this comment

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

Because without specifying the response type, the value selected in the form is not saved. Calling it before parent::prepareEndUserAnswer allows me to tell GLPI to treat the response as a simple drop-down list.

image

Lainow and others added 3 commits March 17, 2026 12:33
Co-authored-by: Adrien Clairembault <42734840+AdrienClairembault@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants