Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/Asset/AttachedAssets.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Core\Asset; |
Chris@0 | 4 |
Chris@0 | 5 /** |
Chris@0 | 6 * The default attached assets collection. |
Chris@0 | 7 */ |
Chris@0 | 8 class AttachedAssets implements AttachedAssetsInterface { |
Chris@0 | 9 |
Chris@0 | 10 /** |
Chris@0 | 11 * The (ordered) list of asset libraries attached to the current response. |
Chris@0 | 12 * |
Chris@0 | 13 * @var string[] |
Chris@0 | 14 */ |
Chris@0 | 15 public $libraries = []; |
Chris@0 | 16 |
Chris@0 | 17 /** |
Chris@0 | 18 * The JavaScript settings attached to the current response. |
Chris@0 | 19 * |
Chris@0 | 20 * @var array |
Chris@0 | 21 */ |
Chris@0 | 22 public $settings = []; |
Chris@0 | 23 |
Chris@0 | 24 /** |
Chris@0 | 25 * The set of asset libraries that the client has already loaded. |
Chris@0 | 26 * |
Chris@0 | 27 * @var string[] |
Chris@0 | 28 */ |
Chris@0 | 29 protected $alreadyLoadedLibraries = []; |
Chris@0 | 30 |
Chris@0 | 31 /** |
Chris@0 | 32 * {@inheritdoc} |
Chris@0 | 33 */ |
Chris@0 | 34 public static function createFromRenderArray(array $render_array) { |
Chris@0 | 35 if (!isset($render_array['#attached'])) { |
Chris@0 | 36 throw new \LogicException('The render array has not yet been rendered, hence not all attachments have been collected yet.'); |
Chris@0 | 37 } |
Chris@0 | 38 |
Chris@0 | 39 $assets = new static(); |
Chris@0 | 40 if (isset($render_array['#attached']['library'])) { |
Chris@0 | 41 $assets->setLibraries($render_array['#attached']['library']); |
Chris@0 | 42 } |
Chris@0 | 43 if (isset($render_array['#attached']['drupalSettings'])) { |
Chris@0 | 44 $assets->setSettings($render_array['#attached']['drupalSettings']); |
Chris@0 | 45 } |
Chris@0 | 46 return $assets; |
Chris@0 | 47 } |
Chris@0 | 48 |
Chris@0 | 49 /** |
Chris@0 | 50 * {@inheritdoc} |
Chris@0 | 51 */ |
Chris@0 | 52 public function setLibraries(array $libraries) { |
Chris@0 | 53 $this->libraries = array_unique($libraries); |
Chris@0 | 54 return $this; |
Chris@0 | 55 } |
Chris@0 | 56 |
Chris@0 | 57 /** |
Chris@0 | 58 * {@inheritdoc} |
Chris@0 | 59 */ |
Chris@0 | 60 public function getLibraries() { |
Chris@0 | 61 return $this->libraries; |
Chris@0 | 62 } |
Chris@0 | 63 |
Chris@0 | 64 /** |
Chris@0 | 65 * {@inheritdoc} |
Chris@0 | 66 */ |
Chris@0 | 67 public function setSettings(array $settings) { |
Chris@0 | 68 $this->settings = $settings; |
Chris@0 | 69 return $this; |
Chris@0 | 70 } |
Chris@0 | 71 |
Chris@0 | 72 /** |
Chris@0 | 73 * {@inheritdoc} |
Chris@0 | 74 */ |
Chris@0 | 75 public function getSettings() { |
Chris@0 | 76 return $this->settings; |
Chris@0 | 77 } |
Chris@0 | 78 |
Chris@0 | 79 /** |
Chris@0 | 80 * {@inheritdoc} |
Chris@0 | 81 */ |
Chris@0 | 82 public function getAlreadyLoadedLibraries() { |
Chris@0 | 83 return $this->alreadyLoadedLibraries; |
Chris@0 | 84 } |
Chris@0 | 85 |
Chris@0 | 86 /** |
Chris@0 | 87 * {@inheritdoc} |
Chris@0 | 88 */ |
Chris@0 | 89 public function setAlreadyLoadedLibraries(array $libraries) { |
Chris@0 | 90 $this->alreadyLoadedLibraries = $libraries; |
Chris@0 | 91 return $this; |
Chris@0 | 92 } |
Chris@0 | 93 |
Chris@0 | 94 } |