I tried it with the newest Nightly Build for MODX 3 and it seems to me, that the Event OnResourceSort never gets fired at all. Nothing is written to the log, when I sort resources in the tree.
The array $modifiedNodes contains an object called “0”, which contains an array called “_fields”, which contains all the resource info, including the ID (and other fields).
0 is just the index of the first item in the array. (There may be other items.)
The items in the array should already be of type modResource. There’s no need to use $modx->getObject().
but $modifiedNodes[0]->id doesn’t work in MODX 3, so something is different there. It worked in MODX 2.8. Normally, I don’t have to use “get” ($resource->get(‘id’)), I can get the ID directly ($resource->id).
So, does this mean that any script where I use “$modx->resource->id” will fail in MODX 3?
UPDATE:
I tried $modx->resource->id in a script in MODX 3, and it works. So, why doesn’t $modifiedNodes[0]->id work? I tried $modifiedNodes[0]->get(‘id’), and that DOES work in MODX 3.
Maybe it depends on the system event used? Don’t know why it would. I’m using it with OnResourceSort. I did extensive testing and recording of output, and using $modifiedNodes[0]->id always gave no value.
For me, this works:
That’s exactly what I put in my script to test it, and no value for ID was recorded. So, no idea why it works for you and not for me! Not a big deal, since there are alternatives, but a mystery none the less.