Currently, the module doesn't provide any way of printing pdf for an entity revision. There is also no way of generating a pdf version of the latest revision page i.e /node/%nid/latest
Steps to follow:
1. Enable entity print module
2. Enable the content moderation module for workflows to have the latest revisions
3. Make necessary changes in the manage display as per the entity print module configuration
4. Create a node and published
5. Create multiple revisions with the latest revision (keep in draft)
6. Click on View pdf of the latest revision and check the changes if available
7. Now, apply the patch -> clear all cache
8. Go to that node's latest revision
9. Click on View pdf of the latest revision and check the changes if available
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | entity_print-revision_support-2979386-21.patch | 7.37 KB | didebru |
| #20 | interdiff_14_20.txt | 2.42 KB | mkindred |
| #20 | entity_print-revision_support-2979386-20.patch | 7.05 KB | mkindred |
| #16 | After patch - pdf.png | 65.53 KB | deepalij |
| #16 | before patch - pdf.png | 75.13 KB | deepalij |
Issue fork entity_print-2979386
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ameymudras commentedCreated a very basic patch that would provide revision support to the entity print module. With this patch, you can print node revisions as PDF's with URL such as print/pdf/node/%nid/%revision_id and also access the nodes latest revision using print/pdf/node/%nid/latest
Comment #3
benjy commentedI don't think the renderer should have anything to do with the request, this seems like the wrong approach.
Can we hook in earlier, and pass the loaded revision entities to this method instead?
Comment #4
ameymudras commentedThanks, benjy I have updated the patch by loading the entity in the controller itself.
Comment #5
benjy commentedI don't like revision_id being latest, does this get the currently published revision or the forward most revision? I think i'd prefer for that to be a separate route.
I'm also wondering if the access control needs to handle revisions as well?
This shouldn't be hard-coded to node, it needs to work for all entity types. We probably need to check if the entity type supports revisions?
Comment #6
sushylAdding a patch to support revisions for entity_print debug.
@benjy,
@benjy, I have changed $revision_id to $revision, since we are reusing the same controller method, I thought it'd be simpler to keep them together. Please confirm if we still need to add new route for 'latest' revision.
Comment #8
sushyl$revision in the last patch did not work and throws missing mandatory argument error. Fixed and re-submitting patch.
Comment #9
benjy commentedComment #11
ey commentedI've created a new patch. Please review.
Comment #12
kapilv commentedComment #13
kapilv commentedComment #14
ey commentedNew try
Comment #15
ey commentedComment #16
deepalij commentedVerified and applied patch #14 on Drupal 10.1.x-dev version with entity print v8.x-2.x-dev
The patch applied cleanly.
Steps:
1. Enable entity print module
2. Enable the content moderation module for workflows to have the latest revisions
3. Make necessary changes in the manage display as per the entity print module configuration
4. Create a node and published
5. Create multiple revisions with the latest revision (keep in draft)
6. Click on View pdf of the latest revision and check the changes if available
7. Now, apply the patch -> clear all cache
8. Go to that node's latest revision
9. Click on View pdf of the latest revision and check the changes if available
Result:
After applying the patch, able to print entity revisions as well.
Refer to the attached screenshots

Revision
Before patch pdf:

After patch pdf:

RTBC +1
Comment #17
deepalij commentedComment #18
shubham rathore commentedComment #19
shubham rathore commentedHi verified and applied patch #14 on Drupal 10.1.x-dev version setup. The patch applied successfully and cleanly.
Thanks.
Comment #20
mkindred commentedI need to create PDFs of revisions, so I tried #14, but it didn't work for me. Although it alters the controller to accomodate printing revisions from PDFs, it seems to be lacking the {revision_id} path parameter for the entity_print.revision.view and entity_print.revision.view.debug routes.
Also, I couldn't apply the patch via git apply due to a case mismatch in EntityPrintController.php:
@TODOshould be@todoin the patch. This case change was made back in #3104331.I made the following changes to #14 and got it working for my purposes:
{revision_id}path parameter to the entity_print.revision.view and entity_print.revision.view.debug routesI'm sure that my revision to entity_print_entity_view_alter() (to alter the View PDF link) is the wrong way to go about this, so consider this patch to be in-progress. It assumes that there's always a revision id, and it works for my specific use case so far. But I'm sure this needs to be improved.
@benjy can I get some feedback on the overall direction of the patch?
Comment #21
didebruFix fatal error:
Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "revision_id" for route "entity_print.revision.view" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 206 of core/lib/Drupal/Core/Routing/UrlGenerator.php).Comment #22
donquixote commentedWith the latest patch we are using access check for the revision page even for the regular non-revision link.
I think it would be cleaner to have two separate paths of control flow.
I am going to prepare an MR.
Comment #23
donquixote commentedI think the type needs to be "int|null".
This is what I see a lot in core for parameters with NULL default value.
This seems weird:
The redirect route is only meant for legacy support, so we should not expect this to be called with a revision id.
On the other hand: If we support a revision_id parameter, then we need to conditionally change the route for the redirect to use the revision route.
Comment #24
donquixote commentedSee also #3448919: Wrong usage of trim() in entity_print_entity_view_alter().
If we solve that, it will conflict with the patches here..
Comment #26
donquixote commentedI pushed some what I think are improvements - TBD.
See the individual commit messages.
I should also add tests, but that requires a bit more thinking and searching.
Comment #27
donquixote commentedActually it could be useful to add the revision id or the revision date to the file name of a pdf.
Comment #28
smustgrave commentedTested MR following the steps and revision is being printed perfectly.
Something probably that should have simple test coverage.
Don't see any file for moderation so probably could add one to Functional or Kernel folders.
Comment #30
alexpottI've added test coverage and improve the MR slightly.
Comment #33
jsacksick commentedMerged! Thanks everyone!