Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
28.57% covered (danger)
28.57%
2 / 7
CRAP
41.18% covered (danger)
41.18%
7 / 17
AttachedAssets
0.00% covered (danger)
0.00%
0 / 1
28.57% covered (danger)
28.57%
2 / 7
30.35
41.18% covered (danger)
41.18%
7 / 17
 createFromRenderArray
0.00% covered (danger)
0.00%
0 / 1
4.84
62.50% covered (warning)
62.50%
5 / 8
 setLibraries
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getLibraries
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setSettings
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getSettings
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getAlreadyLoadedLibraries
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 setAlreadyLoadedLibraries
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
<?php
/**
 * @file
 * Contains \Drupal\Core\Asset\AttachedAssets.
 */
namespace Drupal\Core\Asset;
/**
 * The default attached assets collection.
 */
class AttachedAssets implements AttachedAssetsInterface {
  /**
   * The (ordered) list of asset libraries attached to the current response.
   *
   * @var string[]
   */
  public $libraries = [];
  /**
   * The JavaScript settings attached to the current response.
   *
   * @var array
   */
  public $settings = [];
  /**
   * The set of asset libraries that the client has already loaded.
   *
   * @var string[]
   */
  protected $alreadyLoadedLibraries = [];
  /**
   * {@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) {
    $this->libraries = array_unique($libraries);
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function getLibraries() {
    return $this->libraries;
  }
  /**
   * {@inheritdoc}
   */
  public function setSettings(array $settings) {
    $this->settings = $settings;
    return $this;
  }
  /**
   * {@inheritdoc}
   */
  public function getSettings() {
    return $this->settings;
  }
  /**
   * {@inheritdoc}
   */
  public function getAlreadyLoadedLibraries() {
    return $this->alreadyLoadedLibraries;
  }
  /**
   * {@inheritdoc}
   */
  public function setAlreadyLoadedLibraries(array $libraries) {
    $this->alreadyLoadedLibraries = $libraries;
    return $this;
  }
}