Plugin: no resource data coming in [solved]

Hi!

I’m using a self-developed plugin to do something on saving (creating usergroup/resourcegroup if necessary) and this plugin is running fine since 2 years. And now I have a puzzle here: sometimes the modx->resource is NULL or empty. The variables $mode and $id are there and are filled. “Sometimes” in this case means: yesterday afternoon there was a problem and in the evening the plugin did it - and it didn’t (and right now is did). The cache is regularly cleared and watched and looks fine.
To deal with the missing resource element I just tried to get the resource via a getObject call on modResource with a given ID, but even this result is NULL. (additional note: this may be due to access rights, as the page is already assigned to groups - however, the editor is able to edit the page, so it should also be able to access the page).
Of course, the id is there and correct.

I’m still using this plugin in a MODX 2.7.3 version. On the stage system with the same code, the function runs (of course there is little editing and in case of problems no one will mentioned it - my tests yesterday were okay).
The event is set to OnDocFormSave, but also OnBeforeDocFormSave have this problem.

Does anyone know this problem?
What can be the reason for this behaviour?

Many greetings from Berlin,
Thorsten

I have no idea what causes this behaviour, but in your plugin for the events OnDocFormSave and OnBeforeDocFormSave you should have access to the resource directly with the variable $resource.
So maybe you could use $resource instead of $modx->resource.

1 Like

Many thanks!
Indeed, I have changed my code and for now it works.
I will keep an eye on it and see if it remains stable.

Thorsten