We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34193
    • 330 Posts
    I am trying to write a plugin that runs upon doc publish, as part of the plugin I am trying to retrieve the id of the published/calling doc I have tried the following line which from reading docs etc should work

    $resourceId = $modx->resource->get('id');


    But as soon as I add this line to the code it causes it to stop working, I can run plugin np without the line and it does most of what I want, but retrieving the doc id would make it work as required.

    There are no errors showing in either the server logs or the modx log, the plugin just stops working.

    Can anyone spot any problems with the above line.
      • 28215
      • 4,149 Posts
      Quote from: peteedley at Oct 28, 2009, 12:36 PM

      I am trying to write a plugin that runs upon doc publish, as part of the plugin I am trying to retrieve the id of the published/calling doc I have tried the following line which from reading docs etc should work
      $resourceId = $modx->resource->get('id');

      But as soon as I add this line to the code it causes it to stop working, I can run plugin np without the line and it does most of what I want, but retrieving the doc id would make it work as required.
      There are no errors showing in either the server logs or the modx log, the plugin just stops working.
      Can anyone spot any problems with the above line.

      1. $modx->resource is only available on the front-end. It’s not always available in plugins, which can execute in a myriad of different contexts.
      2. I’m assuming you’re using the OnDocFormSave event. It passes the modResource object through the plugin properties, which can be accessed like so:

      $resource =& $scriptProperties['resource'];
      


      via the $scriptProperties array. We’ll eventually, once these calls get stabilized, document all the parameters that are passed in. Until then, just look at the call in the processor code.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 34193
        • 330 Posts
        Thanks Shaun,

        Actually using the OnDocPublish event since I am trying to write a plugin which publishes to twitter when a new item is added to the site, but some of the items may be created but not published till a later date and so don’t want them appearing on twitter until they are actually on the site.

        But the same command applys.