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.
In the same way that you can get information about Entities and Fields I think that we should create a page that show all the available services on a site.
I'm suggesting that we put this information on the /devel/service/info
path, and use Drupal::service("kernel")->getCachedContainerDefinition()
to retrive the available services and individual information about them.
Comment | File | Size | Author |
---|---|---|---|
#39 | interdiff.txt | 5.1 KB | willzyx |
#39 | add_container_info_page-2828116-39.patch | 23.29 KB | willzyx |
| |||
#33 | service_info_page-2828116-33.patch | 22.76 KB | willzyx |
| |||
#32 | service_detail.jpg | 59.05 KB | willzyx |
#32 | service_list.jpg | 90.59 KB | willzyx |
Comments
Comment #2
lussolucaWebprofiler (submodule of devel) already has a widget that show all the services defined, isn't enough?
Comment #3
tlyngej CreditAttribution: tlyngej at Annertech commentedNope! :-)
I really think that this should be available, in a basic format as the Entity and Field information are, in the Devel module itself.
Comment #4
lussolucaOk, just a couple of quick fixes:
kernel service should be injected
Can we use single quotes here?
Then we should wait for Moshe and willzyx to approve this.
Comment #5
tlyngej CreditAttribution: tlyngej at Annertech commented@lussoluca
How do you say one can access those informations from the Webprofiler?
Comment #6
tlyngej CreditAttribution: tlyngej at Annertech commentedI didn't inject the kernel service because the rest of the module was calling calling the static
\Drupal::service()
. The service is properly injected now.The double quotes was just me being a lazy lad, copying code. Fixed now.
Comment #7
tlyngej CreditAttribution: tlyngej at Annertech commentedBloody hell! I had some unwanted changes in that earlier patch.
This should not involve changes in
webprofiler/src/DataCollector/TimeDataCollector.php
:-)Comment #8
tlyngej CreditAttribution: tlyngej at Annertech commentedForgot to rename a variable.
Comment #9
lussolucaWhy your patch finds 608 services (on my test site) and Webprofiler 615?
Comment #10
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commented@tlyngej: I love it! Some feedback on your patch:
$container_definition['services']
) and not the entire$container_definition
? There is some useful stuff in the$container_definition['parameters']
for example.@lussoluca - a comparison with the web profiler widget:
devel/service/info
automatically inserts into the Development menu block, the Druplicon menu provided byadmin_toolbar_tools
module, and the toolbox menu near the start of web profiler.devel/service/info
identifies the factory method and arguments for a service.Comment #11
tlyngej CreditAttribution: tlyngej at Annertech commentedExcellent question!
Let's compare the webprofiler code with mine.
Comment #12
tlyngej CreditAttribution: tlyngej at Annertech commentedSnap! Looks like @andrewmacpherson beaten me to it :-)
@andrewmacpherson
I guess
$container_definition['parameters']
would be useful as well. But I better put parameters and services in different UI containers, that can be expanded. So that the page doesn't looks so scary.Excellent idea ordering by service name! I'll look into that.
Comment #13
tlyngej CreditAttribution: tlyngej at Annertech commentedThis patch includes both parameters and services, wrapped up in collapsible fieldsets.
Both sorted by array key.
Comment #14
lussolucaWebprofiler also shows private services. I should print this information somewhere so developers know that those services cannot be used directly (#2828361: Add more information to services widget).
Comment #15
willzyx CreditAttribution: willzyx commented@tlyngej thanks for contributing!
I'm ok with the changes but IMHO the issue needs some work
can we use short array syntax?
we can inject
devel.dumper
service and use$this->dumper->exportAsRenderable($var)
instead of manually create the render array and usekpr()
also (not blocking and to be explored) we could think to show the services/parameters in a table with js quick filter for a simpler and better UX.. If we do this what kind of info we will loose?
Comment #16
willzyx CreditAttribution: willzyx commentedComment #17
tlyngej CreditAttribution: tlyngej at Annertech commented@willzyx
Sounds to me like you are pointing out a more general issue.
I agree that having all of the pages existing in one controller is about to get out of hand, but that's how it currently works. This is not what the issue is about.
I also agree that using shorthand arrays would be preferred, but again, that's not used in the rest of the file.
So I merely followed the existing protocol and did what others have done before me.
Comment #18
tlyngej CreditAttribution: tlyngej at Annertech commentedGah, submitted comment to soon. :-)
So in my opinion, this feature is done, ready for a review. What you are suggesting requires a lot more work, and a dedicated issue.
Comment #19
willzyx CreditAttribution: willzyx commentedand I have reviewed it :)
Have all the methods in a single controller looks very wrong to me and since we choose to gradually split DevelController for a better organization and for consistency (see #2792227: Move entity debug methods to a dedicated controller) we should stop to polluting DevelController with the methods for all the functionalities.
if we add NEW functionalities they should be maintainable and with test coverage!
Since we are adding a new functionality I do not see why not do the things properly :)
If you need help with the suggested changes I'm glad to help you
Comment #20
tlyngej CreditAttribution: tlyngej at Annertech commented@willzyx
Gotcha! New patch coming right up.
Comment #21
tlyngej CreditAttribution: tlyngej at Annertech commentedHere we go!
In it's own controller, injecting
devel.dumper
, and with a test.I didn't know of
DevelDumperManager::exportAsRenderable
before you mentioned it. Nifty stuff!I'm a big fan of the idea of having some JS magic to make the info more digestable. But that's a bit more than I can handle right now.
Comment #22
tlyngej CreditAttribution: tlyngej at Annertech commentedLet's try uploading the patch, shall we?
Comment #23
tlyngej CreditAttribution: tlyngej at Annertech commentedFixing some Coding Standard issues
Comment #24
tlyngej CreditAttribution: tlyngej at Annertech commentedAnd decided to rename the test class, prefixing it with
Devel
, as the rest of the tests.Comment #25
willzyx CreditAttribution: willzyx commentedA lot better :)
a quick review
we need to use interfaces for the DI not the concrete classes
since some of devel plugins already wrap the output in a detail element (see DoctrineDebug and DrupalVariable) when you use ::exportAsRenderable() not sure if it is the best solution..
probably we need to expand a bit the test coverage
Good job @tlyngej
Comment #26
tlyngej CreditAttribution: tlyngej at Annertech commented@willzyx
DevelControllerInterface
)or is there one already that I haven't found?
Comment #27
willzyx CreditAttribution: willzyx commentedno absolutely..
this should be changed to use the interfaces. In this way the ServiceInfoController is not coupled with concrete services implementation and the injected services can be swapped without problems
DrupalKernel
=>DrupalKernelInterface
DevelDumperManager
=>DevelDumperManagerInteface
Try to set DrupalVariable or DoctrineDebug plugin as default dumper and visit the service info page
there are two nested detail elements because some of devel plugins already wrap the output in a detail element (see DoctrineDebug and DrupalVariable) when you use ::exportAsRenderable()
probably we can test that the dump of what we expect is present on the page
Also I think that we can display also the aliases retrieved by the cached container definition (
$container_definitions['aliases']
) in addition to services and parametersComment #28
tlyngej CreditAttribution: tlyngej at Annertech commenteddetails
element around the arrays. I can not assume that the var dumper will provide one. Kint and Symfony VarDumper doesn'tComment #30
tlyngej CreditAttribution: tlyngej at Annertech commentedBug fix.
Comment #31
tlyngej CreditAttribution: tlyngej at Annertech commentedComment #32
willzyx CreditAttribution: willzyx commentedsorry for the delay.. @tlyngej good job!
Testing dumper output on the web pages is always tricky.. I'm open to expand the test coverage in another issue
In the attached patch I'm exploring another solution.. Show services and parameters in a table with on-fly search instead of dumping the informations. IMHO this can make the informations more readable and the on-fly search make easy to find a specific service (by id class or alias)
Clicking on the Devel operation button the user will be redirected to a page that show the service comuted definition and instacee detail
What do you think?
Comment #33
willzyx CreditAttribution: willzyx commentedoops.. and here the patch :P (with test coverage)
Comment #35
willzyx CreditAttribution: willzyx commentedComment #36
tlyngej CreditAttribution: tlyngej at Annertech commented@willzyx
I haven't tested (or even read the patch) but based on description and the screenshots, I really like it.
Dividing the services, parameters and aliases into different tabs gives the developer a much cleaner interface.
The believe that the search thingy will prove very useful. Good job on that one!
Comment #37
willzyx CreditAttribution: willzyx commentedI am considering to commit the patch in the coming days.. there is someone who wants to review/test it?
Comment #38
willzyx CreditAttribution: willzyx commentedComment #39
willzyx CreditAttribution: willzyx commentedminor changes in tests
Comment #41
willzyx CreditAttribution: willzyx commentedCommitted and pushed to 8.x. Thanks to all and especially to @tlyngej :)