From 648503c1eb31901218ad449828733b58c75a3979 Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Tue, 8 Aug 2023 10:02:33 -0300 Subject: [PATCH] Add media save redirect. --- islandora.module | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/islandora.module b/islandora.module index 691767140..8d4bc9059 100644 --- a/islandora.module +++ b/islandora.module @@ -332,6 +332,7 @@ function islandora_form_alter(&$form, FormStateInterface $form_state, $form_id) if ($node) { $form['name']['widget'][0]['value']['#default_value'] = $node->getTitle(); } + $form['actions']['submit']['#submit'][] = 'islandora_media_custom_form_submit'; } } @@ -387,6 +388,20 @@ function islandora_form_alter(&$form, FormStateInterface $form_state, $form_id) return $form; } +/** + * Redirect submit handler for media save. + */ +function islandora_media_custom_form_submit(&$form, FormStateInterface $form_state) { + $params = \Drupal::request()->query->all(); + + if (!empty($params)) { + $target_id = $params['edit']['field_media_of']['widget'][0]['target_id']; + $url = Url::fromRoute('entity.node.canonical', ['node' => $target_id]); + $form_state->setRedirectUrl($url); + } + +} + /** * Implements a submit handler for the delete form. */