FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Feature] Allow multiple "Insertion in the form" (dom) blocks per entity by JeremieMercier · Pull Request #941 · pluginsGLPI/fields · GitHub

[Feature] Allow multiple "Insertion in the form" (dom) blocks per entity - #941

Open
JeremieMercier wants to merge 4 commits into
pluginsGLPI:mainfrom
JeremieMercier:feature/multiple-dom-blocks
Open

[Feature] Allow multiple "Insertion in the form" (dom) blocks per entity#941
JeremieMercier wants to merge 4 commits into
pluginsGLPI:mainfrom
JeremieMercier:feature/multiple-dom-blocks

Conversation

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

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?

JeremieMercier commented Apr 9, 2025
edited
Loading

Copy link
Copy Markdown
Author

Hi @stonebuzz,

I retrieve the block row ID like this:

Then, I update the field using the following method:

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

Copy link
Copy Markdown
Contributor

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

PUT {{URL_GLPI}} /Ticket/5

JeremieMercier commented Apr 9, 2025
edited
Loading

Copy link
Copy Markdown
Author

Yes, it works

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


Copy link
Copy Markdown
Author

Hello, do you have time to review the PR ?

Copy link
Copy Markdown
Author

I applied the changes for PHPStan 🤞

Comment thread inc/container.class.php Outdated

JeremieMercier commented Apr 17, 2025
edited
Loading

Copy link
Copy Markdown
Author

I don't understand @trasher

With php 7.4 :

Comment thread inc/container.class.php Outdated

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Author

Are we good this time ? 😅🤞

Copy link
Copy Markdown
Author

Hi, what's the next step ?

stonebuzz commented Apr 24, 2025
edited
Loading

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

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.

akstis-typer commented May 23, 2025
edited
Loading

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

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.

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

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

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

Copy link
Copy Markdown

And code generated by AI ?

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.

Copy link
Copy Markdown

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

JeremieMercier force-pushed the feature/multiple-dom-blocks branch from af76515 to 1aa2594 Compare October 7, 2025 19:35
Comment thread tests/bootstrap.php Outdated
Comment thread composer.json Outdated
Comment thread phpunit.xml Outdated
JeremieMercier requested a review from Rom1-B October 9, 2025 09:16
JeremieMercier force-pushed the feature/multiple-dom-blocks branch from 7ee0d82 to aaf0f14 Compare October 10, 2025 20:29

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?

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

Comment thread front/container.form.php Outdated
Comment thread inc/container.class.php
Comment thread inc/field.class.php Outdated
Comment thread composer.lock
Comment thread tests/PluginFieldsContainerTest.php Outdated
JeremieMercier force-pushed the feature/multiple-dom-blocks branch from 9f6178f to 06a3082 Compare July 31, 2026 14:17
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 force-pushed the feature/multiple-dom-blocks branch from 06a3082 to f318518 Compare July 31, 2026 14:24
JeremieMercier requested a review from Rom1-B July 31, 2026 14:32

JeremieMercier commented Jul 31, 2026
edited
Loading

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 ^^

Comment thread inc/container.class.php
JeremieMercier requested a review from Rom1-B August 7, 2026 09:52

Rom1-B 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Several errors in the CI

- 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 requested a review from Rom1-B August 7, 2026 11:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL