I am working on a module called webform_tracking (soon to be released) which adds some analytics to webfom submissions. We store our data in an extra table, linked by the submission id, but as far as I see there is no way to add additional data to the result displays or the csv export in webform.
I tried to implement it as an extra component, but I need access to the sid to find the right data, and i don't seem to have that inside a component implementation.
Beside that, i think a hook to manipulate the result table and csv export would be a useful feature in general.
I saw that there's drupal_alter to alter the csv export of specific components in 7.x-4.x, but nothing to add extra data or manipulate the whole dataset. A patch with a proof-of-concept implementation which fits my requirements is attached. What do you think?
Summary
- Inserts a new hook: hook_webform_results_extra_data().
Todo
- Is there a way of implementing this without a new hook?
- Needs documentation in webform.api.php
| Comment | File | Size | Author |
|---|---|---|---|
| #57 | 2117285-submission-results-table-57.patch | 10.17 KB | torotil |
| #10 | webform-2117285-10.patch | 8.62 KB | ParisLiakos |
Comments
Comment #0.0
phaer commentedtried to clarify the title
Comment #1
torotil commentedFixed a typo in the original patch.
Comment #2
quicksketchI'd prefer to avoid adding any new hooks for this functionality.
We definitely can't be putting hook invocations inside of theme functions.
Comment #3
torotil commentedDo you have any specific solution in mind?
I don't know where else the data for this functionality should come from (in a pluggable way). Currently there is nothing like "some additional data for webform-results without adding components". IMHO providing such an interface is usually done by creating a hook (at least in Drupal). But either way either it means redifining an existing interface or it means creating a new one.
The invocation can easily be moved to webform_results_table() and passed to the the theme-function as parameter.
Comment #4
torotil commentedHere is a patch without hook-invocations in the theme function. I guess I won't work on documenting this new hook until we have agreed on an approach.
Comment #5
torotil commentedComment #6
ParisLiakos commentedi need this too, but i use the 4.x version. shouldnt this go to 4.x and then backported?
Comment #7
ParisLiakos commentedhere is a patch for 4.x
Comment #8
ParisLiakos commentedand lets make webform_results_get_extra_data() only return data for submission requested ;)
Comment #9
ParisLiakos commentedsorry, here is the interdiff
Comment #10
ParisLiakos commentedand final patch for today..fix some header bugs
Comment #11
liam morlandRelated: #1830370: Hook to add additional submission information in downloads
Comment #12
quicksketchThere is already a hook for hook_webform_submission_load($submissions), that could be used to extend current $submission objects. However, there isn't any way to actually do anything with the extra data that's been collected. Rather than introducing a new hook that loads data in a different way, I think it would be better to use the existing hook for loading data directly into the $submission objects.
This does have a lot of overlap with #1830370: Hook to add additional submission information in downloads, which basically makes what you need possible for CSV downloads, but not for the table view.
Comment #13
torotil commented@quicksketch: The interesting part of the request is "without adding actual components". So why do I think hook_webform_submission_load() wouldn't work for that?
Comment #14
quicksketchYou can now do this for CSVs, because of the new hooks add in #1830370: Hook to add additional submission information in downloads.
You could also add information in certain other places, such as the submission display and analytics display, because those areas have similar alters you can use. However, there isn't an alter hook for the table display.
Essentially I think what we have here is specific hooks for individual things. The patches in this issue added more general hooks that could be used in a number of different places. I'm not sure one approach is necessarily better than the other, but I'm leaning towards keeping down the path we're on, where there is only one loading mechanism and then each individual interface or display must be individually altered to include additional information if needed.
Comment #15
torotil commentedSounds nice! Until I can migrate to 7.x-4.x I'll have to stick to this patches here though.
Comment #16
torotil commentedI've just started to port Webform tracking to webform-7.x-4.x. Sadly the proposed solution is highly unscalable. The hook is called once per property for each submission. I guess I'll make a patch for that.
The proposed patch also adds the additional data to the results table (not only CSV exports). This functionality is still lacking in 7.x-4.x.
Comment #17
torotil commentedHere is the patch that makes hook_webform_results_download_submission_information_data() called only once per submission.
Comment #18
ParisLiakos commentedoh, thanks for this patch, i never got the time to roll it myself
Comment #19
torotil commented#17 just improved the given hooks. I've still had to extend the submission information hooks to also work with the webform results table. As there is some API changes involved I really would like to get quicksketch involved.
Here is a patch that extends hook_webform_results_download_submission_information_*() to also work for the results table. This one works on top of #17!
Comment #20
torotil commentedComment #21
torotil commentedOn top of that I would even suggest to make the components use the very same framework too. This would remove the corresponding code from theme-functions completely.
Comment #24
torotil commentedHere is a combined patch for #16 and #19.
Comment #25
torotil commentedHere is a backport for 7.x-3.x. Note that it only works if the patch for #1327186: Use BatchAPI to Export very large data sets to CSV/Excel is applied first. We'll use and maintain those patches until we've finally migrated to 7.x-4.x with campaignion.
Comment #26
Chipie commentedDo you have an idea for including the additional submission data also in the table view?
Comment #27
liam morlandComment #28
danchadwick commentedArgh. While I only briefly looked at this, it seems clear that #25 introduces a substantial API change. I don't see how we can consider this for 7.x-4.x, and I don't really foresee a 7.x-5.x branch, since I suspect that a year from now all our efforts will be put into the D8 port.
Also, regarding the results table, the plan is to use views for this, even though it will require creating a dynamic view to contain the component columns.
With regret, I am going to close, but I'd be happy to reconsider some API change that is in addition to the current hooks, rather than instead of them, and one that limits itself to the download. I wish we had made these changes prior to 7.x-4.0. :(
Comment #29
Chipie commentedUsing views for the result table would be great. Do you have an idea how to add additional data to the results table in the meantime?
Comment #30
torotil commentedDepends on what you call substantial. #24 is the patch that was actually proposed #25 is only the backport for webform 7.x-3.x. IMHO The only backwards incompatible API change is the removal of
theme_webform_results_table_header. The other changes only extend hooks by making additional data available for them.We did. The patch has been ready months before 7.x-4.0.
Good luck with that. Until then (I suppose it will be years from now) there are the patches in this issue.
Comment #31
danchadwick commentedAlas the patches were never RTBC, and with something like 400 open issues at the time, I was unaware of them. This isn't your fault, torotil, and neither is it mine. It is the fault of the community of 400,000+ websites that benefit from thousands of hours of volunteer time and don't contribute anything back to the issue queue. /soapbox
7.x-3.x is only receiving critical bug fixes, and I hope to not have any more -3.x releases, absent someone else takes over maintainership of that branch. I also would not want to widen the API gap between 3.x and 4.x.
If you want to put this forward, the work on hard-coded tables -> views sure needs help.
@Chipie -- You can build a view for each webform (assuming you only have a small number of them), using the existing views integration. Views can retrieve submission results.
Comment #32
torotil commentedTrue, true. Having pretty much all my work on webform being overlooked until it's too late and then having it postponed until 8.x-x.x … really makes me want to fork webform sometimes. -- Except that I don't have the time for that at the moment. Then again: All the patches that I have to maintain this way actually constitute something like a fork with the downside of not using proper version control.
Comment #33
danchadwick commentedLet's work together on 7.x-4.x. As I understand it, this issue helps with performance, but is this a deal-breaker for you? Maybe there is a way to extend the API to be forward compatible?
I too have all-but-given up on posting patches for certain projects -- drupal 7 core in particular -- since I know they will be ignored. I have been going through the old backlog of issues and trying to give at least a yes-let's-do-it or sorry-no decision on each one. There are still 250 open issues. And all the time I spend managing the queue is time I'm not writing, reviewing, or committing patches. :(
Comment #34
Chipie commented@Dan -- Thank you for you solution, but I'm looking for a generic approach, because the webforms are created by the user and we don't want to create an custom view for each webform. I will take a look at the theme function for the table.
Comment #35
danchadwick commented@Chipie -- I am close to having the Results Table in views. This would be one view which configures itself for the webform, whose nid is passed as an argument to the view. This may help you out. See the related issue.
Comment #36
torotil commentedI've taken another look at #24 and I think I could also implement it without hook-changes - by defining two additional hooks:
hook_webform_submission_information_info()andhook_webform_submission_information_data().Keeping
theme_webform_results_table_header()would need some hack. All themes implementing this function would also redefine (and override) the original submission information.This will take some time though.
Yes it is.
Comment #37
danchadwick commentedI'm planning on deprecating the existing submission table (the one without the data) and results table (the one with the data). I'd rather see you work with the views-based replacements, which probably won't require any extra hooks.
Would it help you if I posted a preliminary patch for comment? So far I have:
1) A results header that mimics the items-per-page controls that webform uses.
2) Expanding a single data column that represents all the components into multiple columns at view display time.
2.5) Drupal alter of view after modification. Allows someone to add more than one column per component.
3) A serial number (with "(draft)") link to view the submission.
4) Click-sorting the the data columns by raw value (string)
5) Update Views support from version 2 to version 3
Left to do:
1) Click-sorting by a cast of the field for number components
2) Click-sorting on the first question in a grid.
3) NOT click-sorting components for which it doesn't make sense
4) Allow selection of views and legacy tables
Maybe:
1) Revise the classes to conform as closely as possible to existing classes. Markup will still be views-ish.
The component expansion was accomplished with hook_views_pre_view. I would have preferred to use a display_extender, but it doesn't get run early enough. I did wanted to modify the view definition, rather than clone parts of an already-constructed view.
Because this will just be a default view, you can modify it as you see fit. This also lays the ground for someone using a Views Bulk Operations view for the submissions or results. This could then be used for things like bulk-resending of e-mails, setting a "Mark as Read" component, and so forth.
Comment #38
torotil commented@DanChadwik - I really need some solution for this in webform 7.x-X.x. Will the views based results and download happen only for D8 or for D7 too?
Comment #39
torotil commentedHere is may first stab at a backwards-compatible patch.
Comment #40
danchadwick commentedThis is 7.x-4.x. I'm not actively working on 8.x. :)
Comment #41
danchadwick commentedChanging to duplicate. Please carry on further discussion in the related hard-coded tables issue.
Comment #42
torotil commentedHere is an updated patch that works with #21 from #1327186: Use BatchAPI to Export very large data sets to CSV/Excel.
Comment #43
torotil commentedFix a notice caused by the patch.
Comment #44
torotil commentedAnother re-roll of the patch in #39 for 7.x-4.x . I still need this until webform_tracking is migrated to the views-based output.
Comment #45
torotil commentedRe-rolled the wrong patch. This is a re-roll of #24. #39 was only a proof-of-concept.
Comment #46
stephenrobinson commentedYou can mess with tables like this, in this example I move a few columns to the start
Comment #47
torotil commentedYeah. I still need this. - re-roll to 4.15.
Comment #48
torotil commented… and re-roll against 7.x-4.x.
Comment #49
torotil commentedRe-roll.
Comment #50
liam morlandSee #41; please use that issue or make a new one.
Comment #51
torotil commentedI have several contrib modules that depend on this patch. Until they are modified (which wasn’t a priority so far) I’m maintaining this fork. This has nothing to do with #41 or any other issue. Only with the fact that years after this patches were posted here a worse solution was merged into 7.x-4.x while this issue went unnoticed. Leaving me in the current situation. cheers ;)
Comment #52
liam morlandIf there is a better solution, I would like to get that in. It needs to happen in a new focused issue.
Comment #53
torotil commentedI finally had time to split parts of this into a backwards compatible API extension: #3086038: Extend submission information handling.
Comment #54
torotil commentedRe-roll against 7.x-4.x. Sorry, still stuck with this patch.
Comment #55
torotil commentedI’m finally able to migrate to module versions of webform_tracking and webform_paymethod_select that work without this patch — or more with more performance with the patch from #3086038: Extend submission information handling.
The only part of this patch that is not also in #3086038 is the change that makes the results table (non-views) be based on the hooks as well. I’m posting the remaining changes here as patch for being used on top of #3086308 in case anyone else is interested in these changes.
Comment #56
torotil commentedAnother tiny update to the patch: Make use of the new
hook_webform_results_download_submission_information_data_row()and its performance improvements.Comment #57
torotil commented… and another update.