Back to WebAssetManager class

Method getAssets

public \Joomla\CMS\WebAsset\WebAssetItem[]
getAssets
(string $type, bool $sort = false)
Get all active assets, optionally sort them to follow the dependency Graph
Parameters
  • string $type The asset type, script or style
  • bool $sort Whether need to sort the assets to follow the dependency Graph
Returns
  • \Joomla\CMS\WebAsset\WebAssetItem[]
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnknownAssetException When Asset cannot be found
  • \Joomla\CMS\WebAsset\Exception\UnsatisfiedDependencyException When Dependency cannot be found

Method getAssets - Source code

/**
 * Get all active assets, optionally sort them to follow the dependency Graph
 *
 * @param   string  $type  The asset type, script or style
 * @param   bool    $sort  Whether need to sort the assets to follow the dependency Graph
 *
 * @return  WebAssetItem[]
 *
 * @throws  UnknownAssetException  When Asset cannot be found
 * @throws  UnsatisfiedDependencyException When Dependency cannot be found
 *
 * @since  4.0.0
 */
public function getAssets(string $type, bool $sort = false) : array
{
    // Make sure that all dependencies are active
    if (!$this->dependenciesIsActual) {
        $this->enableDependencies();
    }
    if (empty($this->activeAssets[$type])) {
        return [];
    }
    // Apply Tree sorting for regular asset items, but return FIFO order for "preset"
    if ($sort && $type !== 'preset') {
        $assets = $this->calculateOrderOfActiveAssets($type);
    } else {
        $assets = [];
        foreach (array_keys($this->activeAssets[$type]) as $name) {
            $assets[$name] = $this->registry->get($type, $name);
        }
    }
    return $assets;
}