2

I have a use case where I have a custom submit button on a node edit form that will take the user off to another page to do some other editing.

If the user has made some changes to the node, such as changed the title, I need to save the current node before redirecting them off to the new page (along with some other generated ID's).

For the life of me, I cant seem to see how I can save the changes to the node in my custom submit handler.
I have tried using $formState->prepareCallback('::submitform()) but that doesn't seem to do what I expected of processing the form.

Anyone done this before or got any good ideas?

2

Typically, I found the answer 10 minutes after posting!

For anyone else, in your custom submit handler get the form object from the form state.

$formObj = $formState->getFormObject();

You can then call submitForm() on the form object and pass the form and form state variables.

$formObj->submitForm($form, $formState);

Then finally just simply trigger the save() function on the object.

$formObj->save($form, $formState);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.