system.assets.beforeAddAsset

Provides an opportunity to inspect or modify an asset.

The parameters provided are: string $type: The type of the asset being added string $path: The path to the asset being added array $attributes: The array of attributes for the asset being added.

All the parameters are provided by reference for modification. This event is also a halting event, so returning false will prevent the current asset from being added. Note that duplicates are filtered out before the event is fired.

Example usage:

Event::listen('system.assets.beforeAddAsset', function (string &$type, string &$path, array &$attributes) {
    if (in_array($path, $blockedAssets)) {
        return false;
    }
});

Or

$this->bindEvent('assets.beforeAddAsset', function (string &$type, string &$path, array &$attributes) {
    $attributes['special_cdn_flag'] = false;
});

Usage

Globally

use Event;

Event::listen('system.assets.beforeAddAsset', function () {
    // Your event listener code goes here...
});

Triggers

Class or file Line
System\Traits\AssetMaker 230
Copyright © 2024 Winter CMS