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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ameymudras created an issue. See original summary.

ameymudras’s picture

Status: Active » Needs review
FileSize
3.31 KB

Created 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

benjy’s picture

Status: Needs review » Needs work
  1. +++ b/src/Renderer/ContentEntityRenderer.php
    @@ -40,6 +48,7 @@ class ContentEntityRenderer extends RendererBase {
    +    $this->currentRequest = \Drupal::request();
    

    I don't think the renderer should have anything to do with the request, this seems like the wrong approach.

  2. +++ b/src/Renderer/ContentEntityRenderer.php
    @@ -60,7 +69,28 @@ class ContentEntityRenderer extends RendererBase {
       public function render(array $entities) {
    ...
    +    $current_path = $this->currentRequest->getPathInfo();;
    +    $path_args = explode('/', $current_path);
    

    Can we hook in earlier, and pass the loaded revision entities to this method instead?

ameymudras’s picture

Status: Needs work » Needs review
FileSize
2.49 KB

Thanks, benjy I have updated the patch by loading the entity in the controller itself.

benjy’s picture

  1. +++ b/src/Controller/EntityPrintController.php
    @@ -76,14 +76,37 @@ class EntityPrintController extends ControllerBase {
    +    if ($revision_id == 'latest') {
    

    I 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?

  2. +++ b/src/Controller/EntityPrintController.php
    @@ -76,14 +76,37 @@ class EntityPrintController extends ControllerBase {
    +        $entity = $node_revision = $this->entityTypeManager->getStorage('node')
    ...
    +      $entity = $node_revision = $this->entityTypeManager->getStorage('node')
    

    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?

sushyl’s picture

Adding a patch to support revisions for entity_print debug.

@benjy,

I 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.

@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.

Status: Needs review » Needs work

The last submitted patch, 6: 2979386-6-entity-print-revision-support.patch, failed testing. View results

sushyl’s picture

$revision in the last patch did not work and throws missing mandatory argument error. Fixed and re-submitting patch.

benjy’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: 2979386-7-entity-print-revision-support.patch, failed testing. View results

Elin Yordanov’s picture

I've created a new patch. Please review.

KapilV’s picture

Assigned: Unassigned » KapilV
KapilV’s picture

Assigned: KapilV » Unassigned
Elin Yordanov’s picture

Elin Yordanov’s picture

Status: Needs work » Needs review
DeepaliJ’s picture

Verified 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
test

Before patch pdf:
before

After patch pdf:
after

RTBC +1

DeepaliJ’s picture

Issue summary: View changes
Shubham Rathore’s picture

Assigned: Unassigned » Shubham Rathore
Shubham Rathore’s picture

Assigned: Shubham Rathore » Unassigned

Hi verified and applied patch #14 on Drupal 10.1.x-dev version setup. The patch applied successfully and cleanly.
Thanks.

mkindred’s picture

I 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: @TODO should be @todo in the patch. This case change was made back in #3104331.

I made the following changes to #14 and got it working for my purposes:

  1. added {revision_id} path parameter to the entity_print.revision.view and entity_print.revision.view.debug routes
  2. added a missing @param to the viewPrintDebug() document block
  3. revised entity_print_entity_view_alter() to add revision_id as a path parameter for the View PDF link.

I'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?

DiDebru’s picture

Fix 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).