3

I've used drupal 8 with devel module. I want to change some values dynamically in views fields. So i tried to use theme_preprocess_views_view_fields(). When i tried to print variables using print_r(), kint() & dump(), no one print values.

/**
 * Implement theme_preprocess_views_view_fields().
 */
function galip_preprocess_views_view_fields(&$variables) {
  $view = $variables['view'];
  print_r($variables['fields']);exit;
}

I've enabled debug mode true in services.yml file. But i can't get any variables. How can i get variables?

1
  • I think the problem is, that this hook never got executed. Not all views preprocess hooks work with all views configurations. Did you try to do something else in the hook and see if it runs? (and always clear the cache when implementing a hook)
    – 4uk4
    Dec 29, 2015 at 11:20

2 Answers 2

6

You should pass the object into the $variables array, and then in one of the Twig templates issue {{ dump(var) }}. Drupal might be using output buffering there, which would explain why you don't see any output when issuing those calls from the preprocess function.

7

Just include Kint debugger in your theme file:

require_once('modules/devel/kint/kint/Kint.class.php');

and use Kint like so:

Kint::dump( $_SERVER );
2
  • 1
    Just enable Kint module, no need to require_once.
    – Nikit
    May 15, 2018 at 2:40
  • 2
    I've found that for a page-level template_preprocess function I needed to do the above as well. Tried just ksm() but that just output in plain text and when I tried to use Kint::dump($variables) with Kint module enabled, it still said class Kint did not exist. Works with the require_once just before it though.
    – scotself
    Dec 6, 2018 at 6:11

Your Answer

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

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