Skip to content
Snippets Groups Projects
Verified Commit d9e9f0c4 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2995893 by tim.plunkett, Dylan Donkersgoed: Layout builder chokes on...

Issue #2995893 by tim.plunkett, Dylan Donkersgoed: Layout builder chokes on form exceptions that are part of natural form processing
parent 01efa20b
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -14,6 +14,7 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FormatterInterface;
use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\Form\EnforcedResponseException;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
......@@ -155,6 +156,10 @@ public function build() {
try {
$build = $entity->get($this->fieldName)->view($display_settings);
}
// @todo Remove in https://www.drupal.org/project/drupal/issues/2367555.
catch (EnforcedResponseException $e) {
throw $e;
}
catch (\Exception $e) {
$build = [];
$this->logger->warning('The field "%field" failed to render with the error of "%error".', ['%field' => $this->fieldName, '%error' => $e->getMessage()]);
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\Form\EnforcedResponseException;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\Core\Session\AccountInterface;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
......@@ -20,6 +21,7 @@
use Prophecy\Promise\ThrowPromise;
use Prophecy\Prophecy\ProphecyInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;
/**
* @coversDefaultClass \Drupal\layout_builder\Plugin\Block\FieldBlock
......@@ -285,4 +287,21 @@ public function providerTestBuild() {
return $data;
}
/**
* Tests a field block that throws a form exception.
*
* @todo Remove in https://www.drupal.org/project/drupal/issues/2367555.
*/
public function testBuildWithFormException() {
$field = $this->prophesize(FieldItemListInterface::class);
$field->view(Argument::type('array'))->willThrow(new EnforcedResponseException(new Response()));
$entity = $this->prophesize(FieldableEntityInterface::class);
$entity->get('the_field_name')->willReturn($field->reveal());
$block = $this->getTestBlock($entity);
$this->setExpectedException(EnforcedResponseException::class);
$block->build();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment