You are here

protected function RemotePostWebformHandler::debug in Webform 6.x

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

Display debugging information.

Parameters

string $message: Message to be displayed.

string $state: The state of the webform submission. Either STATE_NEW, STATE_DRAFT_CREATED, STATE_DRAFT_UPDATED, STATE_COMPLETED, STATE_UPDATED, or STATE_CONVERTED depending on the last save operation performed.

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

string $request_method: The method of remote post.

string $request_type: The type of remote post.

string $request_options: The requests options including the submission data.

\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.

2 calls to RemotePostWebformHandler::debug()
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 885

Class

RemotePostWebformHandler
Webform submission remote post handler.

Namespace

Drupal\webform\Plugin\WebformHandler

Code

protected function debug($message, $state, $request_url, $request_method, $request_type, $request_options, ResponseInterface $response = NULL, $type = 'warning') {
  if (empty($this->configuration['debug'])) {
    return;
  }
  $build = [
    '#type' => 'details',
    '#title' => $this
      ->t('Debug: Remote post: @title [@state]', [
      '@title' => $this
        ->label(),
      '@state' => $state,
    ]),
  ];

  // State.
  $build['state'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Submission state/operation:'),
    '#markup' => $state,
    '#wrapper_attributes' => [
      'class' => [
        'container-inline',
      ],
      'style' => 'margin: 0',
    ],
  ];

  // Request.
  $build['request'] = [
    '#markup' => '<hr />',
  ];
  $build['request_url'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Request URL'),
    '#markup' => $request_url,
    '#wrapper_attributes' => [
      'class' => [
        'container-inline',
      ],
      'style' => 'margin: 0',
    ],
  ];
  $build['request_method'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Request method'),
    '#markup' => $request_method,
    '#wrapper_attributes' => [
      'class' => [
        'container-inline',
      ],
      'style' => 'margin: 0',
    ],
  ];
  $build['request_type'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Request type'),
    '#markup' => $request_type,
    '#wrapper_attributes' => [
      'class' => [
        'container-inline',
      ],
      'style' => 'margin: 0',
    ],
  ];
  $build['request_options'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Request options'),
    '#wrapper_attributes' => [
      'style' => 'margin: 0',
    ],
    'data' => [
      '#markup' => htmlspecialchars(Yaml::encode($request_options)),
      '#prefix' => '<pre>',
      '#suffix' => '</pre>',
    ],
  ];

  // Response.
  $build['response'] = [
    '#markup' => '<hr />',
  ];
  if ($response) {
    $build['response_code'] = [
      '#type' => 'item',
      '#title' => $this
        ->t('Response status code:'),
      '#markup' => $response
        ->getStatusCode(),
      '#wrapper_attributes' => [
        'class' => [
          'container-inline',
        ],
        'style' => 'margin: 0',
      ],
    ];
    $build['response_header'] = [
      '#type' => 'item',
      '#title' => $this
        ->t('Response header:'),
      '#wrapper_attributes' => [
        'style' => 'margin: 0',
      ],
      'data' => [
        '#markup' => htmlspecialchars(Yaml::encode($response
          ->getHeaders())),
        '#prefix' => '<pre>',
        '#suffix' => '</pre>',
      ],
    ];
    $build['response_body'] = [
      '#type' => 'item',
      '#wrapper_attributes' => [
        'style' => 'margin: 0',
      ],
      '#title' => $this
        ->t('Response body:'),
      'data' => [
        '#markup' => htmlspecialchars($response
          ->getBody()),
        '#prefix' => '<pre>',
        '#suffix' => '</pre>',
      ],
    ];
    $response_data = $this
      ->getResponseData($response);
    if ($response_data) {
      $build['response_data'] = [
        '#type' => 'item',
        '#wrapper_attributes' => [
          'style' => 'margin: 0',
        ],
        '#title' => $this
          ->t('Response data:'),
        'data' => [
          '#markup' => Yaml::encode($response_data),
          '#prefix' => '<pre>',
          '#suffix' => '</pre>',
        ],
      ];
    }
    if ($tokens = $this
      ->getResponseTokens($response_data, [
      'webform',
      'handler',
      $this
        ->getHandlerId(),
      $state,
    ])) {
      asort($tokens);
      $build['response_tokens'] = [
        '#type' => 'item',
        '#wrapper_attributes' => [
          'style' => 'margin: 0',
        ],
        '#title' => $this
          ->t('Response tokens:'),
        'description' => [
          '#markup' => $this
            ->t('Below tokens can ONLY be used to insert response data into value and hidden elements.'),
        ],
        'data' => [
          '#markup' => implode(PHP_EOL, $tokens),
          '#prefix' => '<pre>',
          '#suffix' => '</pre>',
        ],
      ];
    }
  }
  else {
    $build['response_code'] = [
      '#markup' => $this
        ->t('No response. Please see the recent log messages.'),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    ];
  }

  // Message.
  $build['message'] = [
    '#markup' => '<hr />',
  ];
  $build['message_message'] = [
    '#type' => 'item',
    '#wrapper_attributes' => [
      'style' => 'margin: 0',
    ],
    '#title' => $this
      ->t('Message:'),
    '#markup' => $message,
  ];
  $this
    ->messenger()
    ->addMessage($this->renderer
    ->renderPlain($build), $type);
}