Score:0

Reuse $view->result after getting field values row by row

br flag

Inside a hook_views_pre_render(ViewExecutable $view): When I try to get and use field values from $view->result, I could no more use the $view->result just after and the execution is interrupted with no explicit errors displayed. For example:

function custom_divers_views_pre_render(ViewExecutable $view) {
  if ($view->id() == 'localisation_front' && $view->current_display == 'block_1') {
        
    // This code is well executed.
    \Drupal::logger('custom_divers')->notice(print_r($view->result, TRUE));

    foreach ($view->result as $result) {
      // Getting this value works.
      $type_value =  $result->_entity->type->getValue()[0]['target_id'];
      \Drupal::logger('custom_divers')->notice("type_value: ".$type_value);
    }

    // But this code is no more executed.
    \Drupal::logger('custom_divers')->notice(print_r($view->result, TRUE));     
  }
}
berliner avatar
bd flag
Is this the full code?
ostry.sn avatar
br flag
no it is an extract
berliner avatar
bd flag
Please post the full code. What you have posted shouldn't create the problem that you describe, so the issue must be elsewhere.
ostry.sn avatar
br flag
ok full code added
berliner avatar
bd flag
Anything in the server/php logs?
ostry.sn avatar
br flag
Ok I found in apache logs "Allowed memory size of 671088640 bytes exhausted" for the second \Drupal::logger call
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.