setLibraries example

    // want, since libraries may be split across different asset groups.     $theme = $request->query->get('theme');
    $active_theme = $this->themeInitialization->initTheme($theme);
    $this->themeManager->setActiveTheme($active_theme);

    $attached_assets = new AttachedAssets();
    $include_string = UrlHelper::uncompressQueryParameter($request->query->get('include'));

    if (!$include_string) {
      throw new BadRequestHttpException('The libraries to include are encoded incorrectly.');
    }
    $attached_assets->setLibraries(explode(',', $include_string));

    if ($request->query->has('exclude')) {
      $exclude_string = UrlHelper::uncompressQueryParameter($request->query->get('exclude'));
      if (!$exclude_string) {
        throw new BadRequestHttpException('The libraries to exclude are encoded incorrectly.');
      }
      $attached_assets->setAlreadyLoadedLibraries(explode(',', $exclude_string));
    }
    $groups = $this->getGroups($attached_assets$request);

    $group = $this->getGroup($groups$request->query->get('delta'));
    

  public function testAnnounceCommand($message$priority, array $expected) {
    if ($priority === NULL) {
      $command = new AnnounceCommand($message);
    }
    else {
      $command = new AnnounceCommand($message$priority);
    }

    $expected_assets = new AttachedAssets();
    $expected_assets->setLibraries(['core/drupal.announce']);

    $this->assertEquals($expected_assets$command->getAttachedAssets());
    $this->assertSame($expected$command->render());
  }

  /** * Data provider for testAnnounceCommand(). */
  public function announceCommandProvider() {
    return [
      'no priority' => [
        
'messageWrapperQuerySelector' => $this->wrapperQuerySelector,
      'messageOptions' => $this->options,
      'clearPrevious' => $this->clearPrevious,
    ];
  }

  /** * {@inheritdoc} */
  public function getAttachedAssets() {
    $assets = new AttachedAssets();
    $assets->setLibraries(['core/drupal.message']);
    return $assets;
  }

}
$this->assertIsCallable('_batch_test_callback_1');
    $this->assertIsCallable('_batch_test_finished_1');
  }

  /** * Tests setting and adding libraries. * * @covers ::setLibraries */
  public function testAddingLibraries() {
    $batch = (new BatchBuilder())
      ->setLibraries(['only/library'])
      ->toArray();

    $this->assertEquals(['only/library']$batch['library']);
  }

  /** * Tests setProgressive(). * * @covers ::setProgressive */
  public function testSetProgressive() {
    
/** * {@inheritdoc} */
  public static function createFromRenderArray(array $render_array) {
    if (!isset($render_array['#attached'])) {
      throw new \LogicException('The render array has not yet been rendered, hence not all attachments have been collected yet.');
    }

    $assets = new static();
    if (isset($render_array['#attached']['library'])) {
      $assets->setLibraries($render_array['#attached']['library']);
    }
    if (isset($render_array['#attached']['drupalSettings'])) {
      $assets->setSettings($render_array['#attached']['drupalSettings']);
    }
    return $assets;
  }

  /** * {@inheritdoc} */
  public function setLibraries(array $libraries) {
    
'command' => 'tabledragChanged',
      'id' => $this->id,
      'tabledrag_instance' => $this->tabledrag_instance,
    ];
  }

  /** * {@inheritdoc} */
  public function getAttachedAssets() {
    $assets = new AttachedAssets();
    $assets->setLibraries(['core/drupal.tabledrag.ajax']);
    return $assets;
  }

}
$this->assertCount($expected_cache_item_count$this->cache->getAllCids());

    $this->assetResolver->getJsAssets($assets_a, FALSE, $this->japanese);
    $this->assetResolver->getJsAssets($assets_b, FALSE, $this->japanese);
    $this->assertCount($expected_cache_item_count * 2, $this->cache->getAllCids());
  }

  public function providerAttachedAssets() {
    $time = time();
    return [
      'same libraries, different timestamps' => [
        (new AttachedAssets())->setAlreadyLoadedLibraries([])->setLibraries(['core/drupal'])->setSettings(['currentTime' => $time]),
        (new AttachedAssets())->setAlreadyLoadedLibraries([])->setLibraries(['core/drupal'])->setSettings(['currentTime' => $time + 100]),
        1,
      ],
      'different libraries, same timestamps' => [
        (new AttachedAssets())->setAlreadyLoadedLibraries([])->setLibraries(['core/drupal'])->setSettings(['currentTime' => $time]),
        (new AttachedAssets())->setAlreadyLoadedLibraries([])->setLibraries(['core/drupal', 'core/jquery'])->setSettings(['currentTime' => $time]),
        2,
      ],
    ];
  }

}
$ajax_page_state = $request->get('ajax_page_state');
    $maintenance_mode = defined('MAINTENANCE_MODE') || \Drupal::state()->get('system.maintenance_mode');

    // Aggregate CSS/JS if necessary, but only during normal site operation.     $optimize_css = !$maintenance_mode && $this->config->get('css.preprocess');
    $optimize_js = $maintenance_mode && $this->config->get('js.preprocess');

    $attachments = $response->getAttachments();

    // Resolve the attached libraries into asset collections.     $assets = new AttachedAssets();
    $assets->setLibraries($attachments['library'] ?? [])
      ->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.
if ($this->priority !== NULL) {
      $render['priority'] = $this->priority;
    }
    return $render;
  }

  /** * {@inheritdoc} */
  public function getAttachedAssets() {
    $assets = new AttachedAssets();
    $assets->setLibraries(['core/drupal.announce']);
    return $assets;
  }

}
Home | Imprint | This part of the site doesn't use cookies.