Commit 0c660e34 authored by alexpott's avatar alexpott

Issue #2843892 by slashrsm, Berdir, dawehner: Query arguments are not persisted when using batch

parent 44d77ea7
...@@ -491,17 +491,13 @@ function _batch_finished() { ...@@ -491,17 +491,13 @@ function _batch_finished() {
$_SESSION['batch_form_state'] = $_batch['form_state']; $_SESSION['batch_form_state'] = $_batch['form_state'];
} }
$callback = $_batch['redirect_callback']; $callback = $_batch['redirect_callback'];
/** @var \Drupal\Core\Url $source_url */ $_batch['source_url']->mergeOptions(['query' => ['op' => 'finish', 'id' => $_batch['id']]]);
$source_url = $_batch['source_url'];
if (is_callable($callback)) { if (is_callable($callback)) {
$callback($_batch['source_url'], array('query' => array('op' => 'finish', 'id' => $_batch['id']))); $callback($_batch['source_url'], $_batch['source_url']->getOption('query'));
} }
elseif ($callback === NULL) { elseif ($callback === NULL) {
// Default to RedirectResponse objects when nothing specified. // Default to RedirectResponse objects when nothing specified.
$url = $source_url return new RedirectResponse($_batch['source_url']->setAbsolute()->toString());
->setAbsolute()
->setOption('query', ['op' => 'finish', 'id' => $_batch['id']]);
return new RedirectResponse($url->toString());
} }
} }
} }
......
...@@ -782,6 +782,9 @@ function batch_set($batch_definition) { ...@@ -782,6 +782,9 @@ function batch_set($batch_definition) {
* \Symfony\Component\HttpFoundation\RedirectResponse, which will be used * \Symfony\Component\HttpFoundation\RedirectResponse, which will be used
* automatically by the standard batch processing pipeline (and which takes * automatically by the standard batch processing pipeline (and which takes
* precedence over this parameter). * precedence over this parameter).
* User will be redirected to the page that started the batch if this argument
* is omitted and no redirect response was returned by the 'finished'
* callback. Any query arguments will be automatically persisted.
* @param \Drupal\Core\Url $url * @param \Drupal\Core\Url $url
* (optional - should only be used for separate scripts like update.php) * (optional - should only be used for separate scripts like update.php)
* URL of the batch processing page. * URL of the batch processing page.
...@@ -801,7 +804,7 @@ function batch_process($redirect = NULL, Url $url = NULL, $redirect_callback = N ...@@ -801,7 +804,7 @@ function batch_process($redirect = NULL, Url $url = NULL, $redirect_callback = N
'current_set' => 0, 'current_set' => 0,
'progressive' => TRUE, 'progressive' => TRUE,
'url' => isset($url) ? $url : Url::fromRoute('system.batch_page.html'), 'url' => isset($url) ? $url : Url::fromRoute('system.batch_page.html'),
'source_url' => Url::fromRouteMatch(\Drupal::routeMatch()), 'source_url' => Url::fromRouteMatch(\Drupal::routeMatch())->mergeOptions(['query' => \Drupal::request()->query->all()]),
'batch_redirect' => $redirect, 'batch_redirect' => $redirect,
'theme' => \Drupal::theme()->getActiveTheme()->getName(), 'theme' => \Drupal::theme()->getActiveTheme()->getName(),
'redirect_callback' => $redirect_callback, 'redirect_callback' => $redirect_callback,
......
...@@ -107,6 +107,13 @@ function testBatchFormMultistep() { ...@@ -107,6 +107,13 @@ function testBatchFormMultistep() {
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), 'Execution order was correct.'); $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
$this->assertNoEscaped('<', 'No escaped markup is present.'); $this->assertNoEscaped('<', 'No escaped markup is present.');
// Extra query arguments will trigger logic that will add them to the
// redirect URL. Make sure they are persisted.
$this->drupalGet('batch-test/multistep', ['query' => ['big_tree' => 'small_axe']]);
$this->drupalPostForm(NULL, array(), 'Submit');
$this->assertText('step 2', 'Form is displayed in step 2.');
$this->assertTrue(strpos($this->getUrl(), 'batch-test/multistep?big_tree=small_axe'), 'Query argument was persisted and another extra argument was added.');
} }
/** /**
......
Markdown is supported
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