Support for printing entity revision

Created on 13 June 2018, about 6 years ago
Updated 11 June 2024, 14 days ago

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

🐛 Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

🇮🇳India ameymudras

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    54 pass
  • 🇺🇸United States mkindred

    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 🐛 PHP_CodeSniffer warnings and errors Fixed .

    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.

    @bengy can I get some feedback on the overall direction of the patch?

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 8 months ago
    54 pass
  • 🇩🇪Germany DiDebru

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

  • 🇩🇪Germany donquixote
    -        '#access' => $access_manager->checkNamedRoute('entity_print.view', $route_params, NULL, TRUE),
    +        '#access' => $access_manager->checkNamedRoute('entity_print.revision.view', $route_params, NULL, TRUE),
    

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

  • 🇩🇪Germany donquixote
    +   * @param int $revision_id
    +   *   The entity revision id.
    

    I think the type needs to be "int|null".
    This is what I see a lot in core for parameters with NULL default value.

    -  public function viewRedirectDebug($export_type, $entity_type, $entity_id) {
    +  public function viewRedirectDebug($export_type, $entity_type, $entity_id, $revision_id = NULL) {
         return $this->redirect('entity_print.view.debug', [
           'export_type' => $export_type,
           'entity_type' => $entity_type,
           'entity_id' => $entity_id,
    +      'revision_id' => $revision_id,
         ]);
       }
    

    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.

  • 🇩🇪Germany donquixote

    See also 🐛 Wrong usage of trim() in entity_print_entity_view_alter() Active .
    If we solve that, it will conflict with the patches here..

  • Pipeline finished with Success
    about 1 month ago
    Total: 230s
    #178647
  • Pipeline finished with Success
    about 1 month ago
    Total: 276s
    #178661
  • 🇩🇪Germany donquixote

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

  • 🇩🇪Germany donquixote

    Actually it could be useful to add the revision id or the revision date to the file name of a pdf.

  • Status changed to Needs work 14 days ago
  • 🇺🇸United States smustgrave

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

Production build 0.69.0 2024