Extra fields added to all entity types, causing noise in exported config

Created on 16 August 2024, 5 months ago

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

πŸ“Œ Task
Status

Active

Version

2.0

Component

Miscellaneous

Created by

πŸ‡©πŸ‡ͺGermany donquixote

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @donquixote
  • Assigned to huzooka
  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

    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.

  • Pipeline finished with Success
    2 months ago
    Total: 284s
    #341825
  • Pipeline finished with Success
    2 months ago
    Total: 269s
    #341886
  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

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

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    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.

  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

    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.

  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

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

  • Pipeline finished with Failed
    about 2 months ago
    Total: 283s
    #354540
  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

    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.
    
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 249s
    #354545
  • Pipeline finished with Success
    about 2 months ago
    Total: 262s
    #354547
  • πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

    I hope we can get back the RTBC status πŸ₯Ή

  • Pipeline finished with Success
    about 2 months ago
    Total: 255s
    #354551
  • πŸ‡΅πŸ‡±Poland alorenc Wolsztyn, πŸ‡΅πŸ‡±

    Looks good, moving to RTBC.

  • πŸ‡΅πŸ‡±Poland alorenc Wolsztyn, πŸ‡΅πŸ‡±
Production build 0.71.5 2024