From 4f8eefa7aa6282c81bf9b94c50ca97106d08f4e5 Mon Sep 17 00:00:00 2001
From: DevinCarlson <DevinCarlson@290182.no-reply.drupal.org>
Date: Fri, 23 Jun 2017 11:46:57 -0400
Subject: [PATCH] Issue #2463407 by Devin Carlson: Support custom CKEditor
 icons

---
 entity_embed.ckeditor.inc | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/entity_embed.ckeditor.inc b/entity_embed.ckeditor.inc
index 8def1283..a93e79e2 100644
--- a/entity_embed.ckeditor.inc
+++ b/entity_embed.ckeditor.inc
@@ -24,11 +24,25 @@ function entity_embed_ckeditor_plugin() {
   $buttons = array();
 
   foreach ($embed_buttons as $embed_button) {
-    // CKEditor only supports icons relative to the plugin path.
-    // @todo: Figure out how to support custom icons.
+    $icon = 'entity.png';
+    $icon_path = FALSE;
+
+    // Use a custom icon when available.
+    if ($fid = $embed_button->button_icon_fid) {
+      if ($file = file_load($fid)) {
+        // We are unable to use _entity_embed_button_image() because CKEditor
+        // requires a specific format for icon paths.
+        if ($wrapper = file_stream_wrapper_get_instance_by_uri($file->uri)) {
+          $icon = file_uri_target($file->uri);
+          $icon_path = base_path() . $wrapper->getDirectoryPath() . '/';
+        }
+      }
+    }
+
     $buttons[$embed_button->name] = array(
       'label' => check_plain($embed_button->button_label),
-      'icon' => 'entity.png',
+      'icon' => $icon,
+      'icon_path' => $icon_path,
     );
   }
 
-- 
GitLab