This module is working just fine on my vanilla D8B9 install. When I tried to use it on a client site, however, I got nothing but problems. I get this error on the view:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS contact_message_, contact_message.contact_form AS contact_message_contact_for' at line 1: SELECT contact_message. AS contact_message_, contact_message.contact_form AS contact_message_contact_form, contact_message.created AS contact_message_created, contact_message.id AS id FROM {contact_message} contact_message ORDER BY contact_message_created DESC LIMIT 20 OFFSET 0; Array ( )
The SQL it's producing looks like:
SELECT contact_message. AS contact_message_, contact_message.contact_form AS contact_message_contact_form, contact_message.created AS contact_message_created, contact_message.id AS id
FROM
{contact_message} contact_message
ORDER BY contact_message_created DESC
LIMIT 20 OFFSET 0
The first part of the SELECT is clearly malformed. If I delete both the "Contact message: Subject (Subject)" and" Contact message: The sender's name (Sender's name)" fields the error goes away. I tried adding other fields instead but the error comes back no matter what I add.
On the edit page of the contact message (admin/structure/contact/messages/NN), I get this error:
<em class="placeholder">Drupal\Core\Entity\Exception\UndefinedLinkTemplateException</em>: No link template "canonical" found for the "contact_message" entity type in <em class="placeholder">Drupal\Core\Entity\Entity->urlInfo()</em> (line <em class="placeholder">189</em> of <em class="placeholder">/home/vagrant/docroot/core/lib/Drupal/Core/Entity/Entity.php</em>).
Neither of those is happening on my vanilla install. I found a possible clue in this comment: "There's a bug in core contact.module, the langcode entity key is missing. Which breaks the view when you have more than one language installed, need to create a core issue for that."
The client site is multi-lingual and my vanilla site is not. Could this be the issue? I couldn't find a core issue that fit. Was one ever filed?
I'm grasping at straws a bit here. I've been searching for hours and can't figure this out. Any insight would be most welcome. :)
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | contact_storage-add_canonical-2484383-13.patch | 1.88 KB | michelle |
Comments
Comment #1
larowlanIf you could create a core issue for that, would be most appreciative
Comment #2
berdirAre you sure you did run update.php? I've seen something like this once when I forgot to run update.php after enabling the module.
Comment #3
michelle@larowlan - If I create an issue it will just be copying and pasting your words because I don't know any more about it than that. If that's what you want me to do, sure, I can do that. :)
@Berdir - Running update.php hoses this site, unfortunately, so I haven't been. That hasn't caused issues with other modules and it didn't occur to me that it might be the issue here. I will try and see what it is supposed to do and see if I can do it manually and let you know.
Thanks!
Comment #4
michelleI couldn't find any update in the install file so I hit a dead end there and tried a different approach. I enabled another language on the site where Contact Storage was working fine. As soon as I did that, the errors appeared on that site as well. So now I know the general cause and I will dig in to see if I can figure out the cure.
Help/advice appreciated. :)
Comment #5
michelleOk, I figured out what Berdir's comment about the " langcode entity key" meant and see what you mean about a core patch. I'll take care of that. So that fixes the error with the view but the other one remains so the hunt continues. :)
Comment #6
michelleOk, core issue filed: #2484959: Properly pass langcode from contact message
Keeping this one active because there's still the other issue to track down.
Comment #7
michelleOk, here is the problem:
* When you have more than one language, trying to view the /admin/structure/contact/messages/{contact_message} page gives you this error: Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template "canonical" found for the "contact_message" entity type in Drupal\Core\Entity\Entity->urlInfo() (line 189 of core/lib/Drupal/Core/Entity/Entity.php).
* The error comes from content_translation_page_attachments() where it tries to do $entity->urlInfo(), which defaults to "canonical" if nothing is passed in.
* I added a canonical link that points at the edit form (see patch) and that fixes the error but I don't know if that's the best approach. From what I've seen else where, the canonical link points to the entity view, but that doesn't exist here. Why doesn't it? Why is there only an option to edit or delete and not view these? If there isn't a reason for it, I think a better approach would be to add a view page and make that canonical.
Thoughts?
Comment #8
larowlanOoh, great sluething
You can use _entity_view too (works like _entity_form) - see aggregator.routing.yml for a sample
Comment #9
larowlanalthough we may need a view builder first
Comment #10
michelleI'll have to come back to this. Fixing the error showed me a much bigger problem: only base field data is saving. I'll file an issue for that once I have a clearer idea what is going on.
Comment #11
berdirConfigurable fields work fine for me, but you need to make sure to install config_storage *before* creating them. Otherwise the tables won't exist.
Comment #12
michelleIt actually turned out to be a remnant of the core bug. I documented it in an issue in case anyone else gets bit by it: #2485181: Documenting: Missing langcode causes non-base field data to not display even after patching core
Now I'll take a look at the _entity_view. :)
Comment #13
michelleOk, I updated the patch to use _entity_view. This definitely will need more work to make the "view" page better but it's a start. After applying the patch:
* The operations in the list view still only have edit and delete. I don't know how to get "view" in there for an option.
* "Edit" now takes you to /admin/structure/contact/messages/NNN/edit.
* There is a "View" page on /admin/structure/contact/messages/NNN.
* The "View" page is affected by changes to /admin/structure/contact/manage/CONTACT_FORM/display but not all the fields are on there. The missing fields also don't show on the view page.
* There are no tabs to switch between View/Edit/Delete.
Any further work I do on this will likely have to be on my own time since it works well enough at this point for the client. I'd like to see this through but I can't make any promises. Will do what I can.
Comment #14
berdirThere is no default view operation. That's usually implemented by making the title/subject a link. Should be available as a checkbox in the field settings I think...
Comment #15
michelleAh, I see. Maybe we could make a pseudo-field in the view with text "View" and use that? I hesitate to use the subject because we can't guarantee there is one. (The client I'm working on has that field hidden so it's never filled in.)
Comment #16
berdirYes, we're often hiding it too, but usually set an automatically generated subject through form alter because otherwise the mail subject will be empty too? :)
Comment #17
michelleOh, you know, that's a point I hadn't even thought of. Thanks for bringing that up!
Comment #18
andypostThe language of form submission should be passed from controller properly
Comment #20
andypostlangcode is here! so what's left?
Comment #21
swentel commentedThis will probably be fixed automatically if #2634226: Add a canonical path for contact message gets in.
Comment #22
andypostotoh that still makes sense to commit and continue in related
Leaving for other maintainers to commit if agree
Comment #23
larowlanFixed in #2634226: Add a canonical path for contact message