Skip to content

generate_item.html.twig passes array as condition to dropdownField, causing strlen() TypeError on PHP 8.x #557

@lestatlion

Description

@lestatlion

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

GLPI Version

11.0.6

Plugin version

2.12.6

Bug description

I've been hitting an issue with the Generate items massive action since upgrading to GLPI 11.0.5+ and order management 2.12.6, and after some digging I was able to identify the root cause. Sharing it here in case others are affected and to hopefully get a fix in a future release.

Description

When using the Generate items massive action on an order, a fatal PHP exception is thrown, preventing the form from rendering entirely.

Error

Twig\Error\RuntimeError: "An exception has been thrown during the rendering of a template
("strlen(): Argument #1 ($string) must be of type string, array given")
in "@order/generate_item.html.twig" at line 238."

Previous: strlen(): Argument #1 ($string) must be of type string, array given
./src/Dropdown.php:185
./src/CommonDBTM.php:4194 Dropdown::show()
.../View/Extension/ItemtypeExtension.php:99 CommonDBTM::dropdown()

Steps to Reproduce

  1. Open any order containing items
  2. Select one or more items
  3. Click Actions > Generate items
  4. The massive action sub-form fails to render and the error is logged

Root Cause

In templates/generate_item.html.twig around line 238, the condition parameter passed to fields.dropdownField() for the Group dropdown is a Twig object (array), not a string:

{{ fields.dropdownField(
    'Group',
    "id[" ~ item.i ~ "][groups_id]",
    item.groups_id,
    "",
    fields_option|merge({
        'entity': -1,
        'condition': {'is_itemgroup': 1},

This array propagates down to Dropdown::show() in GLPI core (src/Dropdown.php:185), which calls strlen($condition) and throws a TypeError under PHP 8.x strict type enforcement.

Environment

GLPI version 11.0.5
Plugin Order version 2.12.6
PHP version 8.5.2
Deployment Kubernetes / Docker

Expected Behavior

The condition parameter should either be converted to a SQL-compatible string before being passed to the core dropdown method, or fields.dropdownField() should properly forward array conditions in a format compatible with Dropdown::show().

Relevant log output

glpi.CRITICAL:   *** Uncaught PHP Exception Twig\Error\RuntimeError: "An exception has been thrown during the rendering of a template ("strlen(): Argument #1 ($string) must be of type string, array given") in "@order/generate_item.html.twig" at line 238." at generate_item.html.twig line 238
  Backtrace :
  ...ace/order/templates/generate_item.html.twig:238 
  ./vendor/twig/twig/src/Template.php:358            Twig\Template->yield()
  ./vendor/twig/twig/src/TemplateWrapper.php:61      Twig\Template->display()
  .../Glpi/Application/View/TemplateRenderer.php:188 Twig\TemplateWrapper->display()
  /var/glpi/marketplace/order/inc/link.class.php:168 Glpi\Application\View\TemplateRenderer->display()
  /var/glpi/marketplace/order/inc/link.class.php:564 PluginOrderLink->showItemGenerationForm()
  ./src/MassiveAction.php:815                        PluginOrderLink::showMassiveActionsSubForm()
  ./ajax/dropdownMassiveAction.php:59                MassiveAction->showSubForm()
  ...Glpi/Controller/LegacyFileLoadController.php:64 require()
  ./vendor/symfony/http-kernel/HttpKernel.php:181    Glpi\Controller\LegacyFileLoadController->__invoke()
  ./vendor/symfony/http-kernel/HttpKernel.php:76     Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  ./vendor/symfony/http-kernel/Kernel.php:208        Symfony\Component\HttpKernel\HttpKernel->handle()
  ./public/index.php:71                              Symfony\Component\HttpKernel\Kernel->handle()
  Previous: strlen(): Argument #1 ($string) must be of type string, array given
  ./src/Dropdown.php:185                             
  ./src/CommonDBTM.php:4167                          Dropdown::show()
  ...ication/View/Extension/ItemtypeExtension.php:99 CommonDBTM::dropdown()
  ...es/b4/b4f642ea49ce56402d71844b8dd63acc.php:2175 Glpi\Application\View\Extension\ItemtypeExtension->getItemtypeDropdown()
  .../twig/twig/src/Extension/CoreExtension.php:2116 __TwigTemplate_df76208fab6e4c94620d15445f2fa953->{closure:{closure:__TwigTemplate_df76208fab6e4c94620d15445f2fa953::macro_dropdownField():2112}:2172}()
  ...es/b4/b4f642ea49ce56402d71844b8dd63acc.php:2172 Twig\Extension\CoreExtension::captureOutput()
  .../twig/twig/src/Extension/CoreExtension.php:2116 __TwigTemplate_df76208fab6e4c94620d15445f2fa953->{closure:__TwigTemplate_df76208fab6e4c94620d15445f2fa953::macro_dropdownField():2112}()
  ...es/b4/b4f642ea49ce56402d71844b8dd63acc.php:2112 Twig\Extension\CoreExtension::captureOutput()
  ...tes/b7/b74e6834ba866549bacb6d32cca9565e.php:376 __TwigTemplate_df76208fab6e4c94620d15445f2fa953->macro_dropdownField()
  ./vendor/twig/twig/src/Template.php:402            __TwigTemplate_643317242086291f0201a9c78d5830e9->doDisplay()
  ./vendor/twig/twig/src/Template.php:358            Twig\Template->yield()
  ./vendor/twig/twig/src/TemplateWrapper.php:61      Twig\Template->display()
  .../Glpi/Application/View/TemplateRenderer.php:188 Twig\TemplateWrapper->display()
  /var/glpi/marketplace/order/inc/link.class.php:168 Glpi\Application\View\TemplateRenderer->display()
  /var/glpi/marketplace/order/inc/link.class.php:564 PluginOrderLink->showItemGenerationForm()
  ./src/MassiveAction.php:815                        PluginOrderLink::showMassiveActionsSubForm()
  ./ajax/dropdownMassiveAction.php:59                MassiveAction->showSubForm()
  ...Glpi/Controller/LegacyFileLoadController.php:64 require()
  ./vendor/symfony/http-kernel/HttpKernel.php:181    Glpi\Controller\LegacyFileLoadController->__invoke()
  ./vendor/symfony/http-kernel/HttpKernel.php:76     Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  ./vendor/symfony/http-kernel/Kernel.php:208        Symfony\Component\HttpKernel\HttpKernel->handle()
  ./public/index.php:71                              Symfony\Component\HttpKernel\Kernel->handle()

Page URL

No response

Steps To reproduce

  1. Open any order containing items
  2. Select one or more items
  3. Click Actions > Generate items
  4. The massive action sub-form fails to render and the error is logged

Your GLPI setup information

GLPI: 11.0.6 ( => /var/www/glpi)
Installation mode: DOCKER
Current language: en_US
Source Integrity: OK

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions