diff --git a/modules/facets_rest/src/Plugin/views/style/FacetsSerializer.php b/modules/facets_rest/src/Plugin/views/style/FacetsSerializer.php index da35dfe..81d4f28 100644 --- a/modules/facets_rest/src/Plugin/views/style/FacetsSerializer.php +++ b/modules/facets_rest/src/Plugin/views/style/FacetsSerializer.php @@ -58,6 +58,7 @@ class FacetsSerializer extends Serializer { protected function defineOptions() { $options = parent::defineOptions(); $options['show_facets'] = ['default' => TRUE]; + $options['display_pager_results'] = ['default' => FALSE]; return $options; } @@ -73,6 +74,13 @@ class FacetsSerializer extends Serializer { '#title' => $this->t('Show facets in the output'), '#default_value' => $this->options['show_facets'], ]; + + $form['display_pager_results'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Display pager and results'), + '#description' => $this->t('If check, pager and summary of results will be display in summary'), + '#default_value' => $this->options['display_pager_results'], + ]; } /** @@ -117,7 +125,30 @@ class FacetsSerializer extends Serializer { if (!$this->options['show_facets']) { $rows = $rows['search_results']; } + if (!$this->options['display_pager_results'] || empty($this->view->pager)) { + return $this->serializer->serialize($rows, $content_type, ['views_style_plugin' => $this]); + } + $pager = $this->view->pager; + $class = get_class($pager); + $current_page = $pager->getCurrentPage(); + $items_per_page = $pager->getItemsPerPage(); + $total_items = $pager->getTotalItems(); + $total_pages = 0; + if (!in_array($class, [ + 'Drupal\views\Plugin\views\pager\None', + 'Drupal\views\Plugin\views\pager\Some', + ])) { + $total_pages = $pager->getPagerTotal(); + } + + $rows['pager'] = [ + 'current_page' => $current_page, + 'total_items' => $total_items, + 'total_pages' => $total_pages, + 'items_per_page' => $items_per_page, + ]; return $this->serializer->serialize($rows, $content_type, ['views_style_plugin' => $this]); } } +