Problem/Motivation

Once entity_print is enabled on a website, when re-saving and exporting entity view displays, we get this in "hidden" part:

hidden:
  entity_print_view_epub: true
  entity_print_view_pdf: true
  entity_print_view_word_docx: true

This happens even for entity types that we never ever want to print.
E.g. I found this happening for message templates.

Steps to reproduce

As above.

Proposed resolution

Provide an option to select the entity types for which the extra fields should be added.

Note:
I tried hook_entity_extra_field_info_alter() in a custom module to remove them from some entity types.
However, this does not remove the items in the display form, which then causes errors when visiting the manage display form.
So, it needs to be more sophisticated.

It would also be nice to only have the extra fields on specific view modes.
But this is not possible with how extra fields are done in core.

Remaining tasks

User interface changes

We would have to provide a form where this can be configured.

API changes

Data model changes

Command icon 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

donquixote created an issue. See original summary.

huzooka’s picture

Assigned: Unassigned » huzooka
Category: Task » Feature request

I also need the same feature (option to limit entity print to some specified types). I also discovered that extra fields are added to every single entity type, not just to content entity types.

Changing the category to feature request.

huzooka’s picture

Title: Extra fields added to all entity types, causing noise in exported config » Option to restrict entity print to specified entity types
Assigned: huzooka » Unassigned
Status: Active » Needs review

* Added a new config option to restrict print features to entity types.
* Added a config subscriber which resets entity field caches if config value is changed
* Updated hook implementations
* Added test coverage

Asking for review.

claudiu.cristea’s picture

Component: Miscellaneous » Code
Status: Needs review » Reviewed & tested by the community

Now I can limit entity print only to a limited group of entity types. No more unneeded extra fields and a huge Git diff on config export. Code looks good. Apart from manual testing, I see it has solid test coverage.

huzooka’s picture

Assigned: Unassigned » huzooka
Status: Reviewed & tested by the community » Needs work

We just hit an error with this patch applied, checking what's going on (should be obvious imho):

php.WARNING: Warning: Undefined array key "webform_submission" in entity_print_entity_extra_field_info() (line 63 of <project-root>/web/modules/contrib/entity_print/entity_print.module)

Moving back to NW.

huzooka’s picture

Th test method I just added should reveal the problem we saw (see #6)

huzooka’s picture

There they are!

https://git.drupalcode.org/issue/entity_print-3468563/-/jobs/3536971#L127

1 test triggered 2 PHP warnings:
1) /builds/issue/entity_print-3468563/entity_print.module:63
Undefined array key "entity_test_with_bundle"
Triggered by:
* Drupal\Tests\entity_print\Kernel\ExtraFieldsTest::testBundleableEntityTypeWithoutBundle
  /builds/issue/entity_print-3468563/tests/src/Kernel/ExtraFieldsTest.php:192
2) /builds/issue/entity_print-3468563/entity_print.module:63
foreach() argument must be of type array|object, null given
Triggered by:
* Drupal\Tests\entity_print\Kernel\ExtraFieldsTest::testBundleableEntityTypeWithoutBundle
  /builds/issue/entity_print-3468563/tests/src/Kernel/ExtraFieldsTest.php:192
OK, but there were issues!
Tests: 59, Assertions: 544, Warnings: 2.
huzooka’s picture

Assigned: huzooka » Unassigned
Status: Needs work » Needs review

I hope we can get back the RTBC status 🥹

alorenc’s picture

Looks good, moving to RTBC.

alorenc’s picture

Status: Needs review » Reviewed & tested by the community
pilot3’s picture

This approach works well. We have recently started using the Recurring Events module, which creates a custom entity type for all events. We want to add a print option to all event pages. I was able to select the custom entity and configure it to enable printing on event pages.

joseph.olstad’s picture

This is a duplicate of

#2928222: Consider to make configurable the entity type on which enable entity print

Postponing in favour of 2928222 since 2928222 is smaller and I've tested it with Drupal 11.1.x

joseph.olstad’s picture

Status: Reviewed & tested by the community » Postponed
joseph.olstad’s picture

Status: Postponed » Needs review

Actually, needs review. Please lets weigh the positives and negatives with both approaches.

#2928222: Consider to make configurable the entity type on which enable entity print

and

this one.

joseph.olstad’s picture

Disadvantage with 3468563 is there's no way to have zero entity types.

Our use case for entity_print is to have a view that generates a pdf, this works when using patch 2928222 and zero entity_types selected, meaning we have no extra cruff when not needed.

So while 2928222 introduces the requirement to configure the setting it is probably worth makeing a 3.0.x version for 2928222

joseph.olstad’s picture