codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
42 stars 24 forks source link

Undo hooks does not support services #155

Closed dmolineus closed 3 years ago

dmolineus commented 3 years ago

Contao supports the usage of services for hooks for a long time. Haste still create the hook instance for itself, so it's not possbile to use services with proper DI.

https://github.com/codefog/contao-haste/blob/c040b0eb397771fb575273a8a88112e6a6b52d4f/library/Haste/Util/Undo.php#L97-L103

Line 99 should use \Contao\Controller::importStatic().

qzminski commented 3 years ago

This will be fixed in 4.24.11.

fritzmg commented 3 years ago

Btw. what about using regular TL_HOOKS and changing it to

foreach (array_merge($GLOBALS['HASTE_HOOKS']['undoData'] ?? [], $GLOBALS['TL_HOOKS']['hasteUndoData'] ?? []) as $callback) {

This way you could register the Hook with the @Hook annotation.

qzminski commented 3 years ago

@fritzmg that's a good idea, added in 34a6820.

fritzmg commented 3 years ago

Ah, I think this needs to be adjusted as well:

https://github.com/codefog/contao-haste/blob/822df2372cefcccd8675a4c9bae36a1962c9cf41/library/Haste/Util/Undo.php#L52-L54

qzminski commented 3 years ago

Right 🤦 1f6c3835 should do now.