ksm() should show Kint output without wrapping the parameters in an $args array but instead showing the actual variable names ($native_languages in this example). Secondly, the backtrace should not include the call to ksm itself.
ksm($native_languages);
is nice and short but it wraps everything in the $args array which I don't want to see.
Calling Kint::dump like this shows directly the variable I want to see, including its name, but it's clumsy:
use Drupal\Core\Render\Markup;
drupal_set_message(Markup::create(@Kint::dump($native_languages)));
This helps a little but the variable name it always prints is "$variable", not the name I want:
function my_ksm($variable) {
drupal_set_message(Markup::create(@Kint::dump($variable)));
}
I understand that ksm() can take multiple arguments. I only want one.
Comment | File | Size | Author |
---|---|---|---|
#29 | devel.remove-unncessary-wrapping-2879341-29.patch | 1.88 KB | AdamPS |
| |||
#27 | devel-remove-unncessary-wrapping-2879341-27.patch | 2.43 KB | ELC |
|
Comments
Comment #2
kari.kaariainen CreditAttribution: kari.kaariainen commentedComment #3
AdamPS CreditAttribution: AdamPS commentedGreat idea. I think I figured out the solution. It does what you want and there is one extra benefit: the backtrace starts with the actual line of interest rather than always showing the function ksm.
Comment #4
AdamPS CreditAttribution: AdamPS commentedComment #5
AdamPS CreditAttribution: AdamPS commentedComment #6
kari.kaariainen CreditAttribution: kari.kaariainen commentedWorks brilliantly! I would perhaps call it ksm_single (same kind of idea as with the kint_lite). That would also avoid any confusion with the letter L.
Comment #7
AdamPS CreditAttribution: AdamPS commentedOK, I think I have a better version. Rather than creating a new function, I have fixed the existing ksm and kint. They should now produce identical output to calling Kint::dump directly for one or multiple parameters.
Comment #9
AdamPS CreditAttribution: AdamPS commentedComment #11
kari.kaariainen CreditAttribution: kari.kaariainen commentedThis works too!
Comment #12
AdamPS CreditAttribution: AdamPS commentedUnfortunately I can't understand the test failure. It doesn't really seem related to the change that I made.
Comment #14
jeffschulerThis is great. Thanks! The patch works for me.
I think this is what's going on with the testbot tests:
The Kint dumper's checkRequirements() function returns the output of kint_require().
The patch changes kint_require() to no longer return the output of require_once(), which would normally be 1. kint_require() will therefore implicitly return NULL.
checkRequirements() then fails and the Kint dumper is unavailable in the Devel settings.
When the test tries to change the dumper to Kint, it cannot, so the value is stuck at "drupal_variable", therefore failing the test.
Comment #15
nicolaj.knudsen@gmail.com CreditAttribution: nicolaj.knudsen@gmail.com commentedPatch works great, thank you so much!
It seems it even (partially?) fixes https://www.drupal.org/project/devel/issues/2643392 and https://www.drupal.org/project/devel/issues/2643338, since the first line of the callstack is now referring to the line where kint() is invoked.
Beautiful!
However something happened with the layout, the text is stretched in the grey line on the buttom with the trace information, but that is absolutely a minor side effect.
Comment #16
AdamPS CreditAttribution: AdamPS commented@jeffschuler thanks for the explanation - so I'll add a return statement and hopefully that fixes it
Comment #18
AnybodyVery nice idea! +1 for this, this will be very helpful.
The patch works for me in manual testing.
Comment #19
willzyx CreditAttribution: willzyx commentedI'm not sure that the new function is needed.. you can obtain the same result by set kint as default dumper and call
kpr()
. I'm missing something?Comment #20
AdamPS CreditAttribution: AdamPS commented@willzyx Thanks for your time.
I have now fixed the issue title which had got out of date. The patch does not add a new function but instead fixes ksm to display what it ought to.
Comment #21
AnybodyComment #22
AdamPS CreditAttribution: AdamPS commentedTest failure was a glitch, now working.
@willzyx
I agree that there are two functions that are mostly the same, and that's true either with or without the patch:
ksm()
kpr()
Both of them have the same bug - I have added a new screenshot from (2). Notice that it always says $input instead of the variable name and the function name in the backtrace is always Kint->export. That means that every dump looks the same until you open it, so it's hard to know which is the one that you want.
Patch #16 fixes the bug for (1). New patch #22 fixes it for both.
Comment #23
AdamPS CreditAttribution: AdamPS commentedSorry forgot the screenshot
Comment #24
AnybodyThank you. I didn't see the other problem indeed. RTBC by manual testing for us.
Comment #25
AdamPS CreditAttribution: AdamPS commentedThanks @Anybody. Please can you change the status to RTBC:-)
Comment #26
prinds CreditAttribution: prinds commentedpatch #22 works for me on drupal 8.5.6 and devel 8.x-1.2
a big improvement to the ksm() functionality..
Comment #27
ELC CreditAttribution: ELC as a volunteer commentedPatch re-rolled for commit #2931217-39: Replace calls to deprecated function drupal_set_message with calls to the messenger service so it will now patch 8.x-2.x without error. Patch is otherwise identical.
There are no apparent negative side effects of this and it makes the ksm output much easier to deal with, especially when using it multiple times.
Comment #28
AdamPS CreditAttribution: AdamPS commentedThanks @ELC. In fact the latest branch is now 8.x-3.x which includes a major change to remove the kint module and use composer to get the kint library. The patch needs some reworking because
kint()
is now a wrapper to\Drupal\devel\DevelDumperManager::dump()
. We need to pass through a flag to indicate that the $args should be printed separately and it will be a bit tricky to find the best way to pass this.There is a separate issue #2712489: Exclude internal functions from backtrace that handles the Kint::$aliases part of this patch so I think we should drop that part from this issue. Please could you take a look at that one and set it to RTBC?
Comment #29
AdamPS CreditAttribution: AdamPS commentedNew patch for 3.x
Comment #30
AnybodyThank you @AdamPS, works perfectly. I guess the 2.x branch will be deprecated and we don't want a backport?
Comment #31
AdamPS CreditAttribution: AdamPS commentedThanks
Yes that's right as far as I know
Comment #32
moshe weitzman CreditAttribution: moshe weitzman as a volunteer commentedSorry for the delay here.
Comment #34
AnybodyThank you very much moshe! Can we perhaps have a new stable release including this very helpful fix?