Events

Matrix Block Anchor does not currently fire custom events. Standard Craft field events (EVENT_DEFINE_RULES, EVENT_AFTER_VALIDATE, etc.) apply as they do on any craft\base\Field subclass.

Extending Validation

To add custom validation rules to the anchor field, use Craft's EVENT_DEFINE_RULES event on the field class:

use craft\base\Field;
use craft\events\DefineRulesEvent;
use johnhenry\matrixblockanchor\fields\MatrixBlockAnchorField;
use yii\base\Event;

Event::on(
    MatrixBlockAnchorField::class,
    Field::EVENT_DEFINE_RULES,
    function (DefineRulesEvent $event) {
        $event->rules[] = ['handle', 'match', 'pattern' => '/^anchor/'];
    }
);

Registering the Field Type

The field type is registered automatically when the plugin is installed. To reference the class in your own code:

use johnhenry\matrixblockanchor\fields\MatrixBlockAnchorField;

$anchorFields = Craft::$app->getFields()->getFieldsByType(MatrixBlockAnchorField::class);