Problem/Motivation
If, on site A, a site builder:
- creates a webform
- creates a view based on this webform
- exports them to a feature module
- imports them to site B
the view is not likely to work out of the box on site B. Instead, the fields in the view will have to be re-linked
to the webform components as the IDs differ between the development and production environments.
This is not news nor is it an issue solely for webform but for any module that stores integer ID values in its views handlers. They simply are not portable across sites, environments, or what have you. This issue was noted in #2132187: Views submission data linked to a single webform, unnecessarily brittle which included a workaround
patch that has been committed.
Proposed resolution
How about we deal with the problem more directly? For better portability, replace the nid and cid values saved in the views handlers with the node title and the component key (called form_key
in schema). As noted in the above issue, this depends on the form_key
being unique like other machine name
columns. This uniqueness is not guaranteed by the current webform code, but can be enforced by the site builder. The latter condition makes the proposed solution viable and allows for creating a separate issue to address the uiniqueness of the form_key (or machine name as I believe it would be better to view it as).
Remaining tasks
Review and test (does a test need to be written?)
Add a hook_update_N routine to update the webform component fields in existing views.
User interface changes
None.
API changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 2412497-11-views-integration.patch | 24.78 KB | solotandem |
| #10 | 2412497-10-views-integration.patch | 24.75 KB | solotandem |
| #1 | 2412497-1-views-integration.patch | 15.05 KB | solotandem |
Comments
Comment #1
solotandem commentedAttached patch implements proposed resolution.
Comment #2
danchadwick commentedUnless I'm missing something, I think this ship has sailed for the -4.x branch. I don't see how we can convert to using the form_key as a machine key. I believe that they are (widely) not unique within the webform. I think that their path (including containing fieldsets within a given page).
There would be numerous benefits to using machine keys for webform nodes and for components, including simplified theming and import/export/features. There have also been requests to use UUIDs, which I think is related. I just don't see how we can make a fundamental change without affecting the many existing webforms, webform-related modules, and custom themes. That said, I definitely see a huge benefit. I wish this had been tackled in the 3.x->4.x development. But that effort took a couple of years, even without this change.
Move to the D8 branch??
Comment #3
solotandem commentedA comment in the the patch you created in the issue referenced above reads:
Reading that issue, it would seem your motivation was exactly what is proposed here but took an approach that can easily be categorized as a , as noted by quicksketch in his comments on the issue.
The proposed change does not affect webforms per se but only the views integration thereto, which may or may not be a significant difference (but that data is not available). I do not see this as a fundamental change that would negatively affect existing use. Again, an outstanding action item is to convert existing views. It is an unknown the extent of views integration in other modules that might possibly be affected by this change. It should be noted that the render steps proceed as normal with the existing nid and cid values. The form_key is only used up front for portability. So I would expect any compatability issues to be minimal. What am I missing?
Comment #4
danchadwick commentedYes, the motivation of my patch was to allow a view to run on a similar webform to the original. It prefers the cid, but when the nid is different, it tries to use the form_key.
Kludge is certainly a pejorative description of that functionality. I prefer to think of it as removing some of the brittleness in the original design.
I have sympathy for the need you describe, and I would certainly like to make views less brittle within an installation (different webforms) and when importing webforms or views from another database, such as you describe with features.
The problem is that our standard is not to make non-backward compatible changes to webform within a N.x version. Your patch changes functions which other modules may call. It changes the operation of the views handlers, creating incompatibilities with any developer who has subclassed them. It relies on the title of a webform as being unique, which it isn't guaranteed to be. It relies on form_keys to be unique, which they aren't.
In short, this is a great idea, and I would have been happy to include it (after testing) in webform 4.0. I don't anticipate a webform 7.x-5.0, so I'm suggesting we move this to the 8.x queue.
Comment #5
solotandem commentedThank you for taking time to respond thoughtfully to this issue.
I appreciate the desire not to make non-backward compatible changes. IMHO, the patch is "close" to that in that, other than the UI settings form, it runs as it does now, meaning it uses the nid and the cid in the other functions implemented by these handlers. So, for those modules that subclass any of the views handlers, I would expect little to no adverse affect.
It should be a trivial addition to the patch to work with a view that has not been updated and saved with the title and form_key values, thus providing a backward compatible change. Or, as suggested previously, adding a hook_update_N to convert existing views.
That said, clinging too hard to backwards compatibility as a design constraint leads to major issues as history will show. Core being one example of where it is not held sacred.
Can you tell me how many modules would be affected? I can't. Is this great unknown of what "other modules may call or rely on" the overriding factor to stymie what we both seem to agree is a step in the right direction of removing the "brittleness" of this code? In the release notes, can we not describe the change and what a module developer might need to look for? There are very few functions implemented by these handlers; I can't imagine it being that big of a deal.
You restate what I have already pointed out in this issue or comments in the patch, things like node title and form_key are expected to be unique though not currently guaranteed to be so. I would think it fairly reasonable for the node title to be unique among webform nodes (although what you described as your use case for the related issue may be an exception). Why would someone want duplicate titles? But the form_key should be just like a "field API" field because it supports best practices for configuration and deployment; and the site builder can guarantee its uniqueness. In any case the patch relies on the form_key as its primary goto and the node title as a fallback.
I would like to see this get into a 7.x release (as well as 8.x), but that is not my call of course. I don't see it as significant enought to warrant a new digit in the release like 7.x-5.x. If there are other considerations involved in this decision (other than what you have already expressed), I would be interested in understanding them.
Comment #6
danchadwick commentedWhether desirable or not, Drupal doesn't "cling to backwards compatibility" between major version (e.g. 7.x -> 8.x). The core maintainers clearly freely make changes, even when they introduce incompatibility with relatively little reward (such as renaming functions or changing parameter orders).
Within a given Drupal version, 7.x in this case, we as module maintainer have a duty to maintain backward compatibility with major version numbers -- 7.x-4.x in this case. This means both functional and API / programming compatibility. Site maintainers need to be assured that they can install minor point updates without fear of their site breaking. This has been quicksketch's standard for the history of webform, and I believe is widely held standard in other contrib modules.
I do agree that the change you suggest is relatively minor, but it is not without risks to the updater. form_key's are very frequently not unique because people use the same form_key within different fieldsets (e.g. name, street, city, state, phone -- both home and work) and between different pages. I don't think this is a good design, and I would like to change it too. But we simply cannot within the 7.x-4.x branch.
Your patch changes webform_component_list. I believe this list makes its way into the node as $node->webform['components']. This is the sort of general purpose routine that another module author (possibly a custom, non-contrib module) might use. I do not think it is safe to change what it returns. I myself rely on this in my custom module.
Unless you can accomplish what you want in a fully backward compatible manner, I don't see this moving forward. "Fully" means that no site that works properly with the current 7.x-4.x branch would break after the patch. I also would not want to use node title as a key. Using the UUID module, if installed, might be a work-around.
We are on the same side on the technical merits. But pragmatically, with lots of sites still using 7.x-3.x -- and lots of webform-related modules stuck in -3.x land, I don't see 7.x-5.x happening anytime soon.
Comment #7
solotandem commentedMy change to webform_component_list() was not intended to have this side effect. I was too focused on the task at hand and failed to check all the calls to this function. Thanks for that feedback. I will retool the patch with the guidelines you have set forth.
Comment #8
danchadwick commentedI hope I didn't mislead you, as the change to webform_component_list is but one of the incompatibilities, right?
Comment #9
chris burge commentedThis issue proposes to solve an issue I've run into on a couple of projects.
On my current project, I'm capturing all configuration with Features, including a Webform submissions view. The site will host a number of registration forms. Each will be different, but they will all have a set of common components: first_name, last_name, email, etc. Because the site is deployed with Features, there is no source node; thus, I need to be able to key off of form_key and not a combination of nid/cid.
It sounds like @solotandem is going to post a reworked patch. I'll wait to do any testing until that patch has been posted.
@solotandem, thanks for tackling this issue. @DanChadwick, thanks for responding to this issue so quickly. Too often we never hear back from a module's maintainer.
Comment #10
solotandem commentedFor forward portability, the attached patch:
For backward compatability, the attached patch:
Comment #12
solotandem commentedRerolled for latest commits.
Comment #14
solotandem commentedTests need to updated for the new column on webform table. Defer this task until agreement on merits of patch.
Comment #15
danchadwick commented@solotandem -- thank you for your great work. I've glanced over the patch and I will find some time soon to apply it and look at it in detail and prepare some detailed comments. I'm very encouraged!
Ironically, I was thinking about this issue earlier when I was out walking and it occurred to me that we could use both the nid and a webform machine name, which seems to be the same solution you arrived at.
The webform machine name could also be used for theming. "webform_client_form_survey_alter()" is much nicer than "webform_client_form_123_alter()", right?
The same concept could be applied to the cid, creating a guaranteed-unique-within-the-webform component machine name, leaving the form_key for theming only. I'm not sure about this....
We also need to be mindful of scale. We need to handle (and update) sites with 10,000 to 100,000 webforms, with 100's of components per webform, with 1,000,000 components, with 1,000,000 to 10,000,000 submissions, etc.
And, of course, we need to be mindful of existing views that cannot be updated. Many of these will be in code. I didn't see anything in your patch to the contrary.
I would love to see others involved in the review of this feature and a patch of this magnitude. Again, thank you for taking this on.
Comment #16
danchadwick commentedAgain, thank you for your significant effort on this issue. Comments are in the order I saw/thought of them, not in any sort of priority order.
General
webform.install
webform.component.inc
webform.module
webform_hander_relationship_submission_data.inc
I didn't review the handlers closely because I think there's plenty to discuss and address. Phew. Time for coffee.
Comment #17
danchadwick commentedWork on D8 is accelerating. It's starting to be do-or-die for this issue in D7. Just sayin'. :)
Comment #18
chris burge commentedI think this issue totally has merit, but I would be in over my head if I tried to jump in. I created another issue that is narrower in scope that seeks to solve the issue of keying off the form_key. I'm not trying to derail this issue, but I needed to get something to production for a client, and now I'm sharing with the community for consideration.
#2506429: Provide Option to Key on 'form_key' in Webform Submission Views
Comment #19
danchadwick commentedClosing for lack of activity. Please do re-open if there is further progress on this patch.