Add option to automatically generate PDFs after saving nodes in a queue

Created on 9 December 2024, 13 days ago

Problem/Motivation

The current method of generating PDFs in a batch job after clicking the 'Save and generate PDF' button has a couple limitations:

  • The 'Save and generate PDF' button is hidden behind the three dot menu when using Gin theme, making it hard to discover for inexperienced editors
  • When creating/updating a node programmatically, no PDF is generated
  • If a user closes the window when a PDF is being generated, the process is interrupted

Proposed resolution

Add a way of generating PDFs in background using a queue, for any node save, including programmatic ones.

User interface changes

Add a way to switch between the existing and the new behaviour. When choosing the new behaviour, no 'Save and generate PDF' button is being added to the node form anymore. In that case, the 'Override submit label' option should also be hidden.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇧🇪Belgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dieterholvoet
  • Pipeline finished with Success
    13 days ago
    Total: 135s
    #363484
  • 🇬🇧United Kingdom scott_euser

    Thanks I can see this being a really useful feature for some sites, thanks for your contributions. I added a couple comments.

  • Pipeline finished with Success
    12 days ago
    Total: 171s
    #364257
  • Pipeline finished with Success
    12 days ago
    Total: 138s
    #364261
  • 🇬🇧United Kingdom scott_euser

    Not sure if you have gitlab comments enabled (I think off by default) so just adding that I replied to your reply. Thanks!

  • 🇧🇪Belgium dieterholvoet Brussels

    Not sure if you have gitlab comments enabled (I think off by default) so just adding that I replied to your reply. Thanks!

    I have them enabled, no need to notify me here. Thanks

  • 🇬🇧United Kingdom scott_euser

    Okay going to see if one of my colleagues can give this a test run in one of our heavier usages of the module next regular maintenance round (which unless there is a security release that affects us, is probably in the new year in fairness, in case someone else wants to review earlier).

    Thanks for the work on this!

  • 🇧🇪Belgium dieterholvoet Brussels

    Sounds good! Did a small change to the documentation you added.

  • Pipeline finished with Success
    10 days ago
    Total: 139s
    #366083
  • Pipeline finished with Success
    6 days ago
    Total: 202s
    #369699
  • Pipeline finished with Success
    6 days ago
    Total: 134s
    #369849
  • 🇬🇧United Kingdom andreastkdf

    Thanks for the great addition @DieterHolvoet!

    Testing this on an existing site using the module

    This is after using the patch and running drush updb, which runs the hook:
    10002 - Set default value for new 'method' option.

    • New PDF generation happens options on the content type Edit page. Very minimal,
      but maybe the wording needs to be updated here? Maybe something like:
      Should the PDF be generated? or PDF generation mode
      (and update the option labels from to Manual, ...
      and to Automatic, ...).
    • The "Manually, after clicking the 'Save and generate PDF' button" option is selected by default.

    Default behaviour - without any change in the settings - using default
    Manually, after clicking the 'Save and generate PDF' button.

    • ✓ Live PDF preview works.
    • ✓ "Save and Generate PDF" button is available on the content item.
    • ✓ "Save and Generate PDF" works as usual; generates the PDF and saves it to the configured destination media document field.

    New behaviour - using Automatically, when the node is saved.

    • ✓ Can we also add this new method on the module page after it's merged?
    • Submit button label is removed on the content type Edit page.
    • ✓ Made a small change, saved the node, and ran cron. PDF generation job worked; it generates the PDF and saves it to the configured destination media document field.
    • ✗ Issue with translations:

      I followed the same steps for a node with multiple translations and noticed that saving translations does not add the job to the queue. This means separate translated PDFs are not being generated, unlike with the manual option.

      For example:

      1. ✗ On a node with multiple translations, I edited a translation, saved it, and then ran cron.

        Result: The "translated" PDF was not generated.
      2. ✓ By comparison, using the manual option:

        On the same node, I edited a translation and clicked Save and Generate PDF.

        Result: The PDF was generated for the current translation and updated the translatable destination media document field.

      The behaviour of the automatic option should match the manual option, where saving a translation triggers the generation of the corresponding translated PDF.

  • 🇧🇪Belgium dieterholvoet Brussels

    New PDF generation happens options on the content type Edit page. Very minimal, but maybe the wording needs to be updated here?

    I changed the title, but I don't agree with the proposed changes to the options. 'Automatic, when the node is saved' is not proper English.

    I followed the same steps for a node with multiple translations and noticed that saving translations does not add the job to the queue.

    I added a hook that triggers when creating a new translation. Are you sure updating a translation doesn't work yet? Because there's no such thing as a translation update hook, normal update hooks should be triggered when updating a translation.

  • Pipeline finished with Success
    3 days ago
    Total: 142s
    #373692
  • Pipeline finished with Skipped
    about 15 hours ago
    #375857
  • Pipeline finished with Skipped
    about 15 hours ago
    #375858
  • Pipeline finished with Skipped
    about 15 hours ago
    #375863
    • scott_euser committed c603dc72 on 1.0.x
      Issue #3492664 by dieterholvoet: Add option to automatically generate...
  • 🇬🇧United Kingdom scott_euser

    Thanks very much!

    I did a retest with:

    1. Automatic enabled
    2. Saved English and Spanish
    3. Ran cron
    4. Both PDFs updated as expected
Production build 0.71.5 2024