I have implemented hook_field_widget_form_alter()
to add a new #process
array item.
E.g.
hook_field_widget_form_alter() {
$element['#process'][] = ['custom_process_function'];
}
This part works fine to add in a new submit button that will save the contents of the current form send the user off to another page. E.g.\
custom_process_function(&$element) {
$element['new_button'] = [
'#type' => 'submit',
'#value' => t('Upload new'),
'#submit' => [
[
"Drupal\inline_entity_form\ElementSubmit",
"trigger",
],
[
AddNewSubmitHandler::class,
'handle',
],
],
'#trigger' => $this->fieldName,
'#name' => $this->fieldName . '_add_new' . '_' . md5(json_encode($this->fieldParents)),
'#ief_submit_trigger' => TRUE,
'#ief_submit_trigger_all' => TRUE,
'#referenceType' => $this->fieldReferenceType,
'#referenceBundles' => $this->fieldReferenceBundles,
'#referenceEntityType' => $this->entityType,
'#referenceEntityBundle' => $this->bundle,
'#allowedFileTypes' => $this->allowedFileTypes,
'#validate' => ['_custom_validate_function'],
];
}
However, the problem lies when it is loaded into Inline Entity Form field and then an ajax event is triggered.
In my case, I am using an Entity Browser field within this form and when I click the Remove
button and then click my custom button, the $formState->getTriggeringElement()
is set to the next submit button that was on the original form, not even the next one in the Inline Entity Form.
Can anyone shed any light on why this is happening or how to fix it?