1

Is there a hook one can use on, say, a node edit page that will print the $form array after it has been completely processed? I'm customizing a Paragraph edit form inside a Node edit form and thus altering the Paragraphs Field Widget -> Subform. The subform's '#process' key contains a further function to execute:

enter image description here

But if, say, I print the $form var inside hook_node_form_alter, this #process still has not executed.

The larger problem is that my subform contains a custom submit handler that is not being called when I submit the subform and I'd like to print the entire form array after processing to ensure the submit handler is actually there in the $form array. If the problem of custom submit handlers not firing inside subforms sounds familiar, let me know

EDIT

Relative to the larger problem, this is what my embedded form looks like after all processing completes (i.e. printed in an #after_build)

enter image description here

6
  • When I've altered paragraph forms in the past I've used hook_field_widget_WIDGET_TYPE_form_alter(), e.g. my_module_field_widget_entity_reference_paragraphs_form_alter(). I can't tell for certain, but it doesn't sound like that's what you're doing - I think you'll find it's easier to work with.
    – sonfd
    Commented Feb 12, 2021 at 21:39
  • I'm using hook_field_widget_entity_reference_paragraphs_form_alter which is working great for getting the form to display the way I want. In essence, I am placing another form within this paragraphs (e.g. the widget has its own paragraph subform and another form). This other form has a custom submit handler that is supposed to fire: '#submit' => [[$this, 'updateSegmentSet']], but when I print debug in that function, it never appears to fire (the form does submit and return empty ajax data though)
    – plambre
    Commented Feb 12, 2021 at 22:00
  • 1
    Basically you could use any hook in the theming level because the result of processing ends up in form elements ready to be rendered. Within the form building process you could add a #after_build callback to the widget element. Probably the easiest way to debug these things is to set a breakpoint in Xdebug in the form builder and step through the code to see why it doesn't fire.
    – 4uk4
    Commented Feb 13, 2021 at 10:04
  • One thing I've done is debug around public function executeSubmitHandlers specifically the line $handlers = $form_state->getSubmitHandlers() and noted that the custom handler isn't even there, only handlers that apply to the greater Node Edit form (since its the entire Node Edit form thats submitted back to the form builder)
    – plambre
    Commented Feb 13, 2021 at 16:05
  • Could the issue be that the embedded form isnt wrapped in a <form> container? So when <input type='submit' is pressed, it bubbles all the way up to the greater form and ignores the custom submit handlers attached? What's strange is that this type of ajax functionality for adding/removing elements from a Node Edit form is commonplace and the submit buttons that power it don't appear to be wrapped in <form>'s
    – plambre
    Commented Feb 13, 2021 at 16:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.