You are here

protected function RemotePostWebformHandler::displayCustomResponseMessage in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformHandler/RemotePostWebformHandler.php \Drupal\webform\Plugin\WebformHandler\RemotePostWebformHandler::displayCustomResponseMessage()

Display custom response message.

Parameters

\Psr\Http\Message\ResponseInterface|null $response: The response returned by the remote server.

bool $default: Display the default message. Defaults to TRUE.

Return value

bool TRUE if custom response message is displayed.

2 calls to RemotePostWebformHandler::displayCustomResponseMessage()
RemotePostWebformHandler::handleError in src/Plugin/WebformHandler/RemotePostWebformHandler.php
Handle error by logging and display debugging and/or exception message.
RemotePostWebformHandler::remotePost in src/Plugin/WebformHandler/RemotePostWebformHandler.php
Execute a remote post.

File

src/Plugin/WebformHandler/RemotePostWebformHandler.php, line 1159

Class

RemotePostWebformHandler
Webform submission remote post handler.

Namespace

Drupal\webform\Plugin\WebformHandler

Code

protected function displayCustomResponseMessage($response, $default = TRUE) {
  $custom_response_message = $this
    ->getCustomResponseMessage($response, $default);
  if (!$custom_response_message) {
    return FALSE;
  }
  $token_data = [
    'webform_handler' => [
      $this
        ->getHandlerId() => $this
        ->getResponseData($response),
    ],
  ];
  $build_message = [
    '#markup' => $this
      ->replaceTokens($custom_response_message, $this
      ->getWebform(), $token_data),
  ];
  $message = \Drupal::service('renderer')
    ->renderPlain($build_message);
  $type = $this
    ->responseHasError($response) ? MessengerInterface::TYPE_ERROR : MessengerInterface::TYPE_STATUS;
  $this
    ->messenger()
    ->addMessage($message, $type);
  return TRUE;
}