Score:0

in hook_views_pre_render, how to get the current display of the ViewExecutable

ca flag

I have this code:

function my_module_views_pre_render(\Drupal\views\ViewExecutable $view) {
  if (isset($view) && $view->storage->id() == 'myview') {
    // Do something.
  }
}

This runs my code for all displays of my view, hoever, if I have page_1 and page_2 displays, and I only want to pre-render page_2, I can't figure it out:

I am looking for something like this:

function my_module_views_pre_render(\Drupal\views\ViewExecutable $view) {
  if (isset($view) && $view->storage->id() == 'myview' && $view->getDisplayId() == 'page_2') {
    // This does not work
    // Do something.
  }
}
Score:0
cn flag

It's just $view->current_display === 'page_2' that you're looking for. Also, in my experience, you don't need "storage" to get the view id; you can just use $view->id()

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.