EnforcedResponseException example

'%field' => 'the_field_name', '%error' => 'The exception message']
    );
  }

  /** * 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->expectException(EnforcedResponseException::class);
    $block->build();
  }

}
// If the form returns a response, skip subsequent page construction by     // throwing an exception.     // @see Drupal\Core\EventSubscriber\EnforcedFormResponseSubscriber     //     // @todo Exceptions should not be used for code flow control. However, the     // Form API does not integrate with the HTTP Kernel based architecture of     // Drupal 8. In order to resolve this issue properly it is necessary to     // completely separate form submission from rendering.     // @see https://www.drupal.org/node/2367555     if ($response instanceof Response) {
      throw new EnforcedResponseException($response);
    }

    // If this was a successful submission of a single-step form or the last     // step of a multi-step form, then self::processForm() issued a redirect to     // another page, or back to this page, but as a new request. Therefore, if     // we're here, it means that this is either a form being viewed initially     // before any user input, or there was a validation error requiring the form     // to be re-displayed, or we're in a multi-step workflow and need to display     // the form's next step. In any case, we have what we need in $form, and can     // return it for rendering.     return $form;
  }
Home | Imprint | This part of the site doesn't use cookies.