docs icon indicating copy to clipboard operation
docs copied to clipboard

[Content]: Manually attaching behaviors

Open AugustMiller opened this issue 1 year ago • 0 comments

Product

Craft CMS

Description

In a conversation about modifying built-in services, @bencroker noted that we don't mention yii\base\Component::attachBehavior() as an alternative to the event-based approach.

Most classes in Craft ultimately inherit from this (including our core services), so it's possible to augment them without going via an intermediate event listener:

Craft::$app->getGc()->attachBehavior('myPlugin.garbageEnhancements', TurboTrash::class);

This bears some similarities to our discussion of instance-level events.

AugustMiller avatar Apr 19 '24 15:04 AugustMiller