GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Feature] Allow multiple "Insertion in the form" (dom) blocks per entity by JeremieMercier · Pull Request #941 · pluginsGLPI/fields

Conversation

@JeremieMercier

@JeremieMercier JeremieMercier commented Apr 4, 2025

Copy link
Copy Markdown

This PR provides the ability to define multiple "Insertion in the form" blocks for the same item based on its entity

  • Created a new method findContainers() (based on findContainer()) that returns all 'dom' containers for an item based on its entity (with parent entity handling via getAncestorsOf()).
  • Adapted hooks (pre_item_add, pre_item_update, post_item_add, post_item_update) to manage multiple containers using the _plugin_fields_data_multi array.
  • Updated the populateData() function to extract input values by stripping the prefix, ensuring that data is saved into the correct columns of the injection table.
  • Modified the container.form.php file to "clean" the form data (by removing the prefix) before calling updateFieldsValues(), thereby enabling the saving of domtab containers.

Please test these modifications and verify that everything works as expected for all object types supported by the Fields plugin. Note that my tests were successful, although I focused exclusively on 'Ticket' type objects for my use case.

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.

Issues : #744, #789, #834

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

CorentinS6 and killerwanee reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@stonebuzz
stonebuzz requested review from Rom1-B and stonebuzz April 7, 2025 07:05
@stonebuzz stonebuzz added enhancement feature suggestion labels Apr 7, 2025
@stonebuzz

stonebuzz commented Apr 9, 2025

Copy link
Copy Markdown
Contributor

Hi @JeremieMercier

I am questioning the plugin's ability to reconcile the correct container during API calls, an issue we have encountered in the past. For example, when updating a ticket and including the "fields" in the payload, could you verify this point?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Apr 9, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

Hi @stonebuzz,

I retrieve the block row ID like this:
image

Then, I update the field using the following method:
image

So I haven’t encountered any issue with the API — unless I misunderstood how you're updating the fields via the API?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stonebuzz

stonebuzz commented Apr 9, 2025

Copy link
Copy Markdown
Contributor

It is also possible to update fields from the fields plugin during ticket update.

PUT {{URL_GLPI}} /Ticket/5

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Apr 9, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

Yes, it works

Just include the block ID in the field name, like:
plugin_fields_15_bloconechamponefield

image
image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier JeremieMercier mentioned this pull request Apr 11, 2025
[Feature] Notification target ticket #943
Draft
2 of 4 tasks
@JeremieMercier

JeremieMercier commented Apr 16, 2025

Copy link
Copy Markdown
Author

Hello, do you have time to review the PR ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Apr 16, 2025

Copy link
Copy Markdown
Author

I applied the changes for PHPStan 🤞

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

trasher
trasher reviewed Apr 17, 2025
View reviewed changes
Comment thread inc/container.class.php Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Apr 17, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

I don't understand @trasher

image

With php 7.4 :

image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Rom1-B
Rom1-B reviewed Apr 17, 2025
View reviewed changes
Comment thread inc/container.class.php Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Apr 17, 2025

Copy link
Copy Markdown
Author

A syntax error, it was slipped in after applying the suggestion 😅

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Apr 17, 2025

Copy link
Copy Markdown
Author

Are we good this time ? 😅🤞

JeremieMercier reacted with laugh emoji Rom1-B and JeremieMercier reacted with hooray emoji
All reactions
  • 😄 1 reaction
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Apr 23, 2025

Copy link
Copy Markdown
Author

Hi, what's the next step ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stonebuzz

stonebuzz commented Apr 24, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hi @JeremieMercier

The feature you are proposing is substantial and introduces significant changes. To ensure its smooth integration and functionality, we must be extremely vigilant. This means we need to "lock down" our testing to guarantee that everything works as expected.

It is important to acknowledge that the plugin is already complex to maintain, especially with the new features introduced in GLPI. Given this complexity, we must approach any additional features with caution to ensure they do not further complicate maintenance and support.

To ensure the proper functioning of this PR, here is a concise list of unit tests that should be added:

Unit Tests for findContainers

  1. Retrieve Containers for Specific Itemtype and Entity

    • Verify that findContainers returns the correct containers for a given itemtype and entity.
  2. Retrieve Containers with Subtype

    • Verify that findContainers returns the correct containers when a subtype is specified.
  3. Retrieve Containers with Recursive Entity

    • Verify that findContainers considers recursive entities.

Unit Tests for Hooks

  1. preItemAdd with Multiple Containers

    • Verify that the preItemAdd hook correctly handles data for multiple containers.
  2. postItemAdd with Multiple Containers

    • Verify that the postItemAdd hook correctly updates field values for multiple containers.
  3. preItemUpdate with Multiple Containers

    • Verify that the preItemUpdate hook correctly handles data for multiple containers during item update.

Unit Tests for populateData

  1. populateData with Prefix

    • Verify that populateData correctly extracts field values by removing the prefix.
  2. populateData with Multiple Selection Fields

    • Verify that populateData correctly handles fields allowing multiple selections.

Unit Tests for showForTab

  1. showForTab with Multiple Containers

    • Verify that showForTab correctly displays containers for a given item.
  2. showForTab with Insufficient Rights

    • Verify that showForTab returns nothing if the user does not have sufficient rights on the containers.

Unit Tests for API

  1. Ticket input update

  2. Container update

Unit Tests for rights

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented May 7, 2025

Copy link
Copy Markdown
Author

Hi @stonebuzz Thanks for the message

I fully understand the concerns and the importance of thorough testing.
I'm currently working on implementing the required tests and will make sure all the listed cases are properly covered.

While working on the tests already partially in place, I’ve been able to identify and fix some issues especially related to "dropdown" field handling and container restriction management.

I’ll keep updating here as I progress.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stonebuzz stonebuzz assigned JeremieMercier May 20, 2025
@stonebuzz stonebuzz added the Need unit tests label May 20, 2025
@akstis-typer

akstis-typer commented May 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Hi, @JeremieMercier.
What tool you are using to send HTTP requests?
I'm newby in WEB development so I'm not entirely shure what tool is that.
Thank you :)

Edit: I've done some research and found Postman, as a tool to send HTTP requests and creating API tests

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented May 25, 2025

Copy link
Copy Markdown
Author

I’ve added all the requested unit tests (except the API ones):

  • findContainers : basic cases, sub-types, entity recursion
  • Hooks: preItem, postItemAdd, preItemUpdate with multiple containers
  • populateData: prefix handling and multi-selection fields
  • showForTab: displaying multiple containers and checking rights

Please note I’m not a testing expert, so the tests may not follow every usual best practice. Feel free to share any feedback so I can improve.

The API tests still need to be written by whoever is willing to tackle them.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier
JeremieMercier force-pushed the feature/multiple-dom-blocks branch 2 times, most recently from 051fcd8 to cf0f71f Compare May 29, 2025 16:46
@CorentinS6

CorentinS6 commented Jul 18, 2025

Copy link
Copy Markdown

Hello,
Tank you very much @JeremieMercier for this work. That's a realy needed feat for us !
Any followup of this PR ?
Best regards

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Jul 21, 2025

Copy link
Copy Markdown
Author

Hello, Tank you very much @JeremieMercier for this work. That's a realy needed feat for us ! Any followup of this PR ? Best regards

Hello @CorentinS6, From my side everything seems good, it remains to be seen if a developer of the project can finalize the tests

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CorentinS6

CorentinS6 commented Aug 26, 2025

Copy link
Copy Markdown

And code generated by AI ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier

JeremieMercier commented Aug 28, 2025

Copy link
Copy Markdown
Author

And code generated by AI ?

Hello, All the logic is 100% mine, however for the tests, it's another story, I used AI to learn and understand the use of the tests in addition to videos like this one from Grafikart, but as I said, I'm not an expert..., the tests can also be redone by a more competent person if necessary knowing that basically, there were no tests set up on the plugin.

CorentinS6 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CorentinS6

CorentinS6 commented Aug 28, 2025

Copy link
Copy Markdown

@stonebuzz , is this work good enough for the merge now?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier
JeremieMercier force-pushed the feature/multiple-dom-blocks branch from af76515 to 1aa2594 Compare October 7, 2025 19:35
Rom1-B
Rom1-B requested changes Oct 9, 2025
View reviewed changes
Comment thread tests/bootstrap.php Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread composer.json Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread phpunit.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier
JeremieMercier requested a review from Rom1-B October 9, 2025 09:16
@JeremieMercier
JeremieMercier force-pushed the feature/multiple-dom-blocks branch from 7ee0d82 to aaf0f14 Compare October 10, 2025 20:29
@JuanPabloToniolo-Udesa

JuanPabloToniolo-Udesa commented Dec 12, 2025

Copy link
Copy Markdown

This will be very useful, now I can only add one block to all entities, I need one per entity and this seems to solve the problem, is there something I can help with?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@killerwanee

killerwanee commented Feb 18, 2026

Copy link
Copy Markdown

Hi,
I have some needs for that type of thing.
Like i have an entity that needs different informations on tickets than the other, but even tho my fields are created seperately on the entities, i'm blocked because it'es for the same "type".
Is there a way to do this in glpi 11 ?
Thank you

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Rom1-B
Rom1-B requested changes Jul 22, 2026
View reviewed changes
Comment thread front/container.form.php Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread inc/container.class.php Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread inc/field.class.php Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread composer.lock Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/PluginFieldsContainerTest.php Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier
JeremieMercier force-pushed the feature/multiple-dom-blocks branch from 9f6178f to 06a3082 Compare July 31, 2026 14:17
@JeremieMercier
[Feature] Allow multiple "Insertion in the form" (dom) blocks per entity
f318518
Provide the ability to define multiple 'dom' blocks for the same item
based on its entity.

- New PluginFieldsContainer::findContainers() returning all active 'dom'
  containers applicable to an item and its entity (with parent entity
  handling via getAncestorsOf(), recursivity and profile rights checks).
- Hooks (pre_item_add, pre_item_update, post_item_add) handle multiple
  containers through the _plugin_fields_data_multi array.
- populateData() extracts input values from per-container prefixed keys
  (plugin_fields_{container_id}_...), with fallback to unprefixed keys.
- fields.html.twig prefixes input names with the container id.
- container.form.php strips the container prefix before calling
  updateFieldsValues(), enabling domtab containers saving.
- showForTab() renders every applicable container, each with its own
  scoped refresh script.
- Add PHPUnit coverage: findContainers (subtypes, entity recursion),
  multi-container hooks, populateData prefix and multi-selection
  handling, showForTab display and rights.

Closes pluginsGLPI#744, pluginsGLPI#789, pluginsGLPI#834
@JeremieMercier
JeremieMercier force-pushed the feature/multiple-dom-blocks branch from 06a3082 to f318518 Compare July 31, 2026 14:24
@JeremieMercier
JeremieMercier requested a review from Rom1-B July 31, 2026 14:32
@JeremieMercier

JeremieMercier commented Jul 31, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

I originally opened this PR because it was an internal feature request for how we use the GLPI plugin. In the end, we managed without it, so I kind of let it drop especially with the commit lag and conflicts to deal with.

Anyway, I've decided to pick it back up: even though we don't need the feature ourselves anymore, it could still be useful to others since it's quite heavily requested ^^

killerwanee reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Rom1-B
Rom1-B reviewed Aug 3, 2026
View reviewed changes
Comment thread inc/container.class.php Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier
JeremieMercier requested a review from Rom1-B August 7, 2026 09:52
Rom1-B
Rom1-B requested changes Aug 7, 2026
View reviewed changes

@Rom1-B Rom1-B left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Several errors in the CI

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JeremieMercier reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
JeremieMercier added 3 commits August 7, 2026 12:29
@JeremieMercier
[CI] Add CHANGELOG entry, apply php-cs-fixer and rector fixes
d9ab144
@JeremieMercier
[Fix] Restore legacy field input handling and fix multi-dom regressions
b03d674
- populateData(): accept bare field names (API/external callers) as fallback
  of the new prefixed input names
- populateData(): treat null input values as not provided (isset semantics),
  fixes SQL error on empty dropdown submitted from a form destination
- preItem(): restore explicit c_id support (tab forms, form destinations)
- findContainers(): JSON-encode itemtype for JSON_CONTAINS to support
  namespaced itemtypes on strict MySQL
- richtext companion inputs stored under the column-based key expected
  by addRichTextFiles()
- tests: multiple dom containers per itemtype are now expected to be allowed
- tests: do not leak $_REQUEST['massiveaction'] between test files
@JeremieMercier
Merge remote-tracking branch 'upstream/main' into feature/multiple-do…
6882401
…m-blocks

# Conflicts:
#	CHANGELOG.md
@JeremieMercier
JeremieMercier requested a review from Rom1-B August 7, 2026 11:25
@JeremieMercier

JeremieMercier commented Aug 28, 2026

Copy link
Copy Markdown
Author

hi @Rom1-B, and now ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JeremieMercier
Merge remote-tracking branch 'upstream/main' into feature/multiple-do…
2a5d81d
…m-blocks
@stonebuzz

stonebuzz commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

I’ll put the PR back into draft status, as it is not yet complete (see conflicts) and has not been updated for some time.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stonebuzz
stonebuzz marked this pull request as draft October 1, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@trasher trasher trasher left review comments
@stonebuzz stonebuzz Awaiting requested review from stonebuzz
@Rom1-B Rom1-B Awaiting requested review from Rom1-B

Requested changes must be addressed to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@JeremieMercier JeremieMercier

Labels

enhancement feature suggestion Need unit tests

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@JeremieMercier @stonebuzz @akstis-typer @CorentinS6 @JuanPabloToniolo-Udesa @killerwanee @trasher @Rom1-B
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.