You are here

function gutenberg_page_attachments in Gutenberg 8

Same name and namespace in other branches
  1. 8.2 gutenberg.module \gutenberg_page_attachments()

Implements hook_page_attachments().

File

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

Code

function gutenberg_page_attachments(array &$page) {
  $settings = _gutenberg_get_default_theme_settings();
  if (!isset($settings['theme-support']['colors'])) {
    return;
  }
  $palette = [
    '#theme' => 'gutenberg_palette',
    '#colors' => $settings['theme-support']['colors'],
  ];
  $renderPalette = \Drupal::service('renderer')
    ->renderRoot($palette);

  // Sanitizing the output, like comments etc.
  $renderPalette = strip_tags($renderPalette);
  $renderPalette = trim($renderPalette);
  $page['#attached']['html_head'][] = [
    [
      '#tag' => 'style',
      '#value' => $renderPalette,
    ],
    'gutenberg_palette',
  ];
}