You are here

function gutenberg_preprocess_node in Gutenberg 8

Implements template_preprocess_node().

File

./gutenberg.module, line 568
Provides integration with the Gutenberg editor.

Code

function gutenberg_preprocess_node(&$variables) {
  $config = \Drupal::service('config.factory')
    ->getEditable('gutenberg.settings');
  $node = $variables['elements']['#node'];
  $node_type = $node->type
    ->getString();
  $gutenberg_enabled = $config
    ->get($node_type . '_enable_full');
  if (!$gutenberg_enabled) {
    return;
  }
  $variables['#attached']['library'][] = 'gutenberg/blocks-view';
  $module_settings = _gutenberg_get_all_modules_settings();
  foreach ($module_settings as $settings) {
    if (isset($settings['libraries-view'])) {
      foreach ($settings['libraries-view'] as $library) {
        $variables['#attached']['library'][] = $library;
      }
    }
  }
  $default_theme = \Drupal::config('system.theme')
    ->get('default');
  if ($default_theme === 'bartik') {
    $variables['#attached']['library'][] = 'gutenberg/bartik';
  }
}