Commit 118abbcc authored by catch's avatar catch

Issue #2399195 by mondrake: Views setting 'Use Ajax' doesn't work

parent 007eaf35
......@@ -35,6 +35,13 @@ protected function setUp() {
public function testAjaxView() {
$this->drupalGet('test_ajax_view');
$drupal_settings = $this->getDrupalSettings();
$this->assertTrue(isset($drupal_settings['views']['ajax_path']), 'The Ajax callback path is set in drupalSettings.');
$this->assertEqual(count($drupal_settings['views']['ajaxViews']), 1);
$view_entry = array_keys($drupal_settings['views']['ajaxViews'])[0];
$this->assertEqual($drupal_settings['views']['ajaxViews'][$view_entry]['view_name'], 'test_ajax_view', 'The view\'s ajaxViews array entry has the correct \'view_name\' key.');
$this->assertEqual($drupal_settings['views']['ajaxViews'][$view_entry]['view_display_id'], 'page_1', 'The view\'s ajaxViews array entry has the correct \'view_display_id\' key.');
$data = array();
$data['view_name'] = 'test_ajax_view';
$data['view_display_id'] = 'test_ajax_view';
......
......@@ -56,20 +56,18 @@ function views_views_pre_render($view) {
// If using AJAX, send identifying data about this view.
if ($view->ajaxEnabled() && empty($view->is_attachment) && empty($view->live_preview)) {
$view->element['#attached']['drupalSettings']['views'] = array(
'views' => array(
'ajax_path' => \Drupal::url('views.ajax'),
'ajaxViews' => array(
'views_dom_id:' . $view->dom_id => array(
'view_name' => $view->storage->id(),
'view_display_id' => $view->current_display,
'view_args' => String::checkPlain(implode('/', $view->args)),
'view_path' => String::checkPlain(Url::fromRoute('<current>')->toString()),
'view_base_path' => $view->getPath(),
'view_dom_id' => $view->dom_id,
// To fit multiple views on a page, the programmer may have
// overridden the display's pager_element.
'pager_element' => isset($view->pager) ? $view->pager->getPagerId() : 0,
),
'ajax_path' => \Drupal::url('views.ajax'),
'ajaxViews' => array(
'views_dom_id:' . $view->dom_id => array(
'view_name' => $view->storage->id(),
'view_display_id' => $view->current_display,
'view_args' => String::checkPlain(implode('/', $view->args)),
'view_path' => String::checkPlain(Url::fromRoute('<current>')->toString()),
'view_base_path' => $view->getPath(),
'view_dom_id' => $view->dom_id,
// To fit multiple views on a page, the programmer may have
// overridden the display's pager_element.
'pager_element' => isset($view->pager) ? $view->pager->getPagerId() : 0,
),
),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment