Problem/Motivation

There are a few issues that would be helped if webform used views instead of hard-coded tables. This would also give site builders that opportunity to fine-tune these tables, and module developers and opportunity to change them as well.

Proposed resolution

Replace all the tables in webform with either straight views or with views that are built and altered.

  1. Submissions table. I suspect this can be a straight view, perhaps with some extra handlers for the operators.
  2. Results table. This is going to be harder. Perhaps start with a copy of a given view, ask each component to add its column(s).
  3. Analysis tables. For each component, start with a copy of the analysis for that component, ask each component to modify it. Probably will require views_crosstab or views_pivottable, or similar functionality built into webform. Difficult. Deferred.
  4. Other tables. E-mail settings for each webform? TBD?

If there isn't already a views_alter (haven't checked), we should use one to give module developers an opportunity to change the view.

Remaining tasks

Define each table and how it will be implemented.

Implement and test.

User interface changes

There will be inevitable UI differences. TBD.

API changes

Additional API functions are expected to be needed. Upward compatible with 7.x-4.0.

Be sure the clear the cache after applying this patch. You may need to clear it a second time for the default views to be discovered.

My plan is to split this patch into two. The first will add the views enhancements. The second will implement the option to use the views in lieu of the hard-coded tables, and provide an update routine and admin to pick which method to use.

I am marking this "Needs review" not because I think it is complete, but because I would like comments from anyone who has been wanting features that can now be added by modifying the views.

Comments

danchadwick’s picture

In a related issue, RedEight said (of the Results / Table):

If we implement this in views, should we add a new _webform_view_component hook for views displays? Or would we modify the reports page to entirely use views? Both?

I haven't looked at it closely enough to be specific, but I think each component should be called in turn to add it's fields to the view. The reports/ table would use views exclusively (the way I am envisioning this).

redeight’s picture

I had a conversation with a gentleman in IRC yesterday regarding Webform. He was trying to hide columns in the reports and was struggling to find a way. I've seen this issue crop up a number of other places as well and have wondered how to do this myself. To this end, we should probably address how columns are enabled/disabled. My first thought was to add a setting to components that enabled/disabled their fields in the result views tables.. Perhaps one per view? Then, before handing off to the individual components, we check if that component is enabled for that table.

This would also give us a convenient way of allowing a component to tell Webform it implements a certain results table. The component just enables the feature in hook_webform_component_info().

danchadwick’s picture

I'm not very keen on adding an additional setting to every component to control whether it is shown in the results table. I was more thinking of an alter function allowing developers to program this to their needs (which may well depend upon role and other factors).

We also need to take care with backward compatibility. Unless we defer this to weform -5.0, which I don't want to, we need to allow existing components to have their column. Therefore we need to be careful about how any additional fields in the component info table is created and used.

If this data were in the info table, then it would be used. And in its absence, whatever field webform uses today would be added.

I'm not sure we want to control the columns in views. This would mean that possibly a different view would be needed for every webform.

I was more thinking of something like HOOK_webform_results_view_alter(). But I have not given this deep thought.

redeight’s picture

To move this issue forward, I've started attempting to replicate the existing result tables with views.

The next comment will contain what I have so far.

At the moment this is mostly a proof of concept. The submissions view is pretty the same as the current submissions table. I had much more difficulty with the 'table' display. For the table display, I was only been able to get the first 4 columns: #, Submitted, User, and IP Address. The current views integration seems a bit flawed when handling submission data.

Right now, the 'Webform submission data: Value' field requires that you enter a node ID or title of the webform node. This would be fine if the contextual filter token replacement worked. Unfortunately the field does not accept %1 or !1 as input. Hard coding the nid or title lets me select the component to output and then it displays as it would if the user were to view the entire submission. Obviously this isn't the table display as defined in the documentation so it wouldn't be backwards compatible. I know DanChadwick mentioned we should hand off to the modules themselves. I suggest that we add views fields for submission data displays, 1 for each component display defined in the documentation. That would allow full backwards compatibility with older components and webforms as well as provide a starting point for components to offer more dynamic results.

PS: Not entirely sure how we will go about getting analysis up and working. Download could possibly be improved with views but I have major difficulties understanding the current documentation regarding the csv hooks and I'm not sure how we could make these backwards compatible with existing 4.0 components. Clear can obviously remain the same as it isn't even a display.

redeight’s picture

StatusFileSize
new11.11 KB
danchadwick’s picture

Update: I've been working on the results table. I have an implementation that uses a combination of an initial view, some enhanced handlers, and some code that modifies the view for the webform's components and pager.

I suspect that the analysis is beyond the scope of what we can do with views.

This would constitute an API change because of the theme functions would no longer be used. I am thinking that we need to deprecate the existing hard-coded tables and theme functions. An update function would set webform to use the deprecated functions but new installations would use views.

I plan to more forward, taking advantage of the work that RedEight did on the submission table.

danchadwick’s picture

Assigned: Unassigned » danchadwick
Category: Task » Feature request

FOR DISCUSSION:

I am thinking that I need to make a "legacy.tables.inc" and a "views.tables.inc" that each implement the same functions and include whichever one is selected via an admin form. If there is ever a 7.x-5.x, the legacy functions would be removed. New installations get views; existing sites get legacy via an update function.

I think If people have themed or used hook_menu_alter to modify the tables, their changes won't work with the new views implementation.

danchadwick’s picture

Issue summary: View changes
danchadwick’s picture

Issue summary: View changes
danchadwick’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new48.28 KB

This path is for testing and comment only. It is not complete and should not be used for production.

Views support enhancements:

  1. A views area result handler has been added that can mimic webform's items-per-page controls. It also can supply tokens from the first row of the results.
  2. A new expanding field which expands to create a field (and column, if placed in a views table) for every component.
  3. Ability to use the webform node id as a filter, sort, and argument.
  4. Ability to use the webform submission user id as an filter and be included as a field.
  5. Enhanced view, edit, and delete links, including the ability to display the serial number/ is_draft status, proper access checking, and click-sorting (useful when displaying the serial #)

Actual views

  1. A webform_submissions view that can replace the existing submissions table (SUBMISSIONS tab).
  2. A webform_results view that can replace the existing results table (TABLE tab).

API enhancements

  1. When a view is expanded to show all the components, hook_webform_view_alter provides modules an opportunity to modify its additions to the view.
  2. Components can now implement _webform_view_field_COMPONENT to modify the fields that are added for that type of component.
  3. Views support has been upgraded from views 2 to views 3.

Status: Needs review » Needs work

The last submitted patch, 10: webform-views_tables-2330557-10.patch, failed testing.

danchadwick’s picture

Status: Needs work » Needs review
StatusFileSize
new48.29 KB

Bad API example.

danchadwick’s picture

StatusFileSize
new50.48 KB

Again, another patch for comment. This patch:

  1. Fixes an issue with clearing the cache and loading the default views.
  2. Fixes the items-per-page links
  3. Allows site builders to customize which view definition is used, by node id or node type. For example, a view with a machine name of 'webform_results_123' would be used when node nid == 123 is having its data report viewed.
  4. Loads the webform-admin js and css files, the only part of which is actually needed is to bold the current number of items-per-page. I am sorely-tempted to just surround it with bold html tags. I bet no one customizes the appearance of the current number of items in the reports.
  5. The new views-based reports are used unless the variable 'webform_table' is set to a truthy value. I decided that if you want the old deprecated behavior, you'll have to ask for it, even if you upgrade. We will need an application / upgrade note for this.

Comments would be very helpful.

danchadwick’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Status: Needs review » Needs work
StatusFileSize
new51.57 KB

Committed to 7.x-4.x. This patch does not apply cleanly to 8.x, at least in part due to a webform.info hunk.

danchadwick’s picture

Assigned: danchadwick » fenstrat
danchadwick’s picture

Status: Needs work » Patch (to be ported)

  • DanChadwick committed 10190cb on 7.x-4.x
    Issue #2330557 by DanChadwick: Added Replace hard-coded tables with...

  • fenstrat committed 8bbfabe on 8.x-4.x
    Issue #2330557 by DanChadwick: Added Replace hard-coded tables with...
fenstrat’s picture

Status: Patch (to be ported) » Fixed

Committed and pushed to 8.x-4.x.

Just needed the webform.info hunk removed as the registry in D8 doesn't exist so no need to explicitly list files.

Thanks @DanChadwick nice work here. Now that the work to get these listing pages in views has been done I think it makes sense to drop the backwards compatible non views versions for D8.

danchadwick’s picture

... it makes sense to drop the backwards compatible non views versions for D8.

Absolutely!

Status: Fixed » Closed (fixed)

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