Issue #3406612 by tedbow, phenaproxima: Exceptions in batch no longer are shown on the page: JavaScript error
parent
fca86410e6
commit
d562edaa14
|
@ -4,6 +4,7 @@ namespace Drupal\system\Controller;
|
|||
|
||||
use Drupal\Core\Batch\BatchStorageInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -14,6 +15,8 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|||
*/
|
||||
class BatchController implements ContainerInjectionInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Constructs a new BatchController.
|
||||
*/
|
||||
|
@ -55,6 +58,19 @@ class BatchController implements ContainerInjectionInterface {
|
|||
return $output;
|
||||
}
|
||||
elseif (isset($output)) {
|
||||
// Directly render a status message placeholder without any messages.
|
||||
// Messages are not intended to be show on the batch page, but in the
|
||||
// event an error in a AJAX callback the messages will be displayed.
|
||||
// @todo Remove in https://drupal.org/i/3396099.
|
||||
$output['batch_messages'] = [
|
||||
'#theme' => 'status_messages',
|
||||
'#message_list' => [],
|
||||
'#status_headings' => [
|
||||
'status' => $this->t('Status message'),
|
||||
'error' => $this->t('Error message'),
|
||||
'warning' => $this->t('Warning message'),
|
||||
],
|
||||
];
|
||||
$title = $output['#title'] ?? NULL;
|
||||
$page = [
|
||||
'#type' => 'page',
|
||||
|
|
|
@ -104,6 +104,18 @@ function _batch_test_callback_7($id, $sleep, &$context) {
|
|||
$context['results'][7][] = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements callback_batch_operation().
|
||||
*
|
||||
* Performs a simple batch operation that optionally throws an exception.
|
||||
*/
|
||||
function _batch_test_callback_8(bool $throw_exception): void {
|
||||
usleep(500);
|
||||
if ($throw_exception) {
|
||||
throw new Exception('Exception in batch');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements callback_batch_operation().
|
||||
*
|
||||
|
|
|
@ -190,6 +190,17 @@ function _batch_test_batch_7() {
|
|||
return $batch_builder->toArray() + ['batch_test_id' => 'batch_7'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch 8: Throws an exception.
|
||||
*/
|
||||
function _batch_test_batch_8(): array {
|
||||
$batch_builder = (new BatchBuilder())
|
||||
->setFile(\Drupal::service('extension.list.module')->getPath('batch_test') . '/batch_test.callbacks.inc')
|
||||
->addOperation('_batch_test_callback_8', [FALSE])
|
||||
->addOperation('_batch_test_callback_8', [TRUE]);
|
||||
return $batch_builder->toArray() + ['batch_test_id' => 'batch_8'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements callback_batch_operation().
|
||||
*
|
||||
|
|
|
@ -34,6 +34,7 @@ class BatchTestSimpleForm extends FormBase {
|
|||
'batch_4' => 'batch 4',
|
||||
'batch_6' => 'batch 6',
|
||||
'batch_7' => 'batch 7',
|
||||
'batch_8' => 'batch 8',
|
||||
],
|
||||
'#multiple' => TRUE,
|
||||
];
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\system\FunctionalJavascript\Batch;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
|
||||
/**
|
||||
* @group Batch
|
||||
*/
|
||||
class ProcessingTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $modules = ['batch_test', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @todo Use the stark theme in https://drupal.org/i/3407067.
|
||||
*/
|
||||
protected $defaultTheme = 'olivero';
|
||||
|
||||
/**
|
||||
* Tests that a link to the error page is shown.
|
||||
*/
|
||||
public function testLinkToErrorPageAppears(): void {
|
||||
$edit = ['batch' => 'batch_8'];
|
||||
$this->drupalGet('batch-test');
|
||||
$this->submitForm($edit, 'Submit');
|
||||
$this->assertNotNull($this->assertSession()->waitForLink('the error page'));
|
||||
$this->assertSession()->assertNoEscaped('<');
|
||||
$this->assertSession()->responseContains('Exception in batch');
|
||||
$this->clickLink('the error page');
|
||||
$this->assertSession()->pageTextContains('Redirection successful.');
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue