Add option to set theme used for entity_print rendering

Created on 13 March 2017, over 7 years ago
Updated 14 March 2023, over 1 year ago

We use entity_print to generate PDF files programmatically.

This is done upon multiple events triggered by end-users (default theme), in the admin-backend (with the admin theme) and command-line (default theme again).
We used this code to get this done: https://www.drupal.org/node/2831952#comment-11871535
We included our PDF template files in the default theme.

The problem is that when the admin-theme is active, the templates and css of the default theme are not used for the PDF rendering.
Therefore those PDF's look really bad.

Some questions:
- Is it possible to pass the theme that must be used to render the PDF somewhere as config option? Like how?
- Is it best-practise to move the template, CSS and preprocessors to the custom module that handles the PDF-rendering?
- Is it best-practise to create a separate theme for PDF rendering?

Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

🇳🇱Netherlands ndf Amsterdam

Live updates comments and jobs are added and updated live.
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.

  • First commit to issue fork.
  • 🇺🇸United States sassafrass

    I was unable to apply the latest patch using:
    Drupal core 9.4.10
    Entity Print 8.x-2.11

  • 🇺🇸United States caesius

    Regarding the previous comment, we were using both this patch and the one in 2996197: Use absolute paths in css Use absolute paths in css Needs work which resulted in a patching conflict.

    Attached is a patch which combines both.

  • Status changed to Needs work over 1 year ago
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    This is looking great, we just need a BC layer for the service constructor changes in case someone has sub-classed the services.

    So default the new arguments to null, if they're not set, use trigger_error to trigger a deprecation and set it using \Drupal.

    Here's an example from core - https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/lib/Drupal/...

    We also need a change notice so we have something to link to, there's a link at the top of this page to 'add change notice'

    Thanks again, nice work adding an upgrade path 🤌

  • 🇨🇦Canada spiderman Halifax, NS

    FYI, we've been using the patch/MR here along with the one in Support multiple view modes for a given library Needs review , and found managing the two patches at once to be cumbersome. As such, I've created a custom fork that incorporates both, here: https://gitlab.com/consensus.enterprises/drupal/entity_print/-/commits/d...

  • I am guessing this would require other modules to update dependency injection. Seeing this trying to use this patch on commerce orders:

    ArgumentCountError: Too few arguments to function Drupal\entity_print\Renderer\ContentEntityRenderer::__construct(), 5 passed in /var/www/html/web/modules/contrib/commerce/modules/order/src/EntityPrint/OrderRenderer.php on line 50 and exactly 7 expected in Drupal\entity_print\Renderer\ContentEntityRenderer->__construct() (line 60 of /var/www/html/web/modules/contrib/entity_print/src/Renderer/ContentEntityRenderer.php).

  • 🇦🇹Austria mvonfrie

    MR 16 conflicts with #2971822 🐛 Allow users to choose whether to optimize css. RTBC .

  • 🇦🇹Austria mvonfrie

    About #39 the error message in commerce order there is already an issue ( Commerce #3336653 💬 Support setting theme for entity print patch Needs review ), added it as child issue.

  • 🇨🇦Canada gwvoigt London, ON 🇨🇦

    Same as @spiderman, I'm using patch #44 from https://www.drupal.org/project/entity_print/issues/2884806 Support multiple view modes for a given library Needs review (Support multiple view modes for a given library) and this patch conflicts with it. I tried adapting the patch locally to work with the patch from this current issue but no luck. Also tried @spiderman's fork (Merge branch '2884806-support-multiple-view-modes' into develop commit) but no luck either. I'm on:

    Drupal 10.1.4
    entity print 8.x-2.13
    using the patches:
    https://www.drupal.org/files/issues/2023-01-21/support-multiple-view-mod...
    https://www.drupal.org/files/issues/2023-07-10/entity_print-dompdf_page_...

  • 🇨🇦Canada gwvoigt London, ON 🇨🇦

    I could fix it in a hook_preprocess_entity_print:

    $css = '
    ';
    $variables['entity_print_css'] = Markup::create($css);

    It's not ideal but it works, none of the patches provided worked for me unfortunatelly.

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 11 months ago
    52 pass, 2 fail
  • 🇺🇸United States SocialNicheGuru

    I upgraded to Drupal 10.3 and php8.2
    I ran system updates for views.

    I got the following error because of this patch

    ArgumentCountError: Too few arguments to function [error]
    Drupal\entity_print\PrintBuilder::__construct(), 3 passed in
    drupal-10.3.x/html/core/lib/Drupal/Component/DependencyInjection/Container.php
    on line 261 and exactly 4 expected in Drupal\entity_print\PrintBuilder->__construct() (line 56
    of
    drupal-10.3.x/html/modules/contrib/entity_print/src/PrintBuilder.php)

  • First commit to issue fork.
  • Pipeline finished with Failed
    4 months ago
    Total: 266s
    #254087
  • Pipeline finished with Failed
    4 months ago
    Total: 363s
    #254111
  • 🇺🇦Ukraine Taran2L Lviv

    taran2l changed the visibility of the branch 8.x-2.x to hidden.

  • 🇺🇦Ukraine Taran2L Lviv

    taran2l changed the visibility of the branch issue/entity_print-2860122-2860122-how-to-set to hidden.

  • Pipeline finished with Success
    4 months ago
    Total: 353s
    #254131
  • Status changed to Needs review 4 months ago
  • 🇺🇦Ukraine Taran2L Lviv

    Added a draft change record + concrete module version + fixed PHPunit

  • 🇮🇹Italy viappidu

    Not sure why but I cannot merge your last push. Created a patch

  • 🇺🇸United States caesius

    The above patch is almost identical to the MR except it removes the newly-added src/ThemeResolverInterface.php and src/ThemeResolver.php files.

    I had no issues applying the MR to either the current 8.x-2.x-dev or to 8.x-2.15, so I don't see any reason for #50 to have been created. Please be more careful when creating patches.

  • 🇪🇸Spain Bryan Toapanta

    The patch generated from the MR (https://git.drupalcode.org/project/entity_print/-/merge_requests/16.patch) is not compatible with version 2.15.

    I have created a new patch that makes it compatible with version 2.15.

    The patch adds changes from commit , which is not available in version 2.15, but is available in the 8.x-2.x-dev version.
    Issue: https://www.drupal.org/project/entity_print/issues/3465822 📌 Fix deprecated function user_roles() Fixed

  • #52 10.3.8+entity print 2.5
    I tried with some failed as ,
    [root@drupal entity_print]# patch -p1 < entity-print-2860122-52.patch
    patching file config/install/entity_print.settings.yml
    patching file config/schema/entity_print.schema.yml
    Hunk #1 FAILED at 2.
    1 out of 1 hunk FAILED -- saving rejects to file config/schema/entity_print.schema.yml.rej
    patching file entity_print.install
    patching file entity_print.post_update.php
    patching file entity_print.services.yml
    patching file src/Asset/AssetCollector.php
    patching file src/Form/SettingsForm.php
    Hunk #4 FAILED at 108.
    Hunk #5 succeeded at 166 (offset 6 lines).
    Hunk #6 FAILED at 241.
    2 out of 6 hunks FAILED -- saving rejects to file src/Form/SettingsForm.php.rej
    patching file src/PrintBuilder.php
    Hunk #4 FAILED at 140.
    1 out of 4 hunks FAILED -- saving rejects to file src/PrintBuilder.php.rej
    patching file src/Renderer/ContentEntityRenderer.php
    patching file src/ThemeResolver.php
    patching file src/ThemeResolverInterface.php
    patching file tests/src/Unit/AssetCollectorTest.php
    before this installed another patch like this, https://www.drupal.org/project/entity_print/issues/2996197#comment-15665803 Use absolute paths in css Needs work

  • 🇮🇹Italy trickfun

    Patch doesn't work with batch process and savePrintable method.
    Theme resolver get right theme but PDF is rendered with admin theme again.

Production build 0.71.5 2024