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.
Problem/Motivation
Can we get a followup to add some document about lazy services to core.api.php - specifically the section on defining services in @defgroup container Services and Dependency Injection Container. Thanks
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#29 | reroll_diff_16-29.txt | 939 bytes | sahil.goyal |
#29 | 2514582-29.patch | 608 bytes | sahil.goyal |
| |||
#16 | interdiff.txt | 702 bytes | Mile23 |
#16 | 2514582_16.patch | 652 bytes | Mile23 |
#14 | 2514582_13.patch | 632 bytes | Mile23 |
Issue fork drupal-2514582
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
Comment #1
Fabianx CreditAttribution: Fabianx as a volunteer commentedComment #2
Wim LeersOne IS template is sufficient :P
Comment #3
jhodgdonOK, what are they? Is there a drupal.org page explaining them?
Comment #4
Fabianx CreditAttribution: Fabianx as a volunteer commentedThis chat should help:
On a high level overview.
Comment #5
jhodgdonOK, so far, so good.
So what would a developer need to know about these? How do you create a lazy-loaded service proxy?
Comment #6
Fabianx CreditAttribution: Fabianx as a volunteer commentedA developer will need to add "lazy: true" to their service definition in [module].services.yml and then would call e.g.:
./core/scripts/generate-proxy.sh 'Drupal\Core\Batch\BatchStorage' core/lib/Drupal/Core
etc.
Comment #7
jhodgdonHm... Well this still isn't clear to me.
I do not see addUsage() in Core... and what is this generate-proxy.sh thing?
Comment #8
Fabianx CreditAttribution: Fabianx as a volunteer commentedI was too lazy to type it all out:
./core/scripts/generate-proxy.sh 'Drupal\Core\Batch\BatchStorage' core/lib/Drupal/Core
will generate a proxy for the BatchStorage class.
./core/scripts/generate-proxy.sh 'Drupal\block\BlockRepository' core/modules/block/src
will generate a proxy for the BlockRepository class.
./core/scripts/generate-proxy.sh 'Drupal\mymodule\MyClass\' modules/contrib/mymodule/src
will generate a proxy for the custom MyClass class.
So it is always:
FullyQualifiedClassName Root-of-the-Namespace, e.g. for modules the 'src' directory.
Comment #9
jhodgdonThis script does not exist. I see generate-proxy-class.php so I guess that is what you mean? That PHP file is awful -- it has no usage docs at all and some of the in-code comments are totally wrong like the line that says it's generating a database dump. Is there some plan to fix it up?
Comment #10
Fabianx CreditAttribution: Fabianx as a volunteer commented#9 Yes, that script.
Sorry :/
There are usage docs to what the Application provided via addUsage(), I am not sure how to add more.
Yes, the database script copy might have slipped through.
However on the plus side if you forget to run the script ( mark any service with lazy: true in core/config.services.yml or in any modules module.services.yml) and rebuild the drupal cache (drush cr) you will get very clear instructions how to run the script.
Comment #11
jhodgdonRE #10 - That generate-proxy.php file:
a) Has no @file block at the top
b) As far as I can see, has zero relevant/correct comments in it except the one line that says "// Bootstrap."
So. It really could use a @file block telling at least what it does and how to use it, and at least a fix to that comment that implies it is running a database dump command.
Let's make that part of this issue of "documenting lazy services"?
Anyway... Do you want to make a first pass at writing this documentation? I am still a bit at a loss. I was not able to run this script on my slightly outdated local test site to see what it would do, and I am pretty busy right now with other stuff so I do not have time to write it. I don't think it's a Novice issue... so if you want this to get done we will need to find someone to write up this documentation.
Comment #12
Fabianx CreditAttribution: Fabianx as a volunteer commented#11: Sorry, busy with Criticals, too.
Would it be possible when you triage the queue, that you ping again in 2 weeks or so?
And I agree the doxygen of the script should be fixed in here.
Comment #13
jhodgdonMaybe assign it to yourself so it doesn't fall underneath your issue queue? The unresolved Docs issue queue runs to about 9 pages of 50 issues right now. This will get lost -- in two weeks it will be buried with all the other issues that got reported and never acted upon. The only ones that get fixed are the ones that get marked Novice, and this one ... I don't think it can be. Sorry.
Comment #14
Mile23This sort of thing is why we need core integration of symfony/console. :-)
Comment #15
jhodgdonThanks! That is a good start at the @file block for the script. A few thoughts:
Should probably say to do this from your Drupal root directory. And apparently also that you have to run it from an installed Drupal code base, because when I tried running this in my "commit stuff to Core" git repo (which is not connected to an installed site), I got an exception.
The namespace in this line needs to start with \
At a minimum, when the topic is written, both this file and that class should probably have @ingroup services in them.
Comment #16
Mile23Yah, it was a patch to get the conversation rolling. I'm not sure if this script is useful only for generating lazy services, or whether it has other uses.
#15.1: Added 'from your installed Drupal root...' Also, getting an exception instead of a help screen would be a bug if we had the console integration in place.
#15.2,3: I included the @see because it's reasonably readable code that shows you what's going on. It's probably not the best documentation effort. I'll just remove it. Also there's no @defgroup services but there is a @defgroup container, so I've added that. I'm not sure if it goes in @file, or if it should have its own docblock.
Still need a how-to writeup in core.api.php.
Comment #17
jhodgdonLooks good! Setting back to Needs Work since the topic has not yet been written.
Comment #29
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedtried with the latest patch as it not getting applied so, Rerolling the patch for the drupal version 9.4.x and attaching the Reroll_Diff along with that,
Comment #30
nod_Comment #31
nod_Patch applies to 10.1.x as well.
I'd RTBC but from #17: "Looks good! Setting back to Needs Work since the topic has not yet been written." I do not know what that means.
Comment #32
joachim CreditAttribution: joachim as a volunteer commentedI filed a duplicate of this. On my issue I wrote that documentation should say:
- why a particular class needs to be proxied
- where the list of classes that get proxied is defined
- what triggers the proxy class generation -- is it something a human must do when these classes are changed, or is it automatic?
Comment #33
joachim CreditAttribution: joachim as a volunteer commentedComment #34
joachim CreditAttribution: joachim as a volunteer commentedI'm reading the comments on this -- I'll try to write a docs topic based on them.
Comment #36
joachim CreditAttribution: joachim as a volunteer commentedComment #37
smustgrave CreditAttribution: smustgrave at Mobomo commentedRandom failure appears to be random ckeditor5 one. So LGTM
Not sure what topic either? Unless this needs a help_topic template but that wasn't around 7 years ago.
Comment #38
joachim CreditAttribution: joachim as a volunteer commented> Looks good! Setting back to Needs Work since the topic has not yet been written.
I assume this means the topic I've added to core.api.php with a @defgroup -- that's a documentation topic.
Comment #40
catchCommitted/pushed to 10.1.x and cherry-picked back through 9.5.x, thanks!