cms icon indicating copy to clipboard operation
cms copied to clipboard

[4.x] Add 'setup hooks' to tags to allow modification of tag state

Open ryanmitchell opened this issue 6 months ago • 0 comments

This PR adds the concept of 'hooks' into points in the tag lifecycle, allowing for modification of the state of the tag at that point.

Combined with macroable, this allows for reuse of the base tags in some circumstances where otherwise a custom tag would be required.

Usage is as follows:

\Statamic\Tags\Collection::addSetupHook(fn ($tag) => $tag->setParameters(['new_params' => 1));

\Statamic\Tags\Collection::addSetupHook([\App\MyClass::class, 'myMethod']);

Ideally this PR would also allow for a hook into the output of the tag (eg a render or processed hook) but I couldn't see how to do that without affecting the magic __call() on all tags that implement it. Maybe you have some bright ideas on an approach for that? Failing that, we could add hook into the output() method.

ryanmitchell avatar Feb 08 '24 10:02 ryanmitchell