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
Comment #2
companyguy CreditAttribution: companyguy commentedComment #3
ziomizar CreditAttribution: ziomizar as a volunteer and at Station, East Atlantic Engineering commentedHi 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.
Comment #4
companyguy CreditAttribution: companyguy commentedThat was EXACTLY my problem ziomizar. Thank you so much.
Comment #5
companyguy CreditAttribution: companyguy commented