public static function AttachedAssets::createFromRenderArray

public static AttachedAssets::createFromRenderArray(array $render_array)

Creates an AttachedAssetsInterface object from a render array.

Parameters

array $render_array: A render array.

Return value

\Drupal\Core\Asset\AttachedAssetsInterface

Throws

\LogicException

Overrides AttachedAssetsInterface::createFromRenderArray

File

core/lib/Drupal/Core/Asset/AttachedAssets.php, line 34

Class

AttachedAssets
The default attached assets collection.

Namespace

Drupal\Core\Asset

Code

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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Asset!AttachedAssets.php/function/AttachedAssets::createFromRenderArray/8.1.x