Element Action Types

Plugins can provide custom action types for element index pages by creating a class that implements craft\base\ElementActionInterface (opens new window). The class will serve both as a way to communicate various things about your action type (with static methods), and as a model that actions of its type will be instantiated with.

As a convenience, you can extend craft\base\ElementAction (opens new window), which provides a base action type implementation.

You can refer to Craft’s own element action classes for examples. They are located in vendor/craftcms/cms/src/elements/actions/.

# Registering Custom Element Action Types

To get an element action to show up on an element index page, it has to be registered with the element type.

If it’s for a custom element type that is defined by the same plugin, simply include your element action in the element class’s defineActions() method.

If it’s for an element type that is out of the plugin’s control, you can register it using the registerActions event:

namespace mynamespace;

use craft\base\Element;
use craft\elements\Entry;
use craft\events\RegisterElementActionsEvent;
use yii\base\Event;

class Plugin extends \craft\base\Plugin
    public function init()
            function(RegisterElementActionsEvent $event) {
                $event->actions[] = MyAction::class;

        // ...

    // ...