I have a view with exposed filters which are ajax enabled. I also have a basic module set up with an event subscriber which picks out ajax responses from the particular view, based on this tutorial.

I'm now trying to include this JS as a library in my module, but

  1. can't figure out what to attach it to and...
  2. when I run that js in the console and then click on a filter, the div fades out nicely but then I get an error telling me that my method isn't a function (and it doesn't fade in the new content).

Here's my event subscriber / command alter 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 view is ours 
    if ($view->storage->id() != 'product_wall'){

    $commands = &$response->getCommands();

   * {@inheritdoc}
  public static function getSubscribedEvents() {
    return [KernelEvents::RESPONSE => [['onResponse']]];

 * Alter the views AJAX response commands
 * @param array $commands
protected function alterCommands(&$commands) {
  foreach ($commands as $delta => &$command) {
    if (isset($command['method']) && $command['method'] === 'replaceWith') {
      $command['method'] = 'fadeReplaceWith';


Do I need to do more to define my own ajax callback?

Is there no D8 equivalent for this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.