getLibraries example

->setAlreadyLoadedLibraries(isset($ajax_page_state['libraries']) ? explode(',', $ajax_page_state['libraries']) : [])
      ->setSettings($attachments['drupalSettings'] ?? []);
    $css_assets = $this->assetResolver->getCssAssets($assets$optimize_css$this->languageManager->getCurrentLanguage());
    [$js_assets_header$js_assets_footer] = $this->assetResolver->getJsAssets($assets$optimize_js$this->languageManager->getCurrentLanguage());

    // First, AttachedAssets::setLibraries() ensures duplicate libraries are     // removed: it converts it to a set of libraries if necessary. Second,     // AssetResolver::getJsSettings() ensures $assets contains the final set of     // JavaScript settings. AttachmentsResponseProcessorInterface also mandates     // that the response it processes contains the final attachment values, so     // update both the 'library' and 'drupalSettings' attachments accordingly.     $attachments['library'] = $assets->getLibraries();
    $attachments['drupalSettings'] = $assets->getSettings();
    $response->setAttachments($attachments);

    // Render the HTML to load these files, and add AJAX commands to insert this     // HTML in the page. Settings are handled separately, afterwards.     $settings = [];
    if (isset($js_assets_header['drupalSettings'])) {
      $settings = $js_assets_header['drupalSettings']['data'];
      unset($js_assets_header['drupalSettings']);
    }
    if (isset($js_assets_footer['drupalSettings'])) {
      
$assets = AttachedAssets::createFromRenderArray(['#attached' => $attached]);
      // Take Ajax page state into account, to allow for something like       // Turbolinks to be implemented without altering core.       // @see https://github.com/rails/turbolinks/       $ajax_page_state = $this->requestStack->getCurrentRequest()->get('ajax_page_state');
      $assets->setAlreadyLoadedLibraries(isset($ajax_page_state) ? explode(',', $ajax_page_state['libraries']) : []);
      $variables = $this->processAssetLibraries($assets$attachment_placeholders);
      // $variables now contains the markup to load the asset libraries. Update       // $attached with the final list of libraries and JavaScript settings, so       // that $response can be updated with those. Then the response object will       // list the final, processed attachments.       $attached['library'] = $assets->getLibraries();
      $attached['drupalSettings'] = $assets->getSettings();

      // Since we can only replace content in the HTML head section if there's a       // placeholder for it, we can safely avoid processing the render array if       // it's not present.       if (!empty($attachment_placeholders['head'])) {
        // 'feed' is a special case of 'html_head_link'. We process them into         // 'html_head_link' entries and merge them.         if (!empty($attached['feed'])) {
          $attached = BubbleableMetadata::mergeAttachments(
            $attached,
            

  protected function getLibrariesToLoad(AttachedAssetsInterface $assets) {
    // The order of libraries passed in via assets can differ, so to reduce     // variation, first normalize the requested libraries to the minimal     // representative set before then expanding the list to include all     // dependencies.     // @see Drupal\FunctionalTests\Core\Asset\AssetOptimizationTestUmami     // @todo: https://www.drupal.org/project/drupal/issues/1945262     $libraries = $assets->getLibraries();
    if ($libraries) {
      $libraries = $this->libraryDependencyResolver->getMinimalRepresentativeSubset($libraries);
    }
    return array_diff(
      $this->libraryDependencyResolver->getLibrariesWithDependencies($libraries),
      $this->libraryDependencyResolver->getLibrariesWithDependencies($assets->getAlreadyLoadedLibraries())
    );
  }

  /** * {@inheritdoc} */
$settings = [];
    foreach ($format_ids as $format_id) {
      $editor = editor_load($format_id);
      if (!$editor) {
        continue;
      }

      $plugin = $this->createInstance($editor->getEditor());
      $plugin_definition = $plugin->getPluginDefinition();

      // Libraries.       $attachments['library'] = array_merge($attachments['library']$plugin->getLibraries($editor));

      // Format-specific JavaScript settings.       $settings['editor']['formats'][$format_id] = [
        'format' => $format_id,
        'editor' => $editor->getEditor(),
        'editorSettings' => $plugin->getJSSettings($editor),
        'editorSupportsContentFiltering' => $plugin_definition['supports_content_filtering'],
        'isXssSafe' => $plugin_definition['is_xss_safe'],
      ];
    }

    
/** * Tests that changes to the info file are picked up. */
  public function testChanges() {
    $this->themeInstaller->install(['test_theme']);
    $this->config('system.theme')->set('default', 'test_theme')->save();
    $this->themeManager->resetActiveTheme();

    $active_theme = $this->themeManager->getActiveTheme();
    // Make sure we are not testing the wrong theme.     $this->assertEquals('test_theme', $active_theme->getName());
    $this->assertEquals(['starterkit_theme/base', 'starterkit_theme/messages', 'core/normalize', 'test_theme/global-styling']$active_theme->getLibraries());

    // @see theme_test_system_info_alter()     $this->state->set('theme_test.modify_info_files', TRUE);
    $this->resetAll();
    $active_theme = $this->themeManager->getActiveTheme();
    $this->assertEquals(['starterkit_theme/base', 'starterkit_theme/messages', 'core/normalize', 'test_theme/global-styling', 'core/once']$active_theme->getLibraries());
  }

}

  public function addCommand(CommandInterface $command$prepend = FALSE) {
    if ($prepend) {
      array_unshift($this->commands, $command->render());
    }
    else {
      $this->commands[] = $command->render();
    }
    if ($command instanceof CommandWithAttachedAssetsInterface) {
      $assets = $command->getAttachedAssets();
      $attachments = [
        'library' => $assets->getLibraries(),
        'drupalSettings' => $assets->getSettings(),
      ];
      $attachments = BubbleableMetadata::mergeAttachments($this->getAttachments()$attachments);
      $this->setAttachments($attachments);
    }

    return $this;
  }

  /** * Gets all AJAX commands. * * @return array * Returns render arrays for all previously added commands. */
Home | Imprint | This part of the site doesn't use cookies.