fix(core): restore event context in nested invokeEvent calls#16892
fix(core): restore event context in nested invokeEvent calls#16892Ibochkarev wants to merge 1 commit intomodxcms:3.xfrom
Conversation
Save and restore $this->event in invokeEvent() via try/finally so that outer plugins see the correct event name when nested invokeEvent calls occur (e.g. OnMediaSourceGetProperties during page load). Resolves modxcms#14063
d5001bc to
c46b1fd
Compare
Code ReviewSummary Fixes Assessment Clean, correct fix. The try/finally pattern is the right approach — it guarantees Verdict: Approve |
What does it do?
Save and restore
$this->eventininvokeEvent()via try/finally so that outer plugins see the correct event name when nestedinvokeEventcalls occur (e.g.OnMediaSourceGetPropertiesduring page load).Why is it needed?
When a static plugin calls
$modx->invokeEvent()from within another event handler, the nested call overwrites$this->event. After the nested call returns, the outer plugin sees the inner event's name instead of its own.How to test
OnWebPageInitthat prints$modx->event->name.OnMediaSourceGetPropertiesduring page load.OnWebPageInit, notOnMediaSourceGetProperties.Related issue(s)/PR(s)
Resolves #14063