Score:0

Create alternate "View Modes" for Webform Submissions?

tr flag

In a View of type "Webform Submissions", I have added a field called "Webform submission: Rendered entity". This displays the entire webform submission (content from all fields in the webform). My problem is that I have a few field elements in the webform that have create/view/update access permissions set to the Administrator role only. This is important because the webform is used by the Commerce Webform Order module to collect extended info for orders. The submitted results of those restricted fields are being displayed in the View.

The purpose of the View is to display the submitted contents of the webform in the Commerce receipt email. I do so with the following code in my order receipt template:

{{ drupal_view('my_view_name', 'block_1', order_entity.getOrderId) }}

As I stated, the restricted field results are being included in the Views output. In the "Webform submission: Rendered entity" field settings in the View, there is a selector called "View Mode" in which the only option is "Default". Is there a way to create a new View Mode for webform submissions, which would include only those fields that I choose? If so, I would be able to add the name, phone, etc fields and exclude the Admin-specific fields, and then select that alternate View Mode in the Views field settings. I have scoured the Webform settings in the back-end of the website, and I cannot find any opportunity to create that new View Mode for Webform Submissions.

Score:1
us flag

WebformSubmission entities have only a few 'view modes', as defined in \Drupal\webform\WebformSubmissionViewBuilder::buildComponents method. Which means that if you want to have another one, you need to override WebformSubmission entity type view builder handler. These view modes are not exposed to views, so you need to provide your own views field handler as well.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.