I would like to create a contextual filter that matches based on the value of a field in the webform submission.

There are contextual filter options for webform submission id or id of the user that submitted it, but it doesn't allow us to match the value of a field in the submission.

Comments

wunter8 created an issue. See original summary.

bserem’s picture

I second that!

@wunter8, while the webform_views module "exports" webform data in view fields and filters, it doesn't do so in contextual filters.
You can see this here: https://docs.google.com/spreadsheets/d/1_wxB3f1EToDxzP53mIIz89LUf07PPKJz...

bucefal91’s picture

Version: 8.x-5.0-alpha2 » 8.x-5.x-dev
Status: Active » Needs review
StatusFileSize
new1.15 KB

Hello, guys!

Yes, until now there was no support for arguments within this module. But yes, that's very good to have it included. I provide a rather small patch but it globally enables context filters for all the elements. It's a pretty dumb "string to string" comparison. But it should cover lots of cases (probably the most).

And then we can tailor experience for some specific elements to more appropriate "argument" logic. Check this patch out and let me know how it looks. I've tried it on "text field", "number" and "date" elements.

no sssweat’s picture

Status: Needs review » Reviewed & tested by the community

@bucefal91 thank you for making the patch. It works like a charm.

- Patch applied cleanly.
- On numbers, (positive and negative) it worked.
- Text field, worked.
- Taxonomy term ref, worked using term id (tid).
- Created date & custom date field worked using YEAR-MM-DD format.
- Radio button worked when using the key (what webform calls option value).

  • bucefal91 committed a864a80 on 8.x-5.x
    Issue #2898000 by bucefal91: Introducing the general support for...
bucefal91’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for testing it! Committed into dev snapshot :)

Status: Fixed » Closed (fixed)

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

andileco’s picture

@bucefal91, I updated to the latest -dev in order to test this. I was able to add a field from my Webform, as requested in this issue. However, the "Webform submission: Submitted to: Entity ID" handler broke.

no sssweat’s picture

StatusFileSize
new46.68 KB

@andileco I am using 8.x-5.0-alpha5 and applied the patch above to it and do not see a "Submitted to: Entity ID" option

image

So maybe the issue is not the above patch, and maybe someone added the "Submitted to: Entity ID" functionality to dev on some other issue??? (if it even exist, because I was not able to find it by doing a quick search on the issues list). If it exists the the bug is probably there and not here.

no sssweat’s picture

@andileco I do however see a "Submission ID" option and using that works fine. Just be careful because the Submission ID is not the same as the number given in the "#" column of /admin/structure/webform/manage/report/results/submissions.

If you add the submission ID to your view as a field you will see these two numbers do not match.

andileco’s picture

StatusFileSize
new305.26 KB

Here's what it looked like before I updated:

 Submitted to Entity ID

I'm likely using a newer version of Webform, which is probably where that field comes from. But I wonder why that one would be breaking with this update, as the others seem fine.

andileco’s picture

The problem seems to be here (it was for a different patch...will need to find where it occurred):

    $data[$base_table]['entity_id'] = [
      'title' => $this->t('Submitted to: Content'),
      'help' => $this->t('Content (node) which webform submission is submitted to.'),
      'relationship' => [
        'base' => $node_definition->getDataTable(),
        'base field' => $node_definition->getKey('id'),
        'id' => 'standard',
        'label' => $this->t('Submitted to: Content'),
        'extra' => [
          ['left_field' => 'entity_type', 'value' => 'node'],
        ],
      ],
    ];

I heard from @jrockowitz that 'entity_id' was the ID used for the field I'm missing now.

andileco’s picture

I changed the first line to:

$data[$base_table]['content_entity_id'] = [

and that restored "Webform submission: Submitted to: Entity ID".

@bucefal91, I will create a separate issue recommending this modification.