-1

I need to create a Webform element that has a list of group members, each with their own checkboxes and text fields ('job description'). I figured out how to display checkable group members through a view, but there's no option for an entity reference-able composite element. Any advice would be appreciated!!

Looking for something like this:

Group:

[X] group1

[ ] group2

Members:

[X] Sarah [Example Job Description]

[ ] Johnny [_______________________]

[ ] Bobby [_______________________]

Also, a little off topic, but is it possible to use a same page checkbox/whatever element value as a contextual filter for an entity reference element (through the arguments box)? I tried the webform tokens but I couldn't get it to work.

2
  • A work around would be to use the views field view module and create a separate view block that contains your composite and then insert this view as a field to your original view and pass the ID or whatever you see fit as the argument.
    – No Sssweat
    Aug 27, 2019 at 5:46
  • That's an interesting idea, but I ended up just creating a custom composite with an entity reference field. Thanks
    – will
    Aug 30, 2019 at 21:28

1 Answer 1

1

The cleanest solution was just going into modules/webform/modules/ and extending WebformCompositeBase to create a custom composite with an entity reference sub-element. It's super intuitive if you go off of the webform_example_composite module (included in core webforms I think).

You only really need to alter webform_example_composite/src/Element/WebformExampleComposite.php. If you create the entity reference you want to add as an individual, non-composite element in the webform ui, you can look in build->source and translate the form of it from yml to php. A basic Group entity element looked something like this:

    $elements['group_members'] = [
      '#type' => 'webform_entity_select',
      '#title' => t('Group Member'),
      '#target_type'=> 'group_content',
      '#selection_handler' => 'default:group_content',
      '#selection_settings' => [
        'target_bundles' => [
          'research_leader-group_membership' => 'research_leader-group_membership'
        ],
      ],
      '#attributes' => ['data-webform-composite-id' => $html_id . '--group_members'],
    ];

In the webform_example_composite module, the Submission data is generated by again extending WebformCompositeBase in Plugin/WebformElement/WebformExampleComposite.php and overriding the formatHtmlItemValue and formatTextItemValue functions. If you need custom formatting for an entity reference, you'll have to look through WebformCompositeBase and figure out what to call. I was happy with the standard formatting. Just comment out the custom formatHtmlItemValue and formatTextItemValue functions in Plugin/WebformElement/WebformExampleComposite.php to see what standard formatting looks like for your composite.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.