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.
Instead of directly using the SchemaMetatagManager directly in the code the service (that is already defined services.yml) should be used.
Comment | File | Size | Author |
---|---|---|---|
#27 | 2944823-27-schema-metatag-use-service.patch | 51.11 KB | KarenS |
| |||
#24 | 2944823-24-schema-metatag-use-service.patch | 69.18 KB | KarenS |
| |||
#22 | 2944823-22-schema-metatag-use-service.patch | 69.01 KB | KarenS |
#20 | 2944823-20-schema-metatag-use-service.patch | 65.55 KB | KarenS |
| |||
#18 | schema_metatag-use_service-2944823-13.patch | 45.2 KB | KarenS |
Comments
Comment #2
mgoedecke CreditAttribution: mgoedecke at One Pixel Ahead commented- change attribution
Comment #3
DamienMcKennaComment #4
mgoedecke CreditAttribution: mgoedecke at One Pixel Ahead commentedComment #5
KarenS CreditAttribution: KarenS at Lullabot commentedUnfortunately that means I can't use the same code for D7 and D8. I have been trying to avoid changes as much as possible. But this is obviously the better way to write the code.
Comment #6
mgoedecke CreditAttribution: mgoedecke at One Pixel Ahead commented@KarenS
Thanks for your response.
I understand, that you want to reuse as much code as possible for both versions.
On the other hand it makes clean code impossible without services when you are trying to extend / change some functionality in your own project.
E.g. we are currently in need of changing the json output and for that need to update parseJsonld. Using the service we can keep the schema_metatag module as is and in our own custom module we just overwrite the parseJsonld function.
Without services we would need to patch the schema_metatag module which is really "hacky" and is probably going to break when updating the module
Comment #7
KarenS CreditAttribution: KarenS at Lullabot commentedPatch no longer applies. Plus rather than calling the service repeatedly, it would make more sense to inject the service into SchemaNameBase and use a variable or method to invoke it. Then we could replicate that in D7 where the only difference between the versions would be the way the method or variable gets constructed.
I would appreciate a patch for both D7 and D8 that works that way.
Comment #8
KarenS CreditAttribution: KarenS at Lullabot commentedComment #9
IT-Cru@KarenS : I will try to re-factor this patch for D8. Any suggestions for the naming of this variable? Before I start to run over all classes :)
Comment #10
IT-CruI've refactored previous patch and it should now apply.
I'm not very happy with...
But perhaps this is a new starting point to integrate this patch in current code base.
Comment #12
IT-CruPatch from #10 breaks the node add/edit form. Please do not use it!
Comment #13
IT-CruFix broken patch from #10 (I have previously remove visibilitySelector in SchemaNameBase ...).
Comment #14
KarenS CreditAttribution: KarenS at Lullabot commentedIt would be better to add the service using dependency injection into SchemaNameBase, thne it will be available to use everywhere. That also lends itself to creating similar code in D7 that won't be much different than D8. D7 wouldn't use dependency injection but still make a common method available to all the other code.
Comment #15
KarenS CreditAttribution: KarenS at Lullabot commentedI see you did you dependency injection into SchemaNameBase, but none of the traits use it. I know you can't use dependency injection on traits, but we do know that everywhere the traits are used they are on some class that inherits from that class, so the method should actually work on the traits as well as the base classes.
Comment #16
DamienMcKennaAs a reminder, the "assigned" field is for indicating you're actively working on something, when you're done you should try to remember to set it back to "unassigned". Thank you.
Comment #17
KarenS CreditAttribution: KarenS at Lullabot commentedMy bad, this does use dependency injection, but we should use the Symfony\Component\DependencyInjection\ContainerInterface class as well, and remove unused use statements. This patch no longer applies, so starting over. Let's see if this passes tests.
Comment #18
KarenS CreditAttribution: KarenS at Lullabot commentedI fixed the fatal error in the code above and then ran into a series of additional problems. There are many many places where I am using static methods (creating each method as a stand-alone process that doesn't require the whole Drupal stack so I can test each method separately and quickly), and none of them work if this is switched to a service model (result in "Using $this when not in object context " errors). And changing those statics would require lots of changes to the architecture of the module. For posterity I am attaching the reworked patch, but I'm not going to commit it ATM.
Comment #20
KarenS CreditAttribution: KarenS at Lullabot commentedI found a way to make this work:
Comment #21
KarenS CreditAttribution: KarenS at Lullabot commentedThe big winner was the way to make sure traits could use the service, abstract methods are the solution.
Comment #22
KarenS CreditAttribution: KarenS at Lullabot commentedSome code cleanup.
Comment #24
KarenS CreditAttribution: KarenS at Lullabot commentedComment #26
KarenS CreditAttribution: KarenS at Lullabot commentedNow try to backport this...
Comment #27
KarenS CreditAttribution: KarenS at Lullabot commentedComment #29
KarenS CreditAttribution: KarenS at Lullabot commented