Problem/Motivation

It would be awesome to be able to use the ajax features Views has built-in with the Views Content display (Context aka ctools_context).

Proposed resolution

The attached patch adds the content type configuration to the views ajax settings (potential security issue?) and uses hook_views_ajax_data_alter() to replace the default ajax commands by views content specific ones.
To make the output of the current Views content content type plugins usable for the ajax handling of views I needed to wrap the output in the same css classes as used in views/theme/views-view.tpl.php. The wrapping is also used to set the Views content specific settings as mentioned above.
Since each rendered content type gets an unique identifier the approach should also work if you place e.g. the pager multiple times on the same page.
First tests look very promising.

Remaining tasks

Reviews needed & security audit needed - I don't like the fact that I had to expose the content type configuration in the JS (Drupal.settings.views.ajaxViews) and I think it could have security implications. Better ideas very welcome :)

User interface changes

None

API changes

None

Views: #2035657: More flexible / defensive ajax handling.
Views Load More: #2035687: Integration with (Ctools) Views Content

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

das-peter’s picture

Issue summary: View changes

Added related issue.

das-peter’s picture

Just found an issue with the current patch. Fixed that.

das-peter’s picture

Issue summary: View changes

Added another related issue.

dawehner’s picture

+++ b/views_content/views_content.moduleundefined
@@ -281,3 +281,158 @@ function _views_content_get_context_from_display($view, $id, $parent, $required
+function views_content_set_views_ajax_settings($context, $sub_type, $conf = NULL, $html_id = NULL) {

I would really like to come up with a generic solution which sets some values on the view object and transports them via the ajax requests. We need this 100% for drupal 8 as well.

dawehner’s picture

Issue summary: View changes

Typos.

Status: Needs review » Needs work

The last submitted patch, 1: ctools-views_content-support-views-ajax-2035643-1.patch, failed testing.

mrjmd’s picture

Status: Needs work » Needs review
FileSize
12.11 KB

Here's a straight re-roll to keep things moving.

das-peter’s picture

Thanks for the re-roll!

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 4 year old patch in #5 does not apply to the latest ctools 7.x-1.x-dev and if still applicable needs to be rerolled.

Checking patch views_content/plugins/content_types/views_attachments.inc...
Checking patch views_content/plugins/content_types/views_empty.inc...
Checking patch views_content/plugins/content_types/views_feed.inc...
Checking patch views_content/plugins/content_types/views_header.inc...
Checking patch views_content/plugins/content_types/views_pager.inc...
Checking patch views_content/plugins/content_types/views_row.inc...
Checking patch views_content/plugins/views/views_content.views.inc...
Checking patch views_content/plugins/views/views_content_plugin_display_ctools_context.inc...
error: while searching for:
   * Render this display.
   */
  function render() {
    if (!empty($this->previewing)) {
      return theme($this->theme_functions(), array('view' => $this->view));
    }
    else {
      // We want to process the view like we're theming it, but not actually
      // use the template part. Therefore we run through all the preprocess
      // functions which will populate the variables array.
      $hooks = theme_get_registry();
      $info = $hooks[$this->definition['theme']];
      if (!empty($info['file'])) {

error: patch failed: views_content/plugins/views/views_content_plugin_display_ctools_context.inc:61
error: views_content/plugins/views/views_content_plugin_display_ctools_context.inc: patch does not apply
Checking patch views_content/views_content.module...