Commit ce4e3fdb authored by Jacob Rockowitz's avatar Jacob Rockowitz Committed by jrockowitz
Browse files

Issue #3183048 by jrockowitz: Deleted webforms placed in layout builder results in WSOD

parents dd8f2e87 6b385cf4
Loading
Loading
Loading
Loading
+19 −1
Changes for src/Plugin/Block/WebformBlock.php: 19 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -30,6 +30,13 @@ class WebformBlock extends BlockBase implements ContainerFactoryPluginInterface
   */
  protected $requestStack;

  /**
   * The route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Entity type manager.
   *
@@ -50,6 +57,7 @@ class WebformBlock extends BlockBase implements ContainerFactoryPluginInterface
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = new static($configuration, $plugin_id, $plugin_definition);
    $instance->requestStack = $container->get('request_stack');
    $instance->routeMatch = $container->get('current_route_match');
    $instance->entityTypeManager = $container->get('entity_type.manager');
    $instance->tokenManager = $container->get('webform.token_manager');
    return $instance;
@@ -171,9 +179,19 @@ class WebformBlock extends BlockBase implements ContainerFactoryPluginInterface
   * {@inheritdoc}
   */
  public function build() {
    $webform = $this->getWebform();
    if (!$webform) {
      if (strpos(\Drupal::routeMatch()->getRouteName(), 'layout_builder.') === 0) {
        return ['#markup' => $this->t('The webform (@webform) is broken or missing.', ['@webform' => $this->configuration['webform_id']])];
      }
      else {
        return NULL;
      }
    }

    $build = [
      '#type' => 'webform',
      '#webform' => $this->getWebform(),
      '#webform' => $webform,
      '#default_data' => WebformYaml::decode($this->configuration['default_data']),
    ];

+6 −0
Changes for tests/src/Unit/Plugin/Block/WebformBlockTest.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Drupal\Core\Cache\Context\CacheContextsManager;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\webform\Plugin\Block\WebformBlock;
@@ -136,9 +137,14 @@ class WebformBlockTest extends UnitTestCase {
      ->disableOriginalConstructor()
      ->getMock();

    $route_match = $this->getMockBuilder(RouteMatchInterface::class)
      ->disableOriginalConstructor()
      ->getMock();

    // Build container.
    $container = new ContainerBuilder();
    $container->set('request_stack', $request_stack);
    $container->set('current_route_match', $request_stack);
    $container->set('entity_type.manager', $entity_type_manager);
    $container->set('webform.token_manager', $token_manager);