You are here

function views_php_views_pre_render in Views PHP 8

Same name and namespace in other branches
  1. 6 views_php.module \views_php_views_pre_render()

Implements hook_views_pre_render().

File

./views_php.module, line 188
Allows to use PHP in views.

Code

function views_php_views_pre_render(ViewExecutable $view) {
  if (!empty($view->views_php)) {
    foreach (array(
      /*'argument',*/
      'field',
      'filter',
      'sort',
    ) as $type) {
      foreach ($view->{$type} as $id => $handler) {
        if (is_callable(array(
          $handler,
          'phpPreRender',
        ))) {
          $handler
            ->phpPreRender();
        }
      }
    }
    $view->pager->total_items = count($view->result);
    $view->pager
      ->updatePageInfo();
    $item_per_page = $view->pager
      ->getItemsPerPage();
    if ($item_per_page > 0) {
      $offset = $view->pager
        ->getCurrentPage() * $item_per_page + $view->pager
        ->getOffset();
      $view->result = array_slice($view->result, $offset, $item_per_page);
    }
  }
}