You are here

protected function AjaxResponseSubscriber::alterPaginationCommands in Views Infinite Scroll 8

Alter the views AJAX response commands only for the infinite pager.

Parameters

array $commands: An array of commands to alter.

1 call to AjaxResponseSubscriber::alterPaginationCommands()
AjaxResponseSubscriber::onResponse in src/EventSubscriber/AjaxResponseSubscriber.php
Renders the ajax commands right before preparing the result.

File

src/EventSubscriber/AjaxResponseSubscriber.php, line 21

Class

AjaxResponseSubscriber
Response subscriber to handle AJAX responses.

Namespace

Drupal\views_infinite_scroll\EventSubscriber

Code

protected function alterPaginationCommands(array &$commands) {
  foreach ($commands as $delta => &$command) {

    // Substitute the 'replace' method with our custom jQuery method which
    // will allow views content to be injected one after the other.
    if (isset($command['method']) && $command['method'] === 'replaceWith') {
      $command['method'] = 'infiniteScrollInsertView';
    }

    // Stop the view from scrolling to the top of the page.
    if ($command['command'] === 'viewsScrollTop') {
      unset($commands[$delta]);
    }
  }
}