Nowadays emojis are everywhere and they are a fundamental part of the social communication. Twits, instagram pictures and others kinds of embedded resources contains this kind of things.
Emojis are represented internally by an unicode character, so in order to have support for emojis we need to have a full support to UTF8 characters, that means, libraries support, language support and database support.
There is a well know issue with Drupal and Emojis since not always we do an installation of mysql with support for UTF8 or we do the proper configuration for the charset in the settings, this bad configuration can take us to errors like these when we save a node that contains an emoji.
[cc lang=”php” width=”100%”]
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect string value: ‘\xF0\x9F\x92\x95’ for column ‘data’ at row 1: INSERT INTO ….
In order to fix this issue you can install and configure properly the support for UTF8 in the whole stack, however if you have a production site already running change all your settings can be a pain.
A quick solution is the contrib module strip_utf8mb4, this module will hook an event in the hook_field_attach_presave to replace all these emoji characters for a non utf8 character (by default –), so it can be saved without problems.
To use it just download the module from the module project page
Enable it and that’s it, ready to put some fancy emojis without troubles.