You are here

function gatsby_post_update_migrate_preview_settings in Gatsby Live Preview & Incremental Builds 8

Same name and namespace in other branches
  1. 2.0.x gatsby.post_update.php \gatsby_post_update_migrate_preview_settings()

Migrates preview settings.

File

./gatsby.post_update.php, line 13
Contains post update hooks.

Code

function gatsby_post_update_migrate_preview_settings() {
  $gatsby_settings = \Drupal::service('config.factory')
    ->getEditable('gatsby.settings');
  $preview_settings = $gatsby_settings
    ->get('preview');
  $target_settings = $gatsby_settings
    ->get('target');
  $iframe_settings = $gatsby_settings
    ->get('iframe');
  foreach ($preview_settings as $node_type_id => $setting) {

    /** @var \Drupal\node\NodeTypeInterface $node_type */
    $node_type = NodeType::load($node_type_id);
    $node_type
      ->setThirdPartySetting('gatsby', 'preview', (bool) $setting);
    $node_type
      ->setThirdPartySetting('gatsby', 'iframe', (bool) $iframe_settings[$node_type_id]);
    $node_type
      ->setThirdPartySetting('gatsby', 'target', $target_settings[$node_type_id]);
    $node_type
      ->save();
  }
  $gatsby_settings
    ->clear('preview')
    ->clear('target')
    ->clear('iframe')
    ->save();
}