- ๐บ๐ธUnited States chucksimply
#4 patch works for me on 10.1.1. This is a small but necessary option.
- last update
almost 2 years ago 29,804 pass - last update
over 1 year ago 30,341 pass - ๐ป๐ณVietnam mrddthi
That's cool, thanks @skyreddwang,
Tested on D9.5.8 /PHP 8.1/MariaDB 10.3 - last update
about 1 year ago 29,722 pass - ๐บ๐ฆUkraine bobi-mel
Hi @skyredwang
I applied the patch #4. Works well.
Thanks - Status changed to RTBC
7 months ago 11:57am 12 September 2024 - ๐บ๐ฆUkraine Znak
I think it's reviewed and tested by community, so I think we can change status of this issue
- Status changed to Needs work
7 months ago 3:08pm 12 September 2024 - ๐ฎ๐ณIndia Sahana _N
sahana _n โ made their first commit to this issueโs fork.
- ๐ฎ๐ณIndia Sahana _N
Hi
I tried to reproduce the issue issue is replaceable in 11. x.
And I created the MR for 11. x and tests are passed.
RTBC++
Please let me know if I missed anything happy to take suggestions.
- ๐บ๐ธUnited States smustgrave
Previously tagged for tests which are still needed.
Did not review.
- First commit to issue fork.
- ๐จ๐ฆCanada b_sharpe
Added unit test to prove new functionality.
Attaching patch simply for composer.
- ๐บ๐ธUnited States smustgrave
So I imagine with this config change we will need a schema update for the new setting.
Existing view config will have to probably be updated.
Also imagine there will have to be a post_update hook to set the new key for existing views (should be batch)
- ๐ฌ๐งUnited Kingdom oily Greater London
A unit test is in place. Test-only test fails as it should. Removing 'Needs tests' tag. If further test coverage is needed, please update.
- ๐บ๐ธUnited States Chris Burge
+1 for this addition to core. In the meantime, you can also accomplish this with an event subscriber:
namespace Drupal\my_module\EventSubscriber; use Drupal\views\Ajax\ViewAjaxResponse; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; /** * Change the scroll-to-top behavior for the my_view view. */ class AjaxResponseEventSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} * * @return array * The event names to listen for, and the methods that should be executed. */ public static function getSubscribedEvents() { return [ KernelEvents::RESPONSE => 'alterCommands', ]; } /** * React to ResponseEvent. * * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * Response event. */ public function alterCommands(ResponseEvent $event) { $response = $event->getResponse(); if ($response instanceof ViewAjaxResponse && $response->getView()->id() === 'my_view' ) { $commands = &$response->getCommands(); foreach($commands as $key => $command) { if ($command['command'] == 'scrollTop') { unset($commands[$key]); } } $commands = array_values($commands); } } }
In my case, I wanted to modify the selector to the views'
.view-content
class, which is only a minor change:$commands = &$response->getCommands(); foreach($commands as $key => $command) { if ($command['command'] == 'scrollTop') { - unset($commands[$key]); + $commands[$key]['selector'] = $command['selector'] . ' .view-content'; } } - $commands = array_values($commands); }
It'd be worthwhile to consider allowing a site builder to set the
scrollTop
selector instead of adding a toggle. It would meet my use case, which is necessitated by responsive design (where the exposed filters stack atop the content on mobile).