3

I've attached a custom submit handler to node add/edit form for the article content type:

$form['actions']['publish']['#submit'][] = 'my_module_node_edit_submit';

In the handler, I am trying to inspect the form state values with kint (via the devel module):

kint($form_state->getValues());

Upon submission of the form, I'm able to briefly see the kint output on the screen, but I am also presented with this message:

Redirecting to http://localhost/example.com/node/123

The page then redirects back to view the node, and the kint output is gone. How can I preserve the kint output so it is available after the redirection?

4
  • may be you could disable the direction for a while
    – Shabir A.
    Commented Jan 8, 2016 at 17:56
  • 1
    Just to be clear, is it your own code that performs the redirection or is that something core/contrib is doing?
    – Clive
    Commented Jan 8, 2016 at 18:37
  • 1
    I think this is a devel setting that is enabled. Otherwise you would not see such message. Also xdebug a great tool to use for this.
    – user21641
    Commented Jan 8, 2016 at 19:43
  • @Clive, the redirection is done by core/kint (my submission handler does nothing but a kint output). If the kint command is removed, the redirection page is not shown. @Ivan Jaros, I looked at admin/config/development/devel but did not see any such settings, I shall go with xDebug. Commented Jan 8, 2016 at 22:53

2 Answers 2

10

Use ksm() instead of kint().

I ran into the same issue when I want to inspect the entity after saving, using drupal's hook_entity_presave and kint

I found this article on how to print variables using kint() which explains that ksm() prints the output inside the drupal page (not before as kint()) does.

So this example prints the entity without redirecting:

function mymodule_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
  ksm($entity->toArray());
}
0

That is the normal behavior of the submit function, to process the form and redirect. If you want to debug this without any tools, then do a var_dump() and then stop the php with die. But debugging without tools is of course not very productive. When you want to do serious work, use xdebug and an IDE of your choice.

Edit: Another way would be to use the message area, for example with drupal_set_message or dpm() from devel. This puts the debugging information in a session and you can see it after the redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.