You are here

protected function RemotePostYamlFormHandler::debug in YAML Form 8

Display debugging information.

Parameters

string $message: Message to be displayed.

string $operation: The operation being performed, can be either insert, update, or delete.

string $request_url: The remote URL the request is being posted to.

string $request_type: The type of remote post.

string $request_post_data: The form submission data being posted.

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

string $type: The type of message to be displayed to the end use.

1 call to RemotePostYamlFormHandler::debug()
RemotePostYamlFormHandler::remotePost in src/Plugin/YamlFormHandler/RemotePostYamlFormHandler.php
Execute a remote post.

File

src/Plugin/YamlFormHandler/RemotePostYamlFormHandler.php, line 371

Class

RemotePostYamlFormHandler
Form submission remote post handler.

Namespace

Drupal\yamlform\Plugin\YamlFormHandler

Code

protected function debug($message, $operation, $request_url, $request_type, $request_post_data, ResponseInterface $response = NULL, $type = 'warning') {
  if (empty($this->configuration['debug'])) {
    return;
  }
  $build = [];

  // Message.
  $build['message'] = [
    '#markup' => $message,
    '#prefix' => '<b>',
    '#suffix' => '</b>',
  ];

  // Operation.
  $build['operation'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Remote operation'),
    '#markup' => $operation,
  ];

  // Request.
  $build['request_url'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Request URL'),
    '#markup' => $request_url,
  ];
  $build['request_type'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Request type'),
    '#markup' => $request_type,
  ];
  $build['request_post_data'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Request data'),
    'data' => [
      '#markup' => htmlspecialchars(Yaml::encode($request_post_data)),
      '#prefix' => '<pre>',
      '#suffix' => '</pre>',
    ],
  ];
  $build['returned'] = [
    '#markup' => $this
      ->t('...returned...'),
    '#prefix' => '<b>',
    '#suffix' => '</b>',
  ];

  // Response.
  if ($response) {
    $build['response_code'] = [
      '#type' => 'item',
      '#title' => $this
        ->t('Response status code'),
      '#markup' => $response
        ->getStatusCode(),
    ];
    $build['response_header'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Response header'),
      'data' => [
        '#markup' => htmlspecialchars(Yaml::encode($response
          ->getHeaders())),
        '#prefix' => '<pre>',
        '#suffix' => '</pre>',
      ],
    ];
    $build['response_body'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Response body'),
      'data' => [
        '#markup' => htmlspecialchars($response
          ->getBody()),
        '#prefix' => '<pre>',
        '#suffix' => '</pre>',
      ],
    ];
  }
  else {
    $build['response_code'] = [
      '#markup' => t('No response. Please see the recent log messages.'),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    ];
  }
  drupal_set_message(\Drupal::service('renderer')
    ->renderPlain($build), $type);
}