public static function AttachedAssets::createFromRenderArray in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Asset/AttachedAssets.php \Drupal\Core\Asset\AttachedAssets::createFromRenderArray()
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
20 calls to AttachedAssets::createFromRenderArray()
- AttachedAssetsTest::testAddExternalFiles in core/
modules/ system/ src/ Tests/ Common/ AttachedAssetsTest.php - Tests adding external CSS and JavaScript files.
- AttachedAssetsTest::testAddFiles in core/
modules/ system/ src/ Tests/ Common/ AttachedAssetsTest.php - Tests adding a CSS and a JavaScript file.
- AttachedAssetsTest::testAddJsFileWithQueryString in core/
modules/ system/ src/ Tests/ Common/ AttachedAssetsTest.php - Tests JavaScript files that have querystrings attached get added right.
- AttachedAssetsTest::testAddJsSettings in core/
modules/ system/ src/ Tests/ Common/ AttachedAssetsTest.php - Tests adding JavaScript settings.
- AttachedAssetsTest::testAggregatedAttributes in core/
modules/ system/ src/ Tests/ Common/ AttachedAssetsTest.php - Tests that attributes are maintained when JS aggregation is enabled.
File
- core/
lib/ Drupal/ Core/ Asset/ AttachedAssets.php, line 38 - Contains \Drupal\Core\Asset\AttachedAssets.
Class
- AttachedAssets
- The default attached assets collection.
Namespace
Drupal\Core\AssetCode
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;
}