If you put an emoji into any plain text field, it implodes with an error that it couldn't insert into the database, presumably due to encoding.CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x91\x8A' for column 'field_testimonial' at row 1
I just noticed this is resolved in #1627 but that's no good for Craft 2... totally understand if you can't/won't fix though.
Emoji is only supported by Rich Text fields when using MySQL (as is always the case in Craft 2).
I can understand the technical reasons for not supporting emoji in plain text, but could this error be handled more gracefully? When I experienced this, the entire entry became uneditable and I had to hit the database to restore an older revision manually.
Would it be possible to simply strip it out when saving, rather than breaking the entire entry?
Not sure about stripping it out, but we could definitely handle it more gracefully, with a validation error.
Even better 鈥撀爄f you鈥檙e running PHP 5.4+ , Plain Text fields will now convert emojis to :shortcodes: when saving to the database (and back to unicode when retrieving the data).
馃檹 incredible work, thank you @brandonkelly!
...he's like that...saw this come by and thought it was pretty cool too :)
Is this fixed for Craft 2 or just Craft 3?
Both聽鈥撀燽ut the fix won鈥檛 apply to Craft 2 if your server is still running PHP 5.3, as the library we鈥檙e using requires PHP 5.4+.
Thanks for the reply Brandon. I just tried it with Craft 2.6 and in my server info I see:
PHP Version | 7.0.22-0ubuntu0.16.04.1
But I'm still getting the error when trying to save an emoji in a plain text field.
What version of Craft 2.6? Plain Text fields just got support for emojis in this week鈥檚 2.6.3004 update. Also worth noting that not _all_ emojis are supported 鈥撀爅ust the ones LitEmoji supports.
I see. Yeah one of the feeds uses this one: 馃 which is a newer Emoji. Thanks!
Most helpful comment
Even better 鈥撀爄f you鈥檙e running PHP 5.4+ , Plain Text fields will now convert emojis to
:shortcodes:when saving to the database (and back to unicode when retrieving the data).