Opt-out per entity type / bundle

Created on 15 November 2023, 8 months ago
Updated 14 June 2024, 14 days ago

Problem/Motivation

This module automatically adds properties and special view modes to all content entity types (with a few exceptions, see below).
While this might be handy for sites with the sole purpose of providing content to Digital Signage devices, it can be pretty annoying in mixed-content scenarios, where only a small part of the content is meant to be exposed to Digital Signage.

<!--break-->

Especially the fact that the view modes are re-created over and over can be a real hassle.

Consider this scenario:

  1. Install a module that provides a custom content entity type, which has nothing to do with Digital Signage.
  2. This module automatically adds the view modes Digital Signage portrait and Digital Signage landscape to the new entity type, regardless of whether they are needed.
  3. These view modes get different UUIDs when installed on development, testing, production.
  4. Normally, when you deploy config e.g. to production, the view modes would be deleted and re-created with the UUIDs from the source, but this fails, because after the deletion, they get re-created at once by the digital_signage_framework_entity_base_field_info() hook.

Proposed resolution

To reduce the pain at least for entity types that are not meant to be used with Digital Signage, there should be a possibility to opt out of this behavior. We would need this setting on entity type level, and possibly also per bundle.
There exists a hard-coded list of entity types to be exluded in the \Drupal\digital_signage_framework\EntityTypes class, but it is not configurable.

Remaining tasks

  • Agree on a solution
  • Implement
  • Review & test
  • Commit

User interface changes

API changes

Data model changes

Feature request
Status

Fixed

Version

2.6

Component

Code

Created by

🇩🇪Germany mrshowerman Munich

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

Merge Requests

Comments & Activities

  • Issue created by @mrshowerman
  • 🇩🇪Germany danielspeicher Steisslingen

    Thank you for your request. Yes, we see your problem. Let us discuss a proper solution here.

    To make this configurable seems to be a proper proposal. This week might be a little busy, but if you are able to provide a first implementation, we would appreciate this.

  • 🇩🇪Germany mrshowerman Munich

    I will try my best to come up with a first approach in the next few days.

  • Assigned to mrshowerman
  • Pipeline finished with Failed
    7 months ago
    #50859
  • Pipeline finished with Failed
    7 months ago
    Total: 143s
    #50896
  • Pipeline finished with Success
    7 months ago
    #50905
  • Issue was unassigned.
  • Status changed to Needs review 7 months ago
  • 🇩🇪Germany mrshowerman Munich

    Here is a first working attempt. I decided not to touch the hard-coded list of excluded entity types, and add a configurable list on top of that (used the term disabled for it).
    That way we reduce the list of types that can be checked, making it easier to read.

    For a start, disabled entity types will be ignored in the automatic (re-)creation of the Digital Signage view modes only. There might be other places where the list could be used as well.

    I did not work on disabling bundles yet. At least for the view mode part, it's not necessary, since they get created on entity type level.

  • 🇩🇪Germany mrshowerman Munich

    For people still on the 2.4.x branch, here's a patch that should apply to it.

  • Status changed to Needs work 7 months ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    There is a conceptual problem in making base field dependent on config (or any other changeable definition) because base fields get added during entity type initialization and get to create a database column. If a base field gets added dynamically later on, an update hook would be required to add that database field. On the other hand, disabling an entity type later on would also require cleaning up the database. However, that then comes with a potential data loss, if somebody disables an entity type mistakenly, that data would then be gone forever.

    That's why the concept of this module was done this way: every entity type has that base field for the digital signage entity reference. The cost is so little, as it is just one integer column attached to the entity base table.

    If we want to make digital signage support configurable per entity type and/or bundle, then we should consider doing this in the UI only. That would mean that the data structure remains the same as it is today, but we alter the forms in a way, that the fields are only displayed for supported entity types.

  • 🇩🇪Germany mrshowerman Munich

    I see your point, @jurgenhaas.
    That's why I didn't work on removing any base fields, for the exact reason you mentioned.
    My main issue currently is, as pointed out in the IS, the automatic creation of view modes, which with the help of this new setting can now be suppressed per entity type, making the config import on another instance much less painful.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    That's why I didn't work on removing any base fields, for the exact reason you mentioned.

    Well, this code

        return [
          'digital_signage' => $service->fieldDefinition(),
        ];
    

    is now only executed for all enabled entity types. And if that list changes due to a config change, an entity type could end up without that base field where it had it right before that change. And that would cause issues.

    That said, we need a static list of entity type for which the base fields get created. That list should never change. In other words, there should be 2 separate lists:

    1. all unsupported entity types: this is what have been the disabled entity types before
    2. all disabled entity types

    The unsupported entity types are of course also disabled entity types, but they can not be in the config list to disable or enable them, because they always need to remain unsupported.

  • Pipeline finished with Success
    7 months ago
    #51438
  • Status changed to Needs review 7 months ago
  • 🇩🇪Germany mrshowerman Munich

    Adressed feedback from #10

  • Assigned to jurgenhaas
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Sorry, I didn't get any notification about your latest commit and patch @mrshowerman. Only saw this by chance today and now assigned this issue to myself, hoping I get to the review soon.

  • Issue was unassigned.
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks again @mrshowerman for your work on this. The latest version of the MR looked great, and I've added the following things to it:

    • Rebased to the latest version of 2.5.x
    • Disabled the digital_signage field in entity forms of disabled entity types
    • Add a condition to the SQL query to create schedules to exclude disabled entity types. This is important, since otherwise some previously enabled entities could sneak into the schedule even though their entity type got disabled afterwards.
    • Fixed tests. This has been done such that the code will require Drupal 10.3 or later, so before merging this, we should create the 2.6.x branch and merge it there then.

    Please review these changes again.

  • 🇩🇪Germany mrshowerman Munich

    Thanks for improving the solution, @jurgenhaas. The changes look good to me!
    Not sure if this single feedback is enough to set the issue to RTBC, so leaving as NR.

  • Status changed to RTBC 28 days ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks @mrshowerman yes, that's good to go for RTBC then. I've just created the 2.6.x branch and will merge this improvement into that.

  • Pipeline finished with Skipped
    28 days ago
    #187019
  • Pipeline finished with Skipped
    28 days ago
    #187020
  • Status changed to Fixed 28 days ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This is now merged, and all tests are green.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024