You are here

protected function GutenbergFilter::addAttachments in Gutenberg 8.2

Attach Gutenberg frontend libraries to the result.

Parameters

\Drupal\filter\FilterProcessResult $result: The resulting markup.

1 call to GutenbergFilter::addAttachments()
GutenbergFilter::process in src/Plugin/Filter/GutenbergFilter.php

File

src/Plugin/Filter/GutenbergFilter.php, line 215

Class

GutenbergFilter
Provides a filter for Gutenberg blocks.

Namespace

Drupal\gutenberg\Plugin\Filter

Code

protected function addAttachments(FilterProcessResult $result) {
  $module_definitions = $this->libraryManager
    ->getModuleDefinitions();
  $attachments = [];
  foreach ($module_definitions as $module_definition) {
    foreach ($module_definition['libraries-view'] as $library) {
      $attachments['library'][] = $library;
    }
  }
  $theme_definition = $this->libraryManager
    ->getActiveThemeMergedDefinition();
  foreach ($theme_definition['libraries-view'] as $library) {
    $attachments['library'][] = $library;
  }
  $default_theme = $this->configFactory
    ->get('system.theme')
    ->get('default');
  if ($default_theme === 'bartik') {
    $attachments['library'][] = 'gutenberg/bartik';
  }
  if ($attachments) {

    // Add the frontend attachments.
    $result
      ->addAttachments($attachments);
  }
}