Problem/Motivation
Right now, contact messages in core are created on the fly, rendered as an e-mail, sent and then dropped.
To make it more flexible, we should make message behave more like any other entity to support use cases like a contrib module switching the storage to log sent contact messages.
Proposed resolution
- Add a UUID field
- Add a langcode field which will be set to the current language automatically once that works
- "Save" the message, as we are now using the null storage, this will not do anything, but it will make it possible for a contrib module to switch out the storage and it should then just work. Right now, it would have to override the form to be able to call save itself.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#29 | 2289063-contact-storage-29.patch | 14.54 KB | andypost |
Comments
Comment #1
corvus_ch CreditAttribution: corvus_ch commentedComment #2
larowlanHi corvus_ch, any progress on this?
If not willing to pick it up
Comment #3
corvus_ch CreditAttribution: corvus_ch commentedNo, not really. Thought I will be able to do it last weekend but…
So go ahead.
Comment #4
andypostThere's some tricks with message formatting in related issue.
+1 to add language field
Comment #5
larowlanlooking now
Comment #6
larowlanWorks, to quote @berdir
but that's another issue
So this makes it possible to provide contact message storage, with a test implementation and tests to boot
Comment #7
BerdirThis doesn't seem to actually implement the "unless specifically set" part?
Contains ;)
Did you copy that coment? Doesn't really make sense to me, especially because we no longer have a category selection input ;)
Can we add a comment here why we set this explicitly?
Aren't the entity keys automatically marked as not null?
Otherwise, really nice! We can basically take that test module and start a contact_storage contrib project.
Would be nice to get feedback from @fago and @plach on the generic changes.
Comment #8
Berdir@plach could probably also check if we need to change the install hook with #1498720: [meta] Make the entity storage system handle changes in the entity and field schema definitions, a real module probably also need uninstall?
Comment #9
larowlanAddresses #7
Comment #10
Berdirlanguage() automatically falls back to the default language, which always has to be set internally, so this doesn't work, you need to check the langcode field directly.
Re 5, did you verify that the key is NOT NULL'd correctly? I didn't, just think that's the case :)
Comment #11
larowlanyeah, ContentEntitySchemaHandler::processIdentifierSchema() converts int to SERIAL which is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE, so we're good there.
Fixes #10
Comment #12
BerdirUsually works well to assign issues to @plach to get feedback from him, so let's try that :)
Comment #13
plachNice work :)
I don't think this is necessary and if it is we have a bug :)
Entity schema should already be installed/uninstalled in the module handler.
This is weird, a base field should never end up in a dedicated table. This is surely taken care in #1498720: [meta] Make the entity storage system handle changes in the entity and field schema definitions, so if this necessary now, let's add a todo to remove this hack, also because the provider property is supposed to be set only by the Entity Manager.
Comment #14
Berdir1. is I think necessary because we only install schema for entity types of the module that is currently installed, and contact has no storage then, so we don't install it, and when we install the test/storage module, but then we don't look at contact message again, because that's not provided by that module.
I assume that your changes issue might improve that, because it will detect a change after you install the storage module and will attempt to/allow to install the schema? we still might have to trigger it manually in the test somehow, not sure, did not look at your issue at all so far..
2. The problem is how we define if it's a base field or not. Right now, only fields added by the entity type itself are considered base fields (provider == entity type provider), and this is not. We kind of need the provider check there, or we'd keep expanding the node table with additional fields...
Comment #15
larowlan1. Yep it is needed because like berdir said, provide mismatch
2. Same, provider mismatch forced id into a dedicated table
So not sure if there is actually anything to do here - so bumping back to needs review
Comment #16
larowlanAdds todo referencing #1498720: [meta] Make the entity storage system handle changes in the entity and field schema definitions
Comment #17
plach@berdir:
Spoke with @larowlan in IRC: both point make sense, but they should be fixed by #1498720: [meta] Make the entity storage system handle changes in the entity and field schema definitions, so let's add a todo about removing the related "hacks".
I'd say a base field is also any field defined through
hook_entity_base_field_info()
:)-> Any field returned by
EntityManagerInterface::getBaseFieldDefinitions()
.Comment #18
larowlanAdded second @todo
Comment #19
plachLooks RTBC to me, thanks.
Comment #20
tim-e CreditAttribution: tim-e commentedCan we inject?
Can we inject?
Comment #21
larowlanFixes #20 and a few other injection issues in MessageForm
there is no OO equiv of drupal_mail, drupal_set_message and user_cookie_save().
user_cookie_save() call can go when #749748: Contact, register and comment forms do not prefill with user info from browser is ready (its close) so added a todo and a note over there.
Comment #22
tim-e CreditAttribution: tim-e commentedLooks good
Comment #23
plachThe module handler is already available through setter injection in the
EntityForm
class...Comment #24
larowlanFixes #23
We also have currentUser() from FormBase
Comment #25
plachLooks good, thanks
Comment #26
andypostJust a nitpick
second line could re-use $user too
Comment #27
larowlanfixes 26
Comment #28
alexpottComment #29
andypoststraight re-roll
Comment #30
BerdirWas about to post the re-roll too.
There is only a small context change from setSettings() to setSetting().
@andypost mentioned that the issue this conflicted with (#1856562: Convert "Subject" and "Message" into Message base fields) needed some tricks re entity language, so maybe we can revert that now?
Comment #31
andypost@Berdir Do you mean that hunk?
Suppose we need @plach here
Comment #32
andypostAlso there's related issue #1938178: Contact module categories has not support language select
So probably we can drop that here
Comment #33
alexpottCommitted 1793df6 and pushed to 8.x. Thanks!