简体   繁体   English

Joomla事件onContentAfterSave未触发

[英]Joomla event onContentAfterSave not firing

I'm trying to run some code when a Joomla plugin config is saved and I've gone through the documentation and tried all content events I could find there with a die(); 保存Joomla插件配置后,我正在尝试运行一些代码,并仔细阅读了文档并尝试了所有可以通过die();找到的内容事件die(); in them and none is triggered. 在他们身上,没有任何触发。

public function onContentAfterSave($context, $article, $isNew)
    {
        die();
    }

Can anyone point out how I can achieve this please? 谁能指出我如何实现这一目标?

onContentBeforeSave does just what the name suggests: fires before you save content not plugin configuration. onContentBeforeSave确实如其名所示:在保存内容而不是插件配置之前触发。 In order to catch the saved plugin configuration you have no Joomla events available. 为了捕获已保存的插件配置,您没有可用的Joomla事件。

So you can check if the plugin configuration was changed at every page load in the administrator: the sequence would be: 因此,您可以检查管理员在每次加载页面时是否更改了插件配置:顺序为:

Your plugin onContentBeforeDisplay (or some other events you don't need for your business logic) runs in the administrator only (which is the not the default behaviour, you'll need to check and exit if it's frontend to avoid slowing down your site) and in that event handler you check for a custom configuration field: to achieve this you just insert a custom (hidden) value in the plugin configuration. 您的插件onContentBeforeDisplay(或您的业务逻辑不需要的其他一些事件)仅在管理员中运行(这不是默认行为,您需要检查并退出它的前端,以避免降低网站速度)然后在该事件处理程序中检查自定义配置字段:要实现此目的,您只需在插件配置中插入自定义(隐藏)值即可。 When your event fires, you load the plugin configuration and check if it's the default value or not, remove it from the configuration object and save it again to the db; 当事件触发时,您将加载插件配置,并检查其是否为默认值,然后将其从配置对象中删除,然后再次将其保存到数据库中。 so next time the user loads it it will change again, setting the default value. 因此,下次用户加载它时,它将再次更改,并设置默认值。 Not nice but it will work. 不好,但是可以用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM