Problem/Motivation

Over in #2944308: Is it possible to set up some kind of workflow on form?, there was some discussion of webform workflows. Well, adding workflows_field and putting that field on a webform makes it so I have a workflow. Its simple. The only thing needed is to add field_permissions to hide it for certain roles and this patch here.

Without this patch, the field values aren't saved to any webform submission fields.

Proposed resolution

Land this patch.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

heddn created an issue. See original summary.

heddn’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.3 KB
heddn’s picture

Title: Allow fieldable webforms » Allow fieldable webform submissions

Let's be accurate in the title.

Status: Needs review » Needs work

The last submitted patch, 2: 3002547.patch, failed testing. View results

jrockowitz’s picture

This feels like a major change. I need to some time to wrap my head around this. Hopefully, people will help review this patch.

heddn’s picture

Agreed about major change :)

And it looks like we'd have a way to go to get it done properly, based on the number of test failures. But... its something to consider and it just works really nicely for workflows so it is so tempting.

jrockowitz’s picture

Maybe you can use hook_entity_type_alter() to enable field support in a custom module.

We would still have to update the WebformSubmissionForm to properly set the field values.

heddn’s picture

@jrockowitz for the fieldable UI, that's a pretty easy temporary hack against the webform submission entity. I hack it, add the fields, then remove it. No big deal to me.

For the webform submission form stuff, a patch in incoming. I'll remove the field_ui route stuff from it. As long as we get the form changes, I don't care that much about the field route.

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new4.11 KB

Here's this more properly looks for fields. But removes the field_ui base route annotation on the entity. If someone wants to add fields, they'll have to hack it.

jbrauer’s picture

StatusFileSize
new3.15 KB

Re-roll only

Status: Needs review » Needs work

The last submitted patch, 10: 3002547-10.patch, failed testing. View results

jbrauer’s picture

StatusFileSize
new3.07 KB

FIx re-roll

jbrauer’s picture

Status: Needs work » Needs review
StatusFileSize
new3 KB

Re-roll patch without extra character jumping in.

solide-echt’s picture

This is an interesting approach: combining workflow with webform makes for some very strong workflow automation. I'm trying to switch from a state_machine implementation for webforms to workflow. Could you shed some light as to how exactly the YAML structure should be for such a field? I have a workflow named 'review_workflow_submissions'. Inspected the config for a field with this workflow in a user object and tried the following:

review_workflow:
  '#type': workflows_field_item
  '#title': 'review workflow'
  '#settings':
    workflow: review_workflow_submissions

But this is not rendering...

justkristin’s picture

StatusFileSize
new2.7 KB

I love this idea, and I hope it does what I need! I did have problems getting the patch to apply - hunks 1 and 4 were failing, no doubt because my knowledge of patch isn't good enough to tell it to be a bit more wobbly in matching lines... I figured I would give creating a patch for my current install a try - my first patch uploaded here at all! Please tell me what I have pooched.

I am, for the record, running D8.7.5 with Webform 8.x-1.3 in the Pantheon environment.

Thank you to everyone with more brains than me! :)

justkristin’s picture

StatusFileSize
new2.7 KB

Sorry, all. Screwed up the filenames and paths. This should be better. :)

justkristin’s picture

That wasn't it either. I am stymied. Sorry!

liam morland’s picture

Re-roll.

@justkristin: It doesn't look like your patches were generated using Git. That is why they don't work. They could be applied using patch, but the automated system uses git apply.

mrweiner’s picture

Can anybody shed some light on how to actually attach the workflow field to a webform?

EDIT: Ah okay, so the first patch has the "field ui hack" that @heddn was referring to. That exposes a "manage fields" option under the "operations" links at /admin/structure/webform. Manually adding * field_ui_base_route = "entity.webform.edit_form", back in adds that "manage fields" option where the workflow field can be added to the webform entity.

That being said, I guess I'm a bit confused what the intended use of this patch is if one cannot actually add fields to the entity. In what situation would we need to check/save field values for a webform submission if an admin cannot add fields to the webform in the first place? Or maybe a better question is, why are we removing the field_ui stuff from the patch?

Also note that the permissions noted in the initial description are not included in these patches -- it's referring to the field permissions module.

mrweiner’s picture

Status: Needs review » Needs work

Setting to "needs work" per above edit

devkinetic’s picture

Version: 8.x-5.x-dev » 6.x-dev
StatusFileSize
new2.42 KB

I've re-rolled that patch against 6.x so work can continue on this.

EDIT: Not sure whats going on with the test suite.

mrweiner’s picture

@devkinetic your patch doesn't look to be in the right format. How'd you generate it? It includes the following which I don't think should be there, unless something has changed with the patch system with recent updates?

From 12868a8735d62159056bda734f5a5af709629bbf Mon Sep 17 00:00:00 2001
From: Ryan Hartman <ryan@commonplaces.com>
Date: Wed, 15 Jul 2020 17:26:40 -0400
Subject: [PATCH] Issue #3002547 by devkinetic: allow saving of webform
 submission form values

---
 src/WebformSubmissionForm.php | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
devkinetic’s picture

@mrweiner My file is a git am patch as outlined in the Advanced patch contributor guide Under step 6.4. That first link walks you through how to use this type of patch.

In my testing, this patch is working great in conjunction with the workflows_field module. Bravo!

mrweiner’s picture

Status: Needs work » Needs review
StatusFileSize
new3.07 KB

Patch wouldn't apply for me either. Re-rolling + adding check to make sure that fieldManager exists in copyFormValuesToEntity(), as we were sometimes hitting "Error: Call to a member function getBaseFieldDefinitions() on null in Drupal\webform\WebformSubmissionForm->copyFormValuesToEntity() (line 530 of /var/www/html/modules/contrib/webform/src/WebformSubmissionForm.php)."

devkinetic’s picture

@mrweiner I think your issue was my patch is for 6.x and your patch is for 5.x. #21 is for 6.x and #24 is for 5.x. I just tested again and both apply via composer-patches to their respective versions.

jrockowitz’s picture

I can see that this is not easy patch to write tests for but I would be okay with committing it. I would even be open to committing it to 8.x-5.x.

Can someone a roll an 8.x-5.x patch and I will handle the merge conflicts with 6.x?

jrockowitz’s picture

Version: 6.x-dev » 8.x-5.x-dev

Switching version to 8.x-5.x

jrockowitz’s picture

StatusFileSize
new3.68 KB

Minor tweaks to the patch. If all the test pass, I will commit it.

jrockowitz’s picture

StatusFileSize
new4.27 KB

  • jrockowitz authored 1e5f4b9 on 8.x-5.x
    Issue #3002547 by jbrauer, heddn, jrockowitz, justkristin, mrweiner,...

  • jrockowitz authored 1e5f4b9 on 6.x
    Issue #3002547 by jbrauer, heddn, jrockowitz, justkristin, mrweiner,...
jrockowitz’s picture

Status: Needs review » Fixed
mrweiner’s picture

Status: Fixed » Needs work

@jrockowitz sorry to open this back up, but I just tried upgrading to 5.19 and updates to my workflows_field seem not to persist through save. Reverting back to 5.18 with patch #24 fixes the issue. #29 and #24 do look quite similar so not sure what might have happened. Perhaps another Webform update from 5.18 to 5.19 may have affected this?

mrweiner’s picture

Status: Needs work » Fixed

Whoops, didn't realize this was only in the dev branch atm -- thought it was released.

Status: Fixed » Closed (fixed)

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

maxwellkeeble’s picture

Hoping not to reopen ticket, but for future reference if anyone visits this ticket and wants to integrate with workflows_field, this summarises what I followed based on the mentions above, now that the patch is no longer required.

  1. Webforms module 6.0.1 or higher
  2. composer require ‘drupal/workflows_field:1.x-dev@dev’
  3. drush en workflows_field
  4. Create workflow:
    1. /admin/config/workflow/workflows/add
    2. Name workflow and select type ‘Workflows Field’
    3. Create states
    4. Add transitions
  5. Add workflow to webform:
    1. Edit WebformSubmission.php, add * field_ui_base_route = "entity.webform.edit_form", before
      links = { 
      

      in annotation

    2. drush cr
    3. /admin/structure/webform
    4. In operations dropdown for the specific webform type, manage fields
    5. Add field General → Workflows type, naming it specific to the workflow you are choosing (it cannot be a generic workflow field across multiple workflows)
    6. Set field-specific permissions to limit who can view it - who can change what to what is determined by the Workflows Field permissions on admin/people/permissions for that workflow
  6. Field now appears on the webform on submission and Notes tab for submission for users with permission.
  7. Uncomment the field_ui_base_route when done

This does not seem to:

  • Add or show workflow state on the ‘Results’ tab for the webform - would need to access the state by views of the webform submissions
  • Allow site users to add workflows to the webform themselves without following a complex process and granting higher level permissions
  • Integrate with submission logs - will need to hook so when field modified a submission log is created
  • Allow integrating with webform element values or access controls, e.g. to limit access based on a group selected on the webform
devkinetic’s picture

@maxwellkeeble This looks to be correct. My experience has been similar. It is definitely a process to integrate the field, but it can be done. Thank you very much for laying it all out there.

NewZeal’s picture

I have got this working rather easily by doing the following:
1. Implement the following hook in my custom module and clear the cache:

/**
 * Implements hook_entity_type_alter().
 *
 * @param array $entity_types
 * @return void
 */
function mymodule_entity_type_alter(array &$entity_types) {
  $entity_types['webform_submission']->fieldable = TRUE;
  $entity_types['webform_submission']->set('field_ui_base_route', 'entity.webform.edit_form');
}

2. With Comment module enabled, go to administer comment types: admin/structure/comment and add a comment type that targets webform submissions.
3. Go to webform administration page: admin/structure/webform and click on the Operations dropdown for the webform you wish to add comments to. You should now find a Manage Fields link.
4. Click on Manage Fields and add a comment field of the type you just created.

There you have it! Comments.

jrochate’s picture

Do you have any idea how we could Duplicate or Clone a webform with a field added via "Manage Fields" using the above tips?

I was able to add a field and use it on the submissions, but when I build a new webform based on a duplication or cloning, the custom "Managed Fields" don't get copied. I have to go again to "manage fields" on the new webform and reuse the field.

Could that be automated based on duplication? Ideas, tips?