You are here

public function GatsbyPreview::gatsbyPrepareData in Gatsby Live Preview & Incremental Builds 8

Same name and namespace in other branches
  1. 2.0.x src/GatsbyPreview.php \Drupal\gatsby\GatsbyPreview::gatsbyPrepareData()

Prepares Gatsby Data to send to the preview and build servers.

By preparing the data in a separate step we prevent multiple requests from being sent to the preview or incremental builds servers if mulutiple Drupal entities are update/created/deleted in a single request.

1 method overrides GatsbyPreview::gatsbyPrepareData()
GatsbyInstantPreview::gatsbyPrepareData in modules/gatsby_instantpreview/src/GatsbyInstantPreview.php
Prepares Gatsby Data to send to the preview and build servers.

File

src/GatsbyPreview.php, line 86

Class

GatsbyPreview
Defines a class for generating Gatsby based previews.

Namespace

Drupal\gatsby

Code

public function gatsbyPrepareData(ContentEntityInterface $entity = NULL) {
  $settings = $this->configFactory
    ->get('gatsby.settings');
  $preview_url = $settings
    ->get('preview_callback_url');
  if ($preview_url) {
    $this
      ->updateData('preview', $preview_url, FALSE);
  }
  $incrementalbuild_url = $settings
    ->get('incrementalbuild_url');
  if (!$incrementalbuild_url) {
    return;
  }
  $build_published = $settings
    ->get('build_published');
  if (!$build_published || $entity instanceof NodeInterface && $entity
    ->isPublished()) {
    $this
      ->updateData('incrementalbuild', $incrementalbuild_url, FALSE);
  }
}