Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 1.23 KB

volume-types.md

File metadata and controls

34 lines (24 loc) · 1.23 KB

Volume Types

Plugins can provide custom asset volume types by creating a class that implements craft\base\VolumeInterface and craft\base\VolumeTrait. The class will serve both as a way to communicate various things about your volume type (with static methods), and as a model that volumes of its type will be instantiated with.

As a convenience, you can extend craft\base\Volume, which provides a base volume type implementation, optimized for Flysystem adapters.

You can refer to Craft’s own volume classes for examples. They are located in vendor/craftcms/cms/src/volumes/.

Registering Custom Volume Types

Once you have created your volume class, you will need to register it with the Volumes service, so Craft will know about it when populating the list of available volume types:

<?php
namespace ns\prefix;

use craft\events\RegisterComponentTypesEvent;
use craft\services\Volumes;

class Plugin extends \craft\base\Plugin
{
    public function init()
    {
        Event::on(Volumes::class, Volumes::EVENT_REGISTER_VOLUME_TYPES, function(RegisterComponentTypesEvent $event) {
            $event->types[] = MyVolume::class;
        });

        // ...
    }

    // ...
}