Loading entity_save_and_addanother.module +26 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,21 @@ function entity_save_and_addanother_form_node_form_alter(array &$form, FormState } } /** * Implements hook_form_FORM_ID_alter(). */ function entity_save_and_addanother_form_media_form_alter(array &$form, FormStateInterface $form_state) { $current_path = \Drupal::service('path.current')->getPath(); if (strpos($current_path, '/media/add/') !== FALSE) { $form_state->setValue('entity_save_and_addanother_media', $current_path); $form['#submit'][] = 'entity_save_and_addanother_media_submit_handler'; $form['actions']['entity_save_and_addanother_media'] = $form['actions']['submit']; $form['actions']['entity_save_and_addanother_media']['#value'] = t('Save and Add Another'); \Drupal::request()->query->remove('destination'); $form['actions']['entity_save_and_addanother_media']['#submit'][] = 'entity_save_and_addanother_media_submit_handler'; } } /** * Implements hook_form_FORM_ID_alter(). */ Loading Loading @@ -86,6 +101,17 @@ function entity_save_and_addanother_node_submit_handler(array &$form, FormStateI } } /** * Submit callback to set the redirect for media. */ function entity_save_and_addanother_media_submit_handler(array &$form, FormStateInterface $form_state) { $trigger = $form_state->getTriggeringElement(); if (isset($trigger['#id']) && $trigger['#id'] == 'edit-entity-save-and-addanother-media') { $current_path = \Drupal::service('path.current')->getPath(); $form_state->setRedirectUrl(Url::fromUserInput($current_path)); } } /** * Submit callback to set the redirect for taxonomy. */ Loading Loading
entity_save_and_addanother.module +26 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,21 @@ function entity_save_and_addanother_form_node_form_alter(array &$form, FormState } } /** * Implements hook_form_FORM_ID_alter(). */ function entity_save_and_addanother_form_media_form_alter(array &$form, FormStateInterface $form_state) { $current_path = \Drupal::service('path.current')->getPath(); if (strpos($current_path, '/media/add/') !== FALSE) { $form_state->setValue('entity_save_and_addanother_media', $current_path); $form['#submit'][] = 'entity_save_and_addanother_media_submit_handler'; $form['actions']['entity_save_and_addanother_media'] = $form['actions']['submit']; $form['actions']['entity_save_and_addanother_media']['#value'] = t('Save and Add Another'); \Drupal::request()->query->remove('destination'); $form['actions']['entity_save_and_addanother_media']['#submit'][] = 'entity_save_and_addanother_media_submit_handler'; } } /** * Implements hook_form_FORM_ID_alter(). */ Loading Loading @@ -86,6 +101,17 @@ function entity_save_and_addanother_node_submit_handler(array &$form, FormStateI } } /** * Submit callback to set the redirect for media. */ function entity_save_and_addanother_media_submit_handler(array &$form, FormStateInterface $form_state) { $trigger = $form_state->getTriggeringElement(); if (isset($trigger['#id']) && $trigger['#id'] == 'edit-entity-save-and-addanother-media') { $current_path = \Drupal::service('path.current')->getPath(); $form_state->setRedirectUrl(Url::fromUserInput($current_path)); } } /** * Submit callback to set the redirect for taxonomy. */ Loading