Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #3744 Prevent views using Quickstart Exposed Filters from scrolling when checkboxes are checked #3745

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/custom/az_finder/az_finder.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ services:
logger.channel.az_finder:
parent: logger.channel_base
arguments: ['az_finder']
az_finder.ajax_response_subscriber:
class: Drupal\az_finder\EventSubscriber\AZFinderAjaxResponseSubscriber
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Drupal\az_finder\EventSubscriber;

use Drupal\views\Ajax\ViewAjaxResponse;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* Modify AJAX responses for views using the Quickstart Exposed Filters plugin.
*/
class AZFinderAjaxResponseSubscriber implements EventSubscriberInterface {

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

/**
* Removes scrollTop AJAX commands for views with Quickstart Exposed Filters.
*
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* The event to process.
*/
public function onResponse(ResponseEvent $event) {
$response = $event->getResponse();

// Only modify commands if this is an AJAX response for a view using
// Quickstart Exposed Filters for the exposed form.
if ($response instanceof ViewAjaxResponse) {
$exposedForm = $response->getView()->display_handler->getOption('exposed_form');
if (is_array($exposedForm) && $exposedForm['type'] === 'az_better_exposed_filters') {
$commands = &$response->getCommands();
foreach ($commands as $key => $value) {
if ($value['command'] === 'scrollTop') {
unset($commands[$key]);
// Only one scrollTop command is expected.
return;
}
}
}
}
}

}