Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Follow-up from #2808337: Make use of proposed entity table relationship refactor to achieve the same end-goal via service decorators instead of taking over the entire class.
Depending on the core changes that may happen as a result of that issue, this may need to change course (eg, if core allows per-entity-type EFQ services, then this issue would be about adding the appropriate alter hooks needed).
Comments
Comment #2
jibranAfter #2808337: Make use of proposed entity table relationship refactor there is this fail in HEAD https://travis-ci.org/jibran/dynamic_entity_reference/jobs/186344732.
Comment #3
jibranNVM #2. Changing the core version fixed the tests https://travis-ci.org/jibran/dynamic_entity_reference/builds/188110987
Comment #4
jhedstromThis moves the logic from the service provider class to a decorator. I added some documentation notes too for future understanding :)
Comment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedShould these inject the "inner" service from the decoration? Then instead of extending the concrete version, you can call $this->decorated->function();
Comment #6
jhedstromI started to go that way, but realized we still don't need to define any methods on our classes, as the namespace detection is still done by the core query factory. Creating a class that didn't extend that one seemed like overkill in this instance, since all method calls would just go back to the core one.
I wonder if we need to be more explicit about ensuring the DER namespaces are picked up here?
Comment #7
jibran@jhedstrom what are the benefits of this patch? How can it help other contrib modules/drupal projects who are overriding the EFQ service as well?
Comment #8
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI don't know what cores namespace detection does, so I might be missing some context. Jibran asked for a review of this, so this is my current grokking of the issue.
You would need the original service as a property of the new service and you would need to implement the interfaces directly, instead of extending a base class to achieve #7. This part of the issue summary is incorrect:
The before and after implementations both take over the whole class in pretty much the same way. This is the only functional difference between the two implementations:
Previously if another module had taken over the service, replacing it would be skipped in DER. I don't believe using "decorates" has that same semantic, because it's for implementations that build on each other by design. So I think the summary of the current changes is:
If using the
Tables
class is very important, then I suppose there isn't much choice than to ignore other versions of the class in the container. At that point it's either "they are broken or we are".This new implementation does open the door to use an actual decorator however, which would be the best of both worlds, provided the other implementations of the factory were actual compatible with the kind of alterations DER is making. Additionally it assumes the other implementation isn't there only for the
Tables
class either.So I think the old way is fine, the new way is fine too. Even better would be finding an alternative implementation that doesn't require the
Tables
class to change.All of this might be a consequence of some interesting design choices with regards to magically loading the table class from the same namespace, but I have no alternative suggestions.
Comment #9
jibranThe only side effect would be that you'll end up joining int column to sting column which is not a total disaster so I think the current implementation is fine. If we'll see some issue down the road then we can revisit this and reconsider our approach.
Also, by looking at the current patch it is not a BC break at all so I don't think this is a stable blocker anymore. The only issue left is #2915512: Entity query doesn't allow relationship specifier for base entity fields but DER can't fix it we have to fix it in core.
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNote that this won't work as expected, we still need to use
pgsql
as a prefix for the service name (instead of a suffix like in the current patch) and add thebackend_overridable
tag to the main service (dynamic_entity_reference.entity.query.sql
).See the patch from #2940446: Decorate core's entity query services instead of replacing them and fix PgSQL support for a working implementation :)
Comment #11
jibranNow that workspace is in the core we should fix this. This how workspace is overriding the EFQ service with decorator.
We can increase DER
decoration_priority
to make it work with workspace.We also have to fix #10. Thank you @amateescu for pointing it out.
Comment #12
jhedstromI've fixed #10 and added decoration priority.
Comment #14
jhedstromComment #15
jhedstromIt'd be great to get this in and release an RC or stable so that #2678756: Allow config entities to be flagged can be committed to the Flag module. It's been some time :)
Comment #16
jibranI added #3090365: Add tests to make sure DER can work together with workspaces.
I added following remianing step over there
I think if we were to able to do this then we can mark is as a won't fix.