You are here

class AttachedAssets in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Asset/AttachedAssets.php \Drupal\Core\Asset\AttachedAssets

The default attached assets collection.

Hierarchy

Expanded class hierarchy of AttachedAssets

7 files declare their use of AttachedAssets
AjaxResponseAttachmentsProcessor.php in core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
Contains \Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor.
AssetResolverTest.php in core/tests/Drupal/Tests/Core/Asset/AssetResolverTest.php
Contains \Drupal\Tests\Core\Asset\AssetResolverTest.
AttachedAssetsTest.php in core/modules/system/src/Tests/Common/AttachedAssetsTest.php
Contains \Drupal\system\Tests\Common\AttachedAssetsTest.
CommandWithAttachedAssetsTrait.php in core/lib/Drupal/Core/Ajax/CommandWithAttachedAssetsTrait.php
Contains \Drupal\Core\Ajax\CommandWithAttachedAssetsTrait.
FrameworkTest.php in core/modules/system/src/Tests/Ajax/FrameworkTest.php
Contains \Drupal\system\Tests\Ajax\FrameworkTest.

... See full list

File

core/lib/Drupal/Core/Asset/AttachedAssets.php, line 12
Contains \Drupal\Core\Asset\AttachedAssets.

Namespace

Drupal\Core\Asset
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AttachedAssets::$alreadyLoadedLibraries protected property The set of asset libraries that the client has already loaded.
AttachedAssets::$libraries public property The (ordered) list of asset libraries attached to the current response.
AttachedAssets::$settings public property The JavaScript settings attached to the current response.
AttachedAssets::createFromRenderArray public static function Creates an AttachedAssetsInterface object from a render array. Overrides AttachedAssetsInterface::createFromRenderArray
AttachedAssets::getAlreadyLoadedLibraries public function Returns the set of already loaded asset libraries. Overrides AttachedAssetsInterface::getAlreadyLoadedLibraries
AttachedAssets::getLibraries public function Returns the asset libraries attached to the current response. Overrides AttachedAssetsInterface::getLibraries
AttachedAssets::getSettings public function Returns the settings attached to the current response. Overrides AttachedAssetsInterface::getSettings
AttachedAssets::setAlreadyLoadedLibraries public function Sets the asset libraries that the current request marked as already loaded. Overrides AttachedAssetsInterface::setAlreadyLoadedLibraries
AttachedAssets::setLibraries public function Sets the asset libraries attached to the current response. Overrides AttachedAssetsInterface::setLibraries
AttachedAssets::setSettings public function Sets the JavaScript settings that are attached to the current response. Overrides AttachedAssetsInterface::setSettings