I'm porting a module that currently works with Blocks/BlockForms to Paragraphs/NodeForms. I'm inserting an embedded form inside a Paragraph inside a Node Edit page using a
hook_field_widget_entity_reference_paragraphs_form_alter
. The general structure where the form gets inserted is:
$form['field']['widget'][0]['settings'][form here]
After this the form displays as expected on the node edit page.
The inserted form goes through a number of #process
steps. The element in question is a select form that when the button underneath it is pressed, is supposed to retrieve some data via a custom submit handler and place it on the page with ajax:
The array for this element looks like this:
You can see the custom submit handler that is supposed to fire when 'Select Segment Set' is pressed
After debugging, I've found that the entire NodeForm appears to be submitted to the backend, and the only handler that is found is from some other field that uses ajax. In short 'updateSegmentSet' is never discovered as a submit handler. When I debug the original module based on block/blockforms, I do see the correct submit handler being discovered. Now in the latter case, of course a blockForm is submitted to the back end with the correct plugin. Given that this is basically a form within a form within a form, is there something special I have to do to get the custom submit handler to run? I've read a few things online e.g. the 'settings' key and '#tree' = true.
EDIT
The Ajax property looks like this:
'#ajax' => [
'callback' => [$this, 'updateSegmentSetAjax'],
'wrapper' => $wrapper_id,
],
public function updateSegmentSetAjax(array &$form, FormStateInterface $form_state) {
$button = $form_state->getTriggeringElement();
// Go one level up in the form, to the widgets container.
return NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));
}
As best I can tell, this is never called either.
'#ajax' => ['callback' => [$this, '::updateSegmentSetAjax']]
and not'#ajax' => ['callback' => ['::updateSegmentSetAjax]]
'callback' => '::ajaxCallback',