We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51399
    • 7 Posts
    I deveoped an extra for a client that would allow them to generate PDFs from a resource and upload it to amazon S3.

    This takes the form of a plugin that runs 'OnDocFormSave', it uses $modx->getChunk to generate some HTML which it then passes to DOMPDF to generate the PDF. In the rendered chunk is an image+ snippet call to get the resource's image+ TV.

    Now this was all working absolutely fine, but the client asked me to make a couple of changes to the PDF (change some wording, add an extra image using Image+ and include the resource's ID in the header) and now suddenly the resource doesn't save, the save bar just gets stuck in a loop until I refresh.

    If I check my error logs I see:
    PHP Fatal error:  Call to a member function get() on a non-object in core/cache/v3Pyu45cTiNHtyEvFo6ADOULJ3oq859K/includes/elements/modsnippet/105.include.cache.php on line 23

    Snippet 105 is ImagePlus, and line 23 is:
    $docid = $modx->getOption('docid', $scriptProperties, $modx->resource->get('id'), true);


    So, I have worked out that if I remove the original ImagePlus snippet call (the new one I added still works fine) then the resource will save and generate its PDF (albeit without the image).

    But I can't figure out why the image that has been working this whole time now suddenly won't, and why the extra ImagePlus call does work.

    And just to confuse things slightly more, I checkout out an old commit from before these changes that I new to be working and reset the DB back to an old dump and still have the same issue.

    Hopefully I've explained my issue ok, because it is a somewhat confusing one (at least to me), any help anyone could give would be great, I've been pulling my hair out with this today.

    Thanks.

    • $modx->resource does not exist in your plugin, this causes the issue.
          • 51399
          • 7 Posts
          Thanks for the reply Jako, that is what I assumed the issue was but it still leaves me confused as to why it ever worked, and just to add to the confusion, it is working again now. It took me removing Image+ completely then reinstalling it from scratch twice.

          So my client is happy that it's working, but it leaves me concerned that I have no idea what the issue was or why it went away.

          Thanks for the pdfresource recommendation too, I built my version a few months ago and the client is happy with it, so there seems not much point switching it over now, but I wish I had discovered that at the start, it might have saved me some time and effort.