I have a node form exposed in the front-end to allow visitors to add their organisation to the list of partners. Below the form, I have exposed view block with the list of existing partners.
When a visitor enters a new organisation to the list I want the form just to add a new node type "partner" and reload the page/block without redirecting to the node content (node/[node ID]).
At the beginning I ed taxonomy terms instead and it worked as it should, now I want to achieve the same with node entity.
I have tried various solutions but none of it works correctly and I didn't find much by googling it.
For example, this is not functioning:
function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) {
if ($form_id == 'node_partners_form') {
$form_state->disableRedirect(); // This is not functioning
}
}
This does not work either:
function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) {
if ($form_id == 'node_partners_form') {
foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'THEME_node_form_submit';
}
}
}
}
function THEME_node_form_submit($form, &$form_state) {
$form_state->setRedirect(Url::fromUri('internal:/node/1')->toString());
}
=> Error: Route /partners does not exist.
Value of attribute action in the exposed node form is correct and therefore I think the proper solution should be elsewhere then altering form properties - probably it has more with the Drupal behaviour after adding a new node.
<form action="/en/partners">...</form>