Problem/Motivation

Installing webform installs its default Contact form which is available to anonymous users. This is unfavorable when trying to use webform in distributions since the easiest way to automatically remove that page is a profile hook_install with an entity query to find the contact form then delete it.

Proposed resolution

Move `webform/config/install/webform.webform.contact.yml` to webform_demo, webform_examples, or a new webform_contact submodule to make it optional when installing webform itself.

CommentFileSizeAuthor
#15 webform-2888250-15.patch404 bytesmalcomio
#5 2888250-5.patch553 bytesjrockowitz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rjg created an issue. See original summary.

jrockowitz’s picture

Status: Active » Closed (won't fix)

I think it is very important to provide a starting point for new users. Personally, I am okay with distributions manually removing the contact webform using a PROFILE_install() which can be documented in a recipe.

Finally, I actually rely on the contact form for a bunch of automated tests.

rjg’s picture

Thanks. I submitted a recipe.

malcomio’s picture

To me it would make more sense for the default form to be created as part of the tests, rather than on module install.

Don't want to re-open an old issue, though.

The recipes at https://www.drupal.org/docs/8/modules/webform/webform-cookbook don't mention how to remove the default contact form.

jrockowitz’s picture

FileSize
553 bytes

Almost all form builders on the market include one default contact form to help get people started.

Still, what we have to love about Drupal and Open Source is that we can change anything (with a patch or fork).

I understand that a distribution or multisite setup might not want to keep the default contact form. The attached patch will automatically delete the default contact form during the webform module's installation.

@malcomio If you have time please add a recipe to the cookbook and link to this patch.

malcomio’s picture

uberhacker’s picture

Status: Closed (won't fix) » Needs work

Why can't we just add an option to disable the webform? Deleting the default contact form is a bad option if there were custom fields added or if the form was enabled at one point and submissions were added. In this case, you cannot simply uninstall the module. I think this should be reopened.

jrockowitz’s picture

Status: Needs work » Closed (won't fix)

I stand by my comments in #2 and #6.

Drupal core is working on improving the UX for deleting content entities which contain existing records.

I am setting this issue's status back to "Closed (won't fix)" because it is an accurate summary of the previous comments.

uberhacker’s picture

@jrockowitz: I respectfully disagree. I recently worked on a site where they initially enabled the contact form and decided later they wanted to disable the form but keep the current submission history. Without custom code, this is currently not possible. Sure, we could add code to hook_form_alter to `$form['#access'] = FALSE;` but I feel providing an option to the form is a more elegant solution. I'll try and submit a patch when I get some "free" time.

jrockowitz’s picture

uberhacker’s picture

Thank you for the feedback @jrockowitz. Once a webform is archived, is it easy to "restore" back to the previous working state? I would think simply disabling the form would be "easier" if you may want to restore later?

jrockowitz’s picture

Archiving is the same as unpublishing and completely safe.

malcomio’s picture

In case people still want to use the patch from #5, it causes an error with later versions of webform: Cannot redeclare webform_install()

I would attach an updated patch, but the option isn't available (I guess because the issue is closed). Here's the content of the updated patch:

diff --git a/webform.install b/webform.install
index bead15d20..d4be376c4 100644
--- a/webform.install
+++ b/webform.install
@@ -33,6 +33,11 @@ function webform_install() {
       'webform_submission_log',
     ]);
   }
+
+  // Issue #2888250: Remove default contact webform.
+  if ($webform = \Drupal\webform\Entity\Webform::load('contact')) {
+    $webform->delete();
+  }
 }

 /**
bcobin’s picture

Wow - the default configuration looks like a real spam magnet to me - I think an option to disable the form would make the most sense.

Being able to archive the form is a help, though; unfortunately, it seems that redirect doesn't work for the /form/contact URL... or maybe I'm missing something? Odd...

There are worse things than getting a "closed to new submissions message," though - thanks for Webform and... Onwards! :)

malcomio’s picture

FileSize
404 bytes

Re-rolled patch for 6.2.x branch