How do you get emojis accepted in Drupal 7?  ? ? ?
hack

How do you get emojis accepted in Drupal 7? ? ? ?

Dabitch
Dabitch

Quite a long time ago, as Kidsleepy was writing an article on Adland, he added an embedded tweet that contained an emoji. Eeek. This lost the entire article, as he met a page stating "an error occurred". I knew from his frustrated rantings at the screen that I had to solve the issue of emojis in Drupal 7, fast.

And I did, but then I was suddenly bounced off the cloud server host Vultr, and had to set up a new server somewhere else, and I lost a lot of tweaks I had done along the way. So I just fixed this again and figured I should make a note in case anyone else was in need of help. All of this assumes that you have sudo access because life isn't fair but the root password helps.

The issue stems from the fact that in Drupal7 the MySQL driver does not support full UTF-8. You can fix this in several ways, you could even use the table converter module. Personally I simply converted the tables for HTML fields and you'd have to do the same with your database. I use Drupal paragraphs, so I had to make sure to convert my "html_content" fields as well. And don't forget the comments. Straight in MySQL this can be done like so;

ALTER TABLE field_data_body MODIFY body_value longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, 
ALTER TABLE field_revision_body MODIFY body_value long text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
ALTER TABLE field_comment_body MODIFY comment_body_value longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
ALTER TABLE field_revision_comment_body MODIFY comment_body_value longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

 

Also, don't forget to do the same with comment_body_format and body_summary - anywhere that you will have emoji or HTML input in your database. If you want to allow Emoji or Japanese character names, you'll need to change the user table fields. 

 

Now, there are two other things you need to do in order for this to work. First, in your settings.php, add this; 

$databases = array (

 

  'default' => 

  array (

    'default' => 

    array (

      'database' => 'databasename',

      'username' => 'databaseusername',

      'password' => 'databasepassword',

      'host' => 'localhost',

      'port' => '',

      'driver' => 'mysql',

      'prefix' => '',

      // Add default charset and collation for mb4 support here.

      'charset' => 'utf8mb4',

      'collation' => 'utf8mb4_general_ci',

    ),

  ),

);

Then, find your mysql.cli and make sure that you have this;

 

  [client]

default-character-set = utf8mb4

 

[mysql]

default-character-set = utf8mb4

character-set-connection = utf8mb4

character-set-results = utf8mb4

 

[mysqld]

character-set-client-handshake = FALSE

character-set-server = utf8mb4

 

collation-server = utf8mb4_unicode_ci

 

Restart your MySQL server, clear all of your Drupal caches, and you are now on your way to commenting "⛪?❗" to your heart's content. Enjoy!