class VLMEventSubscriber in Views Load More 8
Same name and namespace in other branches
- 2.x src/EventSubscriber/VLMEventSubscriber.php \Drupal\views_load_more\EventSubscriber\VLMEventSubscriber
Hierarchy
- class \Drupal\views_load_more\EventSubscriber\VLMEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of VLMEventSubscriber
1 string reference to 'VLMEventSubscriber'
1 service uses VLMEventSubscriber
File
- src/
EventSubscriber/ VLMEventSubscriber.php, line 16 - Contains \Drupal\views_load_more\EventSubscriber\VLMEventSubscriber
Namespace
Drupal\views_load_more\EventSubscriberView source
class VLMEventSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = array(
'onResponse',
0,
);
return $events;
}
/**
* Filter a views AJAX response when the Load More pager is set. Remove the
* scrollTop commane and add in a viewsLoadMoreAppend AJAX command.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
*/
public function onResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
if ($response instanceof ViewAjaxResponse) {
$view = $response
->getView();
$pagerPlugin = $view
->getPager();
if ($pagerPlugin
->getPluginId() == 'load_more') {
$commands =& $response
->getCommands();
foreach ($commands as $key => $command) {
// Remove 'viewsScrollTop' command, as this behavior is unnecessary.
if ($command['command'] == 'viewsScrollTop') {
unset($commands[$key]);
}
else {
if ($command['command'] == 'insert' && $command['selector'] == '.view-dom-id-' . $view->dom_id) {
$stylePlugin = $view
->getStyle();
// Take the data attribute, which is the content of the view,
// otherwise discard the insert command for the view, we're
// replacing it with a VLMAppendCommand
$content = $commands[$key]['data'];
$cmd_options = array(
'wrapper_selector' => $commands[$key]['selector'],
// Changes to the content and pager selectors, if any required by
// theme.
'content_selector' => $pagerPlugin->options['advanced']['content_selector'],
'pager_selector' => $pagerPlugin->options['advanced']['pager_selector'],
// Animation effects
'effect' => $pagerPlugin->options['effects']['type'],
'speed' => $pagerPlugin->options['effects']['speed'],
);
unset($commands[$key]);
// Special case for lists and tables
if ($stylePlugin
->getPluginId() == 'html_list' && in_array($stylePlugin->options['type'], array(
'ul',
'ol',
))) {
if (empty($stylePlugin->options['wrapper_class'])) {
$cmd_options['target_list'] = "> {$stylePlugin->options['type']}:not(.links)";
}
else {
$wrapper_classes = explode(' ', $stylePlugin->options['wrapper_class']);
$wrapper_classes = implode('.', $wrapper_classes);
$cmd_options['target_list'] = ".{$wrapper_classes} > {$stylePlugin->options['type']}:not(.links)";
}
}
else {
if ($stylePlugin
->getPluginId() == 'table') {
$cmd_options['target_list'] = '.views-table tbody';
}
}
$response
->addCommand(new VLMAppendCommand($content, array_filter($cmd_options)));
}
}
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
VLMEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
VLMEventSubscriber:: |
public | function | Filter a views AJAX response when the Load More pager is set. Remove the scrollTop commane and add in a viewsLoadMoreAppend AJAX command. |