We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    I am working on a website that needed some extra tables for document and they also use MaxiGallery.

    When a document is deleted the extra table rows are not deleted cause its not standard modx. also the files and table rows from MaxiGallery are not removed.

    I am trying to make a plugin that delete my cusom rows/tables and files. But I do not get this to work, I get the OnDocFormDelete to give me a alert so that part works (invoking the event) but now I need to know what file I am deleting and what template it is using. the plugin only needs to work on one template(id9).
    When this works then I need the page id with this id I can select the right table rows en gallerie folders to delete.

    I tryed this:

    $e = &$modx->Event;
    
    // Only on this event
    if ($e->name == 'OnDocFormDelete')
    {
       echo "<script> alert('".$modx->documentObject['template']."')</script>";
    }
    


    and it give me the alert but its empty, when i use this on the OnWebPagePrerender I get the correct template id in my alert but $modx->documentObject[’template’] somehow does not exist when I want to delete a document.

    could someone guide me in the right direction?

    Thanks

    Dimmy
      follow me on twitter: @dimmy01
      • 27376
      • 576 Posts
      You will need to retrieve the document using [tt]$modx->getDocument($id)[/tt].

      The reason why is that the document object is not loaded when you are about to delete it. Also, this event is called when the document is marked for deletion. So users can still un-delete the document.

      OnDocFormDelete at MODxWiki
        • 7455
        • 2,204 Posts
        I know that its not deleted but there is no event like OnRealyDocDelete so this is the closed I can get I think.
        but I realy need the option to see what template it hase before processing.

        OK I tryed this:
        $e = &$modx->Event;
        
        // Only on this event
        if ($e->name == 'OnDocFormDelete')
        {
           echo "<script> alert('".$modx->getDocument($id)."')</script>";
        }
        


        and again one empty alert box.
          follow me on twitter: @dimmy01
          • 27376
          • 576 Posts
          Sorry I didn’t mention this earlier but I just realized it too :-/

          Since the event your pluggin in to is called AFTER the document is marked for deletion you need to tell [tt]getDocument()[/tt] to search for deleted documents. Check the getDocument() documentation.