diff --git a/config/schema/islandora.schema.yml b/config/schema/islandora.schema.yml index 86b65fd0c..89c1b58a5 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 ad2eb8e1c..01e5a467b 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 691767140..8d443e1c0 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,22 @@ 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) { + // 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); + } + } +} + /** * Implements a submit handler for the delete form. */ diff --git a/src/Form/IslandoraSettingsForm.php b/src/Form/IslandoraSettingsForm.php index 90e0b4204..6a2662f94 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 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#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-specific media list 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 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ->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);