getMinimalRepresentativeSubset example

'test/no_deps_a', 'test/deps_c', 'test/nested_deps_b']['test/deps_c', 'test/nested_deps_b']],
      [['test/nested_deps_b', 'test/deps_c', 'test/no_deps_c']['test/nested_deps_b', 'test/deps_c', 'test/no_deps_c']],
    ];
  }

  /** * @covers ::getMinimalRepresentativeSubset * * @dataProvider providerTestGetMinimalRepresentativeSubset */
  public function testGetMinimalRepresentativeSubset(array $libraries, array $expected) {
    $this->assertEquals($expected$this->libraryDependencyResolver->getMinimalRepresentativeSubset($libraries));
  }

  /** * @covers ::getMinimalRepresentativeSubset */
  public function testGetMinimalRepresentativeSubsetInvalidInput() {
    $this->expectException(\AssertionError::class);
    $this->expectExceptionMessage('$libraries can\'t contain duplicate items.');
    $this->libraryDependencyResolver->getMinimalRepresentativeSubset(['test/no_deps_a', 'test/no_deps_a']);
  }

}

  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} */
  public function getCssAssets(AttachedAssetsInterface $assets$optimize, LanguageInterface $language = NULL) {
    
$js_assets[$order]['data'] = $js_group['data'];
          break;
      }
    }
    if ($libraries) {
      // All group URLs have the same query arguments apart from the delta and       // scope, so prepare them in advance.       $language = $this->languageManager->getCurrentLanguage()->getId();
      $query_args = [
        'language' => $language,
        'theme' => $this->themeManager->getActiveTheme()->getName(),
        'include' => UrlHelper::compressQueryParameter(implode(',', $this->dependencyResolver->getMinimalRepresentativeSubset($libraries))),
      ];
      $ajax_page_state = $this->requestStack->getCurrentRequest()
        ->get('ajax_page_state');
      $already_loaded = isset($ajax_page_state) ? explode(',', $ajax_page_state['libraries']) : [];
      if ($already_loaded) {
        $query_args['exclude'] = UrlHelper::compressQueryParameter(implode(',', $this->dependencyResolver->getMinimalRepresentativeSubset($already_loaded)));
      }

      // Generate a URL for the group, but do not process it inline, this is       // done by \Drupal\system\controller\JsAssetController.       foreach ($js_assets as $order => $js_asset) {
        
        // CSS assets.         $uri = $css_group['items'][0]['data'];
        $css_assets[$order]['data'] = $uri;
      }
    }

    // All asset group URLs will have exactly the same query arguments, except     // for the delta, so prepare them in advance.     $query_args = [
      'language' => $this->languageManager->getCurrentLanguage()->getId(),
      'theme' => $this->themeManager->getActiveTheme()->getName(),
      'include' => UrlHelper::compressQueryParameter(implode(',', $this->dependencyResolver->getMinimalRepresentativeSubset($libraries))),
    ];
    $ajax_page_state = $this->requestStack->getCurrentRequest()->get('ajax_page_state');
    $already_loaded = isset($ajax_page_state) ? explode(',', $ajax_page_state['libraries']) : [];
    if ($already_loaded) {
      $query_args['exclude'] = UrlHelper::compressQueryParameter(implode(',', $this->dependencyResolver->getMinimalRepresentativeSubset($already_loaded)));
    }

    // Generate a URL for each group of assets, but do not process them inline,     // this is done using optimizeGroup() when the asset path is requested.     foreach ($css_assets as $order => $css_asset) {
      if (!empty($css_asset['preprocessed'])) {
        
Home | Imprint | This part of the site doesn't use cookies.