Commit d503cdd6 authored by Liam Morland's avatar Liam Morland
Browse files

ISTWCMS-4086: Redirect to layout edit page on node creation

parent 2cc80f16
......@@ -5,6 +5,31 @@
* Workbench module file.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function uw_sites_all_form_node_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
// Only on node add forms for content types that use Layout Builder, add
// submit handler.
$fieldDefinitions = $form['#process'][1][0]->get('fieldDefinitions');
if (isset($fieldDefinitions['layout_builder__layout']) && substr($form_id, -10) !== '_edit_form') {
$form['actions']['submit']['#submit'][] = '_uw_sites_all_form_node_form_submit';
}
}
/**
* Form submit handler.
*/
function _uw_sites_all_form_node_form_submit(array $form, FormStateInterface &$form_state): void {
// Redirect to layout tab on form submit.
$nid = $form_state->getValue('nid');
if ($nid) {
$form_state->setRedirect('layout_builder.overrides.node.view', ['node' => $nid]);
}
}
/**
* Implements hook_link_alter().
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment