I use the Inline Entity Form module to build nested multiple forms. I have a design form in which there is an inline form - garment. And inside the garment form, there is a product field.

In the hook_inline_entity_form_entity_form_alter() I get $field_product_user_input

$field_product_user_input = $form_state->getUserInput()['field_design']['form']['inline_entity_form']['entities']['0']['form']['field_garment']['form']['inline_entity_form']['entities']['0']['form']['field_product']['0']['target_id'];

And I get what I need. But when I add a second inline entity form in the design, it gets the first garment's field value. This occurs because the second form has a key of '1' in the 'entities' array, while the code above uses '0' for the first form.

$form_state->getUserInput() show this result:

result = [
  'field_design' => [
    'form' => [
      'inline_entity_form' => [
        'entities' => [
          '0' => [
            'form' => [
              'field_garment' => [
                'form' => [
                  'inline_entity_form' => [
                    'entities' => [
                      '0' => [...],
                      '1' => [...] // new garment
                    ],
                  ],
                ],
              ],
            ],
          ],
        ],
      ],
    ],
  ],
];

Comments

jaypan’s picture

I don't have the answer, but I will note that getUserInput() is unsafe as the values are unsanitized.

Contact me to contract me for D7 -> D10/11 migrations.