From fdfdd874721146bd4c171a3f1ca39284409e49be Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Tue, 8 Aug 2023 10:02:33 -0300 Subject: [PATCH 1/3] Add media save redirect. --- islandora.module | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/islandora.module b/islandora.module index 69176714..8d4bc905 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. */ From c2cd14cfd56c4daf98f6ba748333ccaba2fa6c0d Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Fri, 11 Aug 2023 14:57:14 -0300 Subject: [PATCH 2/3] Add config option to redirect after media add. --- config/schema/islandora.schema.yml | 3 +++ islandora.install | 14 ++++++++++++++ islandora.module | 16 +++++++++------- src/Form/IslandoraSettingsForm.php | 9 +++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/config/schema/islandora.schema.yml b/config/schema/islandora.schema.yml index 86b65fd0..89c1b58a 100644 --- a/config/schema/islandora.schema.yml +++ b/config/schema/islandora.schema.yml @@ -17,6 +17,9 @@ islandora.settings: delete_media_and_files: type: boolean label: 'Node Delete with Media and Files' + redirect_after_media_save: + type: boolean + label: 'Redirect to node after media save.' upload_form_location: type: string label: 'Upload Form Location' diff --git a/islandora.install b/islandora.install index ad2eb8e1..01e5a467 100644 --- a/islandora.install +++ b/islandora.install @@ -212,3 +212,17 @@ function islandora_update_8007() { // have the here, just in case? throw new UpdateException('Failed; hit the end of the update hook implementation, which is not expected.'); } + +/** + * Set config to no redirect after media save. + */ +function islandora_update_8008() { + $config = \Drupal::configFactory()->getEditable('islandora.settings'); + if ($config) { + $config->set('redirect_after_media_save', FALSE); + $config->save(TRUE); + return t('A new configuration option, "Redirect after media save" is now available. + It has been turned off to preserve existing behaviour. To enable this setting visit + Configuration > Islandora > Core Settings.'); + } +} diff --git a/islandora.module b/islandora.module index 8d4bc905..8d443e1c 100644 --- a/islandora.module +++ b/islandora.module @@ -392,14 +392,16 @@ function islandora_form_alter(&$form, FormStateInterface $form_state, $form_id) * 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); + // Check configuration to see whether a redirect is desired. + $redirect = \Drupal::config('islandora.settings')->get('redirect_after_media_save'); + if ($redirect) { + $params = \Drupal::request()->query->all(); + if (!empty($params)) { + $target_id = $params['edit']['field_media_of']['widget'][0]['target_id']; + $url = Url::fromRoute('view.media_of.page_1', ['node' => $target_id]); + $form_state->setRedirectUrl($url); + } } - } /** diff --git a/src/Form/IslandoraSettingsForm.php b/src/Form/IslandoraSettingsForm.php index 90e0b420..77d8aa27 100644 --- a/src/Form/IslandoraSettingsForm.php +++ b/src/Form/IslandoraSettingsForm.php @@ -43,6 +43,7 @@ class IslandoraSettingsForm extends ConfigFormBase { ]; const GEMINI_PSEUDO_FIELD = 'field_gemini_uri'; const NODE_DELETE_MEDIA_AND_FILES = 'delete_media_and_files'; + const REDIRECT_AFTER_MEDIA_SAVE = 'redirect_after_media_save'; /** * To list the available bundle types. @@ -210,6 +211,13 @@ class IslandoraSettingsForm extends ConfigFormBase { '#default_value' => (bool) $config->get(self::NODE_DELETE_MEDIA_AND_FILES), ]; + $form[self::REDIRECT_AFTER_MEDIA_SAVE] = [ + '#type' => 'checkbox', + '#title' => $this->t('Redirect after media save.'), + '#description' => $this->t('Redirect to node page after creation of media.'), + '#default_value' => (bool) $config->get(self::REDIRECT_AFTER_MEDIA_SAVE), + ]; + $form[self::FEDORA_URL] = [ '#type' => 'textfield', '#title' => $this->t('Fedora URL'), @@ -361,6 +369,7 @@ class IslandoraSettingsForm extends ConfigFormBase { ->set(self::UPLOAD_FORM_ALLOWED_MIMETYPES, $form_state->getValue(self::UPLOAD_FORM_ALLOWED_MIMETYPES)) ->set(self::GEMINI_PSEUDO, $new_pseudo_types) ->set(self::NODE_DELETE_MEDIA_AND_FILES, $form_state->getValue(self::NODE_DELETE_MEDIA_AND_FILES)) + ->set(self::REDIRECT_AFTER_MEDIA_SAVE, $form_state->getValue(self::REDIRECT_AFTER_MEDIA_SAVE)) ->save(); parent::submitForm($form, $form_state); From d6e07491d25f35b63abe821f2e698b2cd0bb3bfc Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Fri, 11 Aug 2023 15:00:42 -0300 Subject: [PATCH 3/3] UI text improvement. --- src/Form/IslandoraSettingsForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/IslandoraSettingsForm.php b/src/Form/IslandoraSettingsForm.php index 77d8aa27..6a2662f9 100644 --- a/src/Form/IslandoraSettingsForm.php +++ b/src/Form/IslandoraSettingsForm.php @@ -214,7 +214,7 @@ class IslandoraSettingsForm extends ConfigFormBase { $form[self::REDIRECT_AFTER_MEDIA_SAVE] = [ '#type' => 'checkbox', '#title' => $this->t('Redirect after media save.'), - '#description' => $this->t('Redirect to node page after creation of media.'), + '#description' => $this->t('Redirect to node-specific media list after creation of media.'), '#default_value' => (bool) $config->get(self::REDIRECT_AFTER_MEDIA_SAVE), ];