We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36552
    • 32 Posts
    I'm working on a EVO plugin and I'm having a difficult time determining when system events are occurring and what is available when they fire. I've read through the API documentation, but I haven't found quite what I need.

    Specifically, the plugin is going to update data in a related table that will track a group of tvs attached to a resource. The data from this table is applied to a sorting module I created, so that a resource can show up in multiple categories with a different (manually-determined) sort order.

    Where I am currently having a problem is the creation of a new resource. According to the API docs, a new resource doesn't have an id until OnDocFormSave (which makes sense), but I'm not sure at what point during that event does the plugin 'OnDocFormSave' event fire. Is it before the resource gets saved or after.

    If it's before, then how would I get the id to apply to my function or how do the tvs get the contentid when a resource is saved?

    Any help is appreciated and if anyone knows a great resource for MODx plugin development, please let me know.

    This question has been answered by Everettg_99. See the first response.

    [ed. note: djad33 last edited this post 14 years, 3 months ago.]
    • discuss.answer
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      OnDocFormSave occurs AFTER the row has been created in the database, so you can get its id -- if that were not the case, you'd be out of luck.

      In your plugin, you can do something like this:

      $page_id = $resource->get('id');
      // or simply
      $page_id = $id;
      


      When testing plugins, you often have to write messages to the log since the save action occurs asynchronously via AJAX (so you can't print data directly), e.g. to show all fields available to your resource:

      $modx->log(MODX_LOG_LEVEL_ERROR, print_r( $resource->toArray(), true ) );


      Hope that helps. I'll put an example in the docs for you. [ed. note: Everettg_99 last edited this post 14 years, 3 months ago.]
        • 36552
        • 32 Posts
        Everett! Yes, extremely helpful! Thank you!