I'm trying to retrieve a variable in a view, but I receive an error when attempting to display it via kint. Here are the steps to reproduce:

1. Fresh Install of Drupal with devel and devel kint enabled
2. Create a new view of any content type.
3. In a theme's .theme, file write the following:
function THEMENAME_theme_suggestions_views_view_alter(&$suggestions, &$vars) {
kint($vars['view']['current_page']);
}

You should see a "website encountered an unexpected error" on the view page and in the recent log messages a "Error: Cannot use object of type Drupal\views\ViewExecutable as array" error.

Now, kint($vars['view']; works just fine. But when I try to retrieve any variable below ['view'], I get that error.

This is presumably a pretty simple task, but I can't tell if I just have my syntax wrong or I just don't understand how kint works, or this is actually a legit bug. Can someone give me a hand or point me in the right direction?

Comments

companyguy created an issue. See original summary.

companyguy’s picture

Issue summary: View changes
ziomizar’s picture

Category: Bug report » Support request

Hi companyguy,

The error you reported "Error: Cannot use object of type Drupal\views\ViewExecutable as array",
means that you can't access $vars['view']['current_page'] in this way but probably you you have to use $vars['view']->current_page as $vars['view'] is an object.

companyguy’s picture

That was EXACTLY my problem ziomizar. Thank you so much.

companyguy’s picture

Status: Active » Closed (works as designed)