You are here

views_ajax_get.module in Views Ajax Get 2.0.x

Same filename and directory in other branches
  1. 8 views_ajax_get.module
  2. 7 views_ajax_get.module

Allows Views ajax to work with GET instead of POST.

File

views_ajax_get.module
View source
<?php

/**
 * @file
 * Allows Views ajax to work with GET instead of POST.
 */
use Drupal\views\ViewExecutable;

/**
 * Implements hook_views_pre_render().
 *
 * Include the necessary JavaScript file if an Ajax view is embedded
 * on the page.
 */
function views_ajax_get_views_pre_render(ViewExecutable $view) {
  if (_views_ajax_get_is_ajax_get_view($view)) {
    $view->element['#attached']['library'][] = 'views_ajax_get/ajax_get';
    $view->element['#attached']['drupalSettings']['viewsAjaxGet'][$view
      ->id()] = $view
      ->id();
  }
}

/**
 * Determines whether the current view has ajax get enabled.
 *
 * @param \Drupal\views\ViewExecutable $view
 *   The view.
 *
 * @return bool
 */
function _views_ajax_get_is_ajax_get_view(ViewExecutable $view) {
  return $view->display_handler
    ->usesAJAX() && empty($view->is_attachment) && empty($view->live_preview) && !empty($view->display_handler
    ->getExtenders()['views_ajax_get']) && $view->display_handler
    ->getExtenders()['views_ajax_get']->options['ajax_get'];
}

Functions

Namesort descending Description
views_ajax_get_views_pre_render Implements hook_views_pre_render().
_views_ajax_get_is_ajax_get_view Determines whether the current view has ajax get enabled.