Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Asset/AttachedAssets.php
- 9 core/lib/Drupal/Core/Asset/AttachedAssets.php
Namespace
Drupal\Core\Asset
File
core/lib/Drupal/Core/Asset/AttachedAssets.php
View source
<?php
namespace Drupal\Core\Asset;
class AttachedAssets implements AttachedAssetsInterface {
public $libraries = [];
public $settings = [];
protected $alreadyLoadedLibraries = [];
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;
}
public function setLibraries(array $libraries) {
$this->libraries = array_unique($libraries);
return $this;
}
public function getLibraries() {
return $this->libraries;
}
public function setSettings(array $settings) {
$this->settings = $settings;
return $this;
}
public function getSettings() {
return $this->settings;
}
public function getAlreadyLoadedLibraries() {
return $this->alreadyLoadedLibraries;
}
public function setAlreadyLoadedLibraries(array $libraries) {
$this->alreadyLoadedLibraries = $libraries;
return $this;
}
}
Classes