You are here

public function AjaxResponseSubscriber::onResponse in Views Infinite Scroll 8

Renders the ajax commands right before preparing the result.

Parameters

\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The response event, which contains the possible AjaxResponse object.

File

src/EventSubscriber/AjaxResponseSubscriber.php, line 41

Class

AjaxResponseSubscriber
Response subscriber to handle AJAX responses.

Namespace

Drupal\views_infinite_scroll\EventSubscriber

Code

public function onResponse(FilterResponseEvent $event) {
  $response = $event
    ->getResponse();

  // Only alter views ajax responses.
  if (!$response instanceof ViewAjaxResponse) {
    return;
  }
  $view = $response
    ->getView();

  // Only alter commands if the user has selected our pager and it attempting
  // to move beyond page 0.
  if ($view
    ->getPager()
    ->getPluginId() !== 'infinite_scroll' || $event
    ->getRequest()->query
    ->get('page') == 0) {

    // When the current page is 0 it might be the case that there where no
    // additional items in this case we want to still append the empty result.
    return;
  }
  $commands =& $response
    ->getCommands();
  $this
    ->alterPaginationCommands($commands);
}