Skip to content

Assets field - make _getUploadedFiles publicly available / protected instead of private #11123

Closed Answered by brandonkelly
Anubarak asked this question in Ideas
Discussion options

You must be logged in to vote

Just added a new EVENT_LOCATE_UPLOADED_FILES event to Assets fields, which you can tap into to add additional files to the mix, without needing to extend craft\fields\Assets.

use craft\events\LocateUploadedFilesEvent;
use craft\fields\Assets;
use yii\base\Event;

Event::on(
    Assets::class,
    Assets::EVENT_LOCATE_UPLOADED_FILES,
    function(LocateUploadedFilesEvent $event) {
        /** @var Assets $field */
        $field = $event->sender;
        
        $event->files[] = [
            'type' => 'file',
            'filename' => 'foo.jpg',
            'path' => '/path/to/temp/foo.jpg',
        ];
    }
);

It’ll be in the next v3 and v4 releases.

To get the change early, you can ch…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Anubarak
Comment options

@brandonkelly
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants