After creating a view and setting 'Use Ajax' to 'Yes', links are not loaded via Ajax. - They still cause a page refresh.

It looks like this is due to an array nesting issue when preparing drupalSettings in views.module, introduced by #2382557: Change JS settings into a separate asset type.

Beta phase evaluation

tr>

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because views ajax is broken
Issue priority Critical because it affects a lot of users.
Disruption Not disruptive, because it doesn't change an API, it just fixes the bug.

Comments

mondrake’s picture

Status: Active » Needs review
StatusFileSize
new703 bytes

Patch.

dawehner’s picture

Oh wow.

Thank you for the patch, do you mind writing some kind of test for it?
You could expand \Drupal\views\Tests\ViewAjaxTest
to check whether the required drupalSetting is available after the drupalGet() call?

mondrake’s picture

StatusFileSize
new1.15 KB
new1.83 KB

Ok, here with some tests over the returning drupalSettings as per #2.

berdir’s picture

+++ b/core/modules/views/views.module
@@ -55,7 +55,7 @@ function views_help($route_name, RouteMatchInterface $route_match) {
-    $view->element['#attached']['drupalSettings']['views'] = array(
+    $view->element['#attached']['drupalSettings'] = array(
       'views' => array(
         'ajax_path' => \Drupal::url('views.ajax'),
         'ajaxViews' => array(

Wondering if the fix should be the other way round, even if the patch is going to be a bit more complicated.

This replaces the whole drupalSettings array and prevents anyone from adding something there. I guess that is not likely to happen but we had real bugs related to code like this in the past.

The last submitted patch, 3: 23399195-views_ajax-3-test-only.patch, failed testing.

mondrake’s picture

StatusFileSize
new2.03 KB
new3.05 KB

Changes as per #4.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks great for me now!

dawehner’s picture

Issue summary: View changes

  • catch committed 118abbc on 8.0.x
    Issue #2399195 by mondrake: Views setting 'Use Ajax' doesn't work
    
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.