MODX 3 coding question — onResourceSort not working

In a plugin, in MODX 3, the following isn’t working in a Manager plugin:

if($modx->event->name == 'OnResourceSort') {
  $resource = $modx->getObject('modResource', $modifiedNodes[0]->id);

Does MODX 3 not return $modifiedNodes after dragging and dropping in the tree? Or is something else amiss?

Works fine in 2.8.1.

The call looks like this:

$this->modx->invokeEvent('OnResourceSort', [
            'nodes' => &$this->nodes,
            'nodesAffected' => &$this->nodesAffected,
            'contexts' => &$this->contexts,
            'contextsAffected' => &$this->contextsAffected,
            'modifiedNodes' => &$this->nodesAffected, /* backward compat */

It looks like modifiedNodes is deprecated, so you might have better luck with nodesAffected.

I had already tried nodesAffected, and it didn’t return anything. I’ve tried it in MODX 3, and same thing: no ID returned. Should this work?:


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.

$modx->log(modX::LOG_LEVEL_ERROR,'Event: ' . $modx->event->name);

if($modx->event->name == 'OnResourceSort') {
  $resource = $modx->getObject('modResource', $modifiedNodes[0]->id);

Can you confirm this?

I think you’re right. I installed a plugin to write a message to the log onResourceSort and nothing happens.

I’ve submitted a bug report:

1 Like