docs
docs copied to clipboard
[Content]: Manually attaching behaviors
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.