Problem/Motivation

Currently, the "Customize" feature for the webform submission list is maintained via global state. Some users may benefit from the ability to personalize which webform elements are visible in the list.

Proposed resolution

I think that we should examine and discuss how the current customize feature may be used by organizations. For example, some organizations may have a specific configuration that their submission viewers are not normally able to change. Perhaps the users that are analyzing submissions are not trained on how to use the customize feature, or do not wish to take on the responsibility of maintaining their own list views. A direct shift from global state to individualized user settings may be disruptive to this use case.

Remaining tasks

  • Document how the feature was originally intended to be used.
  • TBD?

User interface changes

Depending on the changes, the permissions controlling the "Customize" button may be affected.

API changes

Webform::(get|set|delete|has)UserData methods add

Data model changes

N/A

User Acceptance Test

  • Confirm existing 'Customize' results is working as expected
    /admin/structure/webform/manage/contact/results/submissions
  • Enable 'Allow users to customize the submission results table'
    /admin/structure/webform/manage/contact/settings/submissions
  • Confirm 'Customize' button changed to 'Customize my table'
    /admin/structure/webform/manage/contact/results/submissions
  • Click 'Customize my table'
    /admin/structure/webform/manage/contact/results/submissions
  • Confirm 'Customize my table' allows table to be customized for the current user
    /admin/structure/webform/manage/contact/results/submissions/custom/user
  • Confirm 'Customize default table' button on 'Customize my table' form allows defaults to be defined
    /admin/structure/webform/manage/contact/results/submissions/custom
  • Confirm 'Customize default table' and 'Customize my table' reset works as expected
    /admin/structure/webform/manage/contact/results/submissions/custom
  • Confirm 'Allow users to customize the submission results table' can be toggled on/off via the 'Customize' form
    /admin/structure/webform/manage/contact/results/submissions/custom
  • Confirm 'Allow users to customize the submission results table' can be enabled for all webforms
    /admin/structure/webform/config/submissions

Comments

Luke.Leber created an issue. See original summary.

luke.leber’s picture

StatusFileSize
new2.33 KB

Added proof of concept patch that seems to allow customization on a per-user basis.

I'm not entirely convinced that using \Drupal::state is appropriate for this kind of thing after introducing this much granularity. While is was perfect for storing the global state, it almost seems like the wrong tool for storing per-user information.

luke.leber’s picture

Copying the patch from slack seems to have corrupted it. Trying again...

jrockowitz’s picture

This would have to be configurable setting and use UserData. My gut says we need to allow admins to set the default results columns and then provide a setting to allow individual users to further customize the result columns.

A few notes...

  • Only the columns, sort, direction, and limit should be configurable
  • Add 'Allows users to customize the results' checkbox should be added to /admin/structure/webform/manage/{webform}/settings/submissions
  • Details widget should be labeled 'Submission results settings'
  • WebformResultsCustomForm::buildForm needs to be reworked to allow columns, sort, direction, and limit form to be reusable
  • Saving and deleting customized results needs to be refactored
  • Webform related user data needs to be deleted when a webform is deleted
luke.leber’s picture

What are your thoughts on making an (abstract?) base class form to be able to recycle most of the form build? Using two forms could also allow for a cleaner separation of persistence logic. It should also let the existing form remain intact for BC reasons.

I'm also wondering if the new form should have its own link on the results page such that there could be a "Set Defaults" and/or a "Customize" (bikeshed needed) button that appears depending on the user's permission. This could allow more logic to be nicely separated, especially when a user has permission to edit the webform default as well as their own personal results lists.

This week is going to be busy, but I should have more time next weekend to get at least part of a rough working patch put together.

jrockowitz’s picture

BaseForm could be a good approach. I think you could also pass an $operation parameter to WebformResultsCustomForm::form. I recommend approaching this patch in small incremental steps and to make sure not to break WebformSubmissionListBuilderTest.

luke.leber’s picture

StatusFileSize
new5.45 KB

Added configuration related changes.

luke.leber’s picture

StatusFileSize
new5.49 KB

Ouch. Added webform settings update call to update hook.

luke.leber’s picture

StatusFileSize
new5.5 KB

Passing config changes.

nancydru’s picture

I don't see a per-user option as being terribly useful, but I really would like to see it not select every single form field to show. My forms have literally hundreds of fields, so the view gets enormous. I would rather see an opt-in for form fields (as opposed to module fields) instead of an opt-out.

luke.leber’s picture

I think this is more of an "enterprisey" feature that is useful when more than one individual is involved in site management, and none of whom should be able to administer webform settings.

Our particular use case involves different types of stakeholders that all care about different data. For example, marketing associates want to see campaign related information (who clicked what, where did they come from, etc...) whereas others want to see other subsets.

Having multiple parties attempting to view data all at once can be disorienting (especially if someone else changes the view while you are using it). Having enough permission to customize the results also currently carries more implications.

luke.leber’s picture

StatusFileSize
new6.83 KB
  • Add call to delete user-specific webform configuration on delete.
  • Adjust update hook N.
jrockowitz’s picture

We also need to add some test coverage either via \Drupal\Tests\webform\Functional\WebformSubmissionListBuilderTest or a brand new Test.

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new5.11 KB

The attached patch just contains the 'results_customize' configured to be a global or webform specific behavior.

How the customized results data is stored right now is a little confusing and I want to see if there is an opportunity to fix this.

I do want to restore the below code once we have customized user results.

+      /** @var \Drupal\user\UserDataInterface $userData */
+      $userData = \Drupal::service('user.data');
+
+      // Delete all user customized results.
+      $userData->delete('webform', NULL, 'webform.webform.' . $entity_id . 'customized_results');

  • a401c55 committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...
jrockowitz’s picture

Approach

On the Results table/page

  • If results_customize is TRUE and ....
  • User is webform administrator display 'Customize my table' and 'Customize default table'
  • User is NOT webform administrator display only 'Customize my table'
  • If results_customize is FALSE then continue to change 'Customize' button to 'Customize table'.

In the 'Customize table' form

  • Pass type = (default|user) as route parameter
  • Change form title to 'Customize (default|my) table'
  • Set default settings to webform states
  • Set my settings to user data

Notes

  • Possibly add getUserDate and setUserData to Webform entity.
  • Rework \Drupal\webform\WebformSubmissionStorage::getCustomSetting
  • User data will be stored using 'webform.webform.{webform_id}' prefix.
  • Need to investigate how default settings are working.

  • 82f7353 committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...

  • 13842be committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...

  • 88e4fbf committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...

  • 5b9845b committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...

  • 7fc0746 committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...

  • fdad832 committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...
jrockowitz’s picture

StatusFileSize
new55.39 KB

The attached patch is a preview of the new feature. The patch still needs some more test coverage.

  • 8c1d911 committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...

  • 3400aed committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...

  • 564d7bd committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...
jrockowitz’s picture

StatusFileSize
new66.44 KB

This patch has test coverage and is ready to be reviewed.

  • 151234f committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...
jrockowitz’s picture

Issue summary: View changes
StatusFileSize
new205.35 KB
new65.65 KB

I think that we should examine and discuss how the current customize feature may be used by organizations.

Most organization webforms have only one "owner", which means the one "owner" can customize the results without any problems.

Allowing users to customize the submission results table addresses the situation where a webform has multiple owners who required a customized results table. The existing functionality should be default behavior and allowing users to customize the submission results table can be enabled directly in the 'Customize table' modal.

jrockowitz’s picture

Issue summary: View changes
luke.leber’s picture

Hey Jacob,

I was able to take a pass through the changes (sans tests -- I'll try to run through those tomorrow night). Overall, it's a work of art. I have just a couple pieces of feedback.

1) The \Drupal\webform\Form\WebformResultsCustomForm form seems to continuously render a 'Customize my table' link for users that have access to customize their personal table, but not set the defaults. Perhaps this could be a fix:

diff --git a/src/Form/WebformResultsCustomForm.php b/src/Form/WebformResultsCustomForm.php
index 2b8222be8..e8c1ca11b 100644
--- a/src/Form/WebformResultsCustomForm.php
+++ b/src/Form/WebformResultsCustomForm.php
@@ -150,7 +150,7 @@ class WebformResultsCustomForm extends FormBase {
           '#suffix' => '</p>',
         ];
       }
-      else {
+      else if ($this->type !== static::CUSTOMIZE_USER) {
         $route_name = $this->requestHandler->getRouteName($this->webform, $this->sourceEntity, 'webform.results_submissions.custom.user');
         $route_parameters = $this->requestHandler->getRouteParameters($this->webform, $this->sourceEntity);
         $url = Url::fromRoute($route_name, $route_parameters)

2) The \Drupal\webform\WebformSubmissionStorage::getCustomSetting method could potentially allow user-specific customizations to be used even if the webform configuration forbids it.

To POC this, add a user customization to a form that's different than the default, then disallow user customizations. Refresh the page and see that the user customized settings are still used.

diff --git a/src/WebformSubmissionStorage.php b/src/WebformSubmissionStorage.php
index 206eb72dd..4a366dc7e 100644
--- a/src/WebformSubmissionStorage.php
+++ b/src/WebformSubmissionStorage.php
@@ -897,6 +897,8 @@ class WebformSubmissionStorage extends SqlContentEntityStorage implements Webfor
 
     $key = "results.custom.$name";
     if (!$source_entity) {
+      // I think we might need an access check here.
+      // Or perhaps clear out user data if a webform is updated to forbid user customizations?
       return $webform->getUserData($key)
         ?: $webform->getState($key)
         ?: $default;

  • fff6098 committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber: Allow users to personalize the submission...
jrockowitz’s picture

StatusFileSize
new3.36 KB
new66.56 KB

Thanks for the code review. I applied your suggestions to the patch.

luke.leber’s picture

I'm a little confused by some of the WebformSubmissionListBuilderCustomizeTest test. If I'm not mistaken, the test seems to be broken -- or at least not working like I'd expect it to.

diff --git a/tests/src/Functional/WebformSubmissionListBuilderCustomizeTest.php b/tests/src/Functional/WebformSubmissionListBuilderCustomizeTest.php
index 381b18144..9f741dcb2 100644
--- a/tests/src/Functional/WebformSubmissionListBuilderCustomizeTest.php
+++ b/tests/src/Functional/WebformSubmissionListBuilderCustomizeTest.php
@@ -244,8 +244,9 @@ class WebformSubmissionListBuilderCustomizeTest extends WebformBrowserTestBase {
     $webform->setSetting('results_customize', TRUE)->save();
 
     // Check that 'Customize' button and link are not visible.
+    // This part *should* fail, right?
     $this->drupalGet('/admin/structure/webform/manage/test_submissions/results/submissions');
-    $this->assertLink('Customize');
+    $this->assertLink('Customize'); // <-- $this->assertNoLink('Customize') ?
     $this->assertLinkByHref("${base_path}admin/structure/webform/manage/test_submissions/results/submissions/custom");
 
     // Check that 'Customize my table' button and link are visible.

Running through the steps manually in my browser, I can confirm that a webform set with 'results_customize' should only show the 'Customize my table' link on the submission table and not the 'Customize' link. I'm not sure where the test is finding a 'Customize' link on that page.

* AH! It looks like \Behat\Mink\Element\Element::findAll can fall back to doing partial matches. Why the link was found now makes sense.

jrockowitz’s picture

I will tweak the test to be more specific.

  • 20e9c7c committed on 3108433-personalize-results
    Issue #3108433 by Luke.Leber, jrockowitz: Allow users to personalize the...
jrockowitz’s picture

StatusFileSize
new66.57 KB

Instead of $this->assertLink('Customize'); I decided to use $this->assertRaw('>Customize<');.

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community

  • jrockowitz authored e7d804a on 8.x-5.x
    Issue #3108433 by jrockowitz, Luke.Leber: Allow users to personalize the...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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