Commit 1b27675a authored by Brittany Huntzberry's avatar Brittany Huntzberry Committed by Damien McKenna
Browse files

Issue #3206524 by DamienMcKenna, brittany.huntzberry, iansholtys: Add option...

Issue #3206524 by DamienMcKenna, brittany.huntzberry, iansholtys: Add option to log JSON data when a POST request is sent to Gatsby server.
parent 40037a7b
Loading
Loading
Loading
Loading
+1 −0
Changes for config/install/gatsby.settings.yml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,5 +2,6 @@ server_url: ''
path_mapping: ''
incrementalbuild_url: ''
build_published: true
log_json: false
preview_entity_types: []
preview_callback_url: ''
+3 −0
Changes for config/schema/gatsby.schema.yml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@ gatsby.settings:
    build_published:
      type: boolean
      label: 'Build published'
    log_json:
      type: boolean
      label: 'Log JSON'
    preview_entity_types:
      type: sequence
      label: 'Preview Entity Types'
+8 −0
Changes for src/Form/GatsbyAdminForm.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -142,6 +142,13 @@ class GatsbyAdminForm extends ConfigFormBase {
      '#default_value' => $config->get('build_published') !== NULL ? $config->get('build_published') : TRUE,
      '#weight' => 2,
    ];
    $form['log_json'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Create log messages of JSON objects sent to the Gatsby preview server'),
      '#description' => $this->t('By checking this box, log messages will be created every time a POST request is sent to the Gatsby preview server. Useful for debugging the JSON object data that gets sent to Gatsby.<br /><strong>Note: this may have security implications, esure that only trusted users can access the logged messages. Should not be used on a production environment.</strong.'),
      '#default_value' => $config->get('log_json'),
      '#weight' => 3,
    ];
    $form['preview_entity_types'] = [
      '#type' => 'checkboxes',
      '#options' => $this->getContentEntityTypes(),
@@ -214,6 +221,7 @@ class GatsbyAdminForm extends ConfigFormBase {
      ->set('build_published', $form_state->getValue('build_published'))
      ->set('preview_entity_types', array_values(array_filter($form_state->getValue('preview_entity_types'))))
      ->set('path_mapping', $form_state->getValue('path_mapping'))
      ->set('log_json', $form_state->getValue('log_json'))
      ->save();
  }

+6 −0
Changes for src/GatsbyPreview.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -199,10 +199,16 @@ class GatsbyPreview {

    if ($json) {
      $data['json'] = $json;
      // Check for enabled setting and set up a logger debug message with JSON object.
      $json_log = $this->configFactory->get('gatsby.settings')->get('log_json') ? $this->logger->debug(json_encode($json)) : NULL;
    }

    try {
      $this->httpClient->post($preview_callback_url . $path, $data);
      // Return logger with JSON object data.
      if ($json_log) {
        return $json_log;
      }
    }
    catch (ConnectException $e) {
      // This is maintained for the legacy callback URL only.