function AttachedAssets::createFromRenderArray

Same name in other branches
  1. 9 core/lib/Drupal/Core/Asset/AttachedAssets.php \Drupal\Core\Asset\AttachedAssets::createFromRenderArray()
  2. 8.9.x core/lib/Drupal/Core/Asset/AttachedAssets.php \Drupal\Core\Asset\AttachedAssets::createFromRenderArray()
  3. 10 core/lib/Drupal/Core/Asset/AttachedAssets.php \Drupal\Core\Asset\AttachedAssets::createFromRenderArray()

Overrides AttachedAssetsInterface::createFromRenderArray

20 calls to AttachedAssets::createFromRenderArray()
AttachedAssetsTest::testAddExternalFiles in core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php
Tests adding external CSS and JavaScript files.
AttachedAssetsTest::testAddFiles in core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php
Tests adding a CSS and a JavaScript file.
AttachedAssetsTest::testAddJsFileWithQueryString in core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php
Tests JavaScript files that have query strings attached get added right.
AttachedAssetsTest::testAddJsSettings in core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php
Tests adding JavaScript settings.
AttachedAssetsTest::testAggregatedAttributes in core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php
Tests that attributes are maintained when JS aggregation is enabled.

... See full list

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.