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.
- Submissions table. I suspect this can be a straight view, perhaps with some extra handlers for the operators.
- 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).
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.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.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | webform-replace_hard_coded-2330557-14.patch | 51.57 KB | danchadwick |
| #13 | webform-views_tables-2330557-12.patch | 50.48 KB | danchadwick |
| #5 | 2330557-5-initial_table_replacements.txt | 11.11 KB | redeight |
Comments
Comment #1
danchadwick commentedIn a related issue, RedEight said (of the Results / Table):
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).
Comment #2
redeight commentedI 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().
Comment #3
danchadwick commentedI'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.
Comment #4
redeight commentedTo 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.
Comment #5
redeight commentedComment #6
danchadwick commentedUpdate: 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.
Comment #7
danchadwick commentedFOR 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.
Comment #8
danchadwick commentedComment #9
danchadwick commentedComment #10
danchadwick commentedThis path is for testing and comment only. It is not complete and should not be used for production.
Views support enhancements:
Actual views
API enhancements
Comment #12
danchadwick commentedBad API example.
Comment #13
danchadwick commentedAgain, another patch for comment. This patch:
Comments would be very helpful.
Comment #14
danchadwick commentedCommitted to 7.x-4.x. This patch does not apply cleanly to 8.x, at least in part due to a webform.info hunk.
Comment #15
danchadwick commentedComment #16
danchadwick commentedComment #19
fenstratCommitted 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.
Comment #20
danchadwick commentedAbsolutely!