Problem/Motivation
Right after the Drupal installation, if a user tries to contact the site owner via the provided contact form that is linked in the footer, he gets an error message that the mail could not be delivered. This happens, because the contact module creates the site contact form without pre filling any recipient. The admin has to set the recipient at /admin/structure/contact/manage/feedback, but this is not obvious.
Proposed resolution
A resolution would be for the site to send the contact form email to the site's email address, if the recipients field is not set. This can happen only for the default contact form that comes with installation, as the recipients field is mandatory and no other form may be created without this field properly filled in.
I have created a patch that does just that. Checks if the recipients are set. if not, sends the mail to the site's email address.
Also, another approach is to set the contact form email recipient during installation time. The patch at #6 works like this.
Remaining tasks
- Add tests.
- Rewrite patch.
- Review patch.
User interface changes
None
API changes
Could be API change if we inject the config.factory service into the MailHandler class. This is the "right" way to do this.
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | contact-email-standard-2349651.36.patch | 5.99 KB | larowlan |
| #36 | interdiff.txt | 1.3 KB | larowlan |
| #33 | contact-email-standard-2349651.33.patch | 4.69 KB | larowlan |
| #33 | interdiff.txt | 2.76 KB | larowlan |
| #32 | do-it.gif | 430.29 KB | larowlan |
Comments
Comment #1
yannisc commentedI attach the patch.
Comment #2
mradcliffeThe comment line should end at 80 characters or less. If a word exceeds this, then you should start a new line.
Would it be possible to inject the configuration class into MailHandler?
This would be an API change, but would be better code.
We probably need a test for this as our current tests haven't caught the issue. A test would assert that the recepient of the mail is system.site.mail via assertMail... methods.
Comment #3
mradcliffeTo inject the service you would need to modify contact.services.yml and add @config.factory service (iirc on the service name in core.services.yml).
Then __construct needs to be modified to set $this->config = ConfigFactory.... there are some examples around core.
Comment #4
yannisc commentedMatthew, thank you for your comments!
I will fix the comments length issue, but could you please elaborate on the configuration class issue?
What do you mean by "inject the configuration class"? What do we want to achieve?
Thanks again for your help and mentorship,
Yannis
Comment #5
larowlanDoes the default form live in standard profile? If so the fix should be to load the form config entity in standard_install() and set using the value in config
Comment #6
yannisc commented@larowlan, yes, the default form lives in the standard profile.
I agree that it would be better if the form got populated with the site's email during installation time. I think it cannot be done via standard_install though, as this runs before the user inputs the site email, but can be done through SiteConfigureForm.php.
I attach a patch with this approach.
Comment #7
yannisc commentedComment #8
d.pagkratis commentedThe patch attached from yannisc works properly!
Comment #9
penyaskitoWe should use
$this->moduleHandler, which is already injected. Otherwise, I think is RTBC.Comment #10
yannisc commentedI attach with penyaskito's fix.
Comment #11
yannisc commentedComment #13
penyaskitoOh! And we need tests too!
Comment #14
yannisc commentedSorry, this is the right one.
Comment #15
yannisc commentedI don't see an Installer folder in the Tests folder. Mradcliffe added the needs tests tag before switching to the installer approach. Can you point me to the right direction?
Comment #16
penyaskitoInstaller tests are in
Drupal\system\Tests\Installer. You should extendInstallerTestBase. Look atDrupal\system\Tests\Installer\SiteNameTestas an example.Comment #17
larowlanThis is wrong. You said earlier that contact.form.feedback lives in standard profile. In which case globally changing the installer for all profiles is wrong. Please add a hook form alter to standard profile that adds a new submit handler which in turn updates the config.
Comment #18
yannisc commentedlarowlan, I've added an if that checks if the contact module is enabled and only then it adds the site email to the recipient field. That way, it will work with any profile. I've tested it with both the standard and the minimal profiles and works ok.
Comment #19
larowlanBut what about a contrib profile that includes contact module but not the feedback form?
Comment #20
yannisc commentedShould I add an extra condition that checks for the feedback form and that the recipient field is empty, then?
Comment #21
larowlanNo, as said in #5 this is an issue with standard profile, nothing to do with contact.
Here's how I think it should be done, as well as a test to verify it works.
Test only patch is the .fail one - should come back red.
Pass patch should come back green.
Comment #23
yannisc commentedIt worked for me as well.
Comment #24
penyaskito#21 is RTBC, test coverage++.
Comment #25
alexpottNice find, nice fix and nice test.
Committed 62f8b46 and pushed to 8.0.x. Thanks!
Comment #28
alexpotthmmm... actually contact.form.feedback is provided by the contact module. Reverted the change for now.
I think we should consider moving the feedback form to the standard profile.
Comment #30
larowlanComment #31
larowlanLets move it to standard
Comment #32
larowlanComment #33
larowlanComment #34
larowlanComment #36
larowlanComment #37
penyaskitoFeedback form is in standard profile instead of the contact module as alexpott suggested.
Missing
hidden: true?Otherwise, RTBC.
Comment #38
penyaskitoTalked with larowlan on IRC.
After checking #2188661: Extension System, Part II: ExtensionDiscovery (item 1.4 on proposed resolution) and looking at the existing test modules, if we grep'ed correctly there are only 3 which define
hidden:true. So not a requirement then.Comment #39
alexpottNice - only if all core modules did the same as contact - yep I'm looking at you forum, book, node and views. Moving all "feature-like" config entities into standard will be awesome - roll on 9.x :)
Committed 9a19c4e and pushed to 8.0.x. Thanks!
Comment #41
berdircontact_install() still has this:
That's dead code now?
Comment #42
alexpottOpened #2362519: Remove dead code from contact.install