From 26a8d2c216607d0821fc577cbde7a9c4d0725a3c Mon Sep 17 00:00:00 2001
From: rudiedirkx <rudiedirkx@890274.no-reply.drupal.org>
Date: Tue, 31 Mar 2015 16:46:02 -0600
Subject: [PATCH] Issue #2422875 by rudiedirkx: Save module path for every
 plugin to make features reusable

---
 ckeditor.ckeditor.inc     |  9 +++++++++
 includes/ckeditor.lib.inc | 17 ++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/ckeditor.ckeditor.inc b/ckeditor.ckeditor.inc
index f3ec838..c283537 100644
--- a/ckeditor.ckeditor.inc
+++ b/ckeditor.ckeditor.inc
@@ -23,6 +23,7 @@ function ckeditor_ckeditor_plugin() {
     if (file_exists($_editor_path . '/plugins/tableresize/plugin.js')) {
       $plugins['tableresize'] = array(
         'name' => 'tableresize',
+        'module' => 'ckeditor',
         'desc' => t('Table Resize plugin'),
         'path' => $editor_path . '/plugins/tableresize/',
         'buttons' => FALSE,
@@ -33,6 +34,7 @@ function ckeditor_ckeditor_plugin() {
     if (file_exists($_editor_path . '/plugins/autogrow/plugin.js')) {
       $plugins['autogrow'] = array(
         'name' => 'autogrow',
+        'module' => 'ckeditor',
         'desc' => t('Auto Grow plugin'),
         'path' => $editor_path . '/plugins/autogrow/',
         'buttons' => FALSE,
@@ -43,6 +45,7 @@ function ckeditor_ckeditor_plugin() {
     if (file_exists($_editor_path . '/plugins/stylesheetparser/plugin.js')) {
       $plugins['stylesheetparser'] = array(
         'name' => 'stylesheetparser',
+        'module' => 'ckeditor',
         'desc' => t('Stylesheet Parser plugin'),
         'path' => $editor_path . '/plugins/stylesheetparser/',
         'buttons' => FALSE,
@@ -55,6 +58,7 @@ function ckeditor_ckeditor_plugin() {
     if (preg_match("/\/(standard|full)-all/", $_editor_url)) {
       $plugins['tableresize'] = array(
         'name' => 'tableresize',
+        'module' => 'ckeditor',
         'desc' => t('Table Resize plugin. See <a href="@ckdocs-tableresize">addon page</a> for more details.',
           array('@ckdocs-tableresize' => 'http://ckeditor.com/addon/tableresize')
         ),
@@ -64,6 +68,7 @@ function ckeditor_ckeditor_plugin() {
       );
       $plugins['autogrow'] = array(
         'name' => 'autogrow',
+        'module' => 'ckeditor',
         'desc' => t('Auto Grow plugin. See <a href="@ckdocs-autogrow">addon page</a> for more details.',
           array('@ckdocs-autogrow' => 'http://ckeditor.com/addon/autogrow')
         ),
@@ -73,6 +78,7 @@ function ckeditor_ckeditor_plugin() {
       );
       $plugins['stylesheetparser'] = array(
         'name' => 'stylesheetparser',
+        'module' => 'ckeditor',
         'desc' => t('Stylesheet Parser plugin. See <a href="@ckdocs-stylesheetparser">addon page</a> for more details.',
           array('@ckdocs-stylesheetparser' => 'http://ckeditor.com/addon/stylesheetparser')
         ),
@@ -82,6 +88,7 @@ function ckeditor_ckeditor_plugin() {
       );
       $plugins['codesnippet'] = array(
         'name' => 'codesnippet',
+        'module' => 'ckeditor',
         'desc' => t('Plugin for inserting Code Snippets. See <a href="@ckdocs-codesnippet">addon page</a> for more details. See <a href="@ckdocs-codesnippet-help">help</a> for additional instructions.',
           array(
             '@ckdocs-codesnippet' => 'http://ckeditor.com/addon/codesnippet',
@@ -99,6 +106,7 @@ function ckeditor_ckeditor_plugin() {
       );
       $plugins['mathjax'] = array(
         'name' => 'mathjax',
+        'module' => 'ckeditor',
         'desc' => t('Plugin for inserting Mathematical Formula (MathJax). See <a href="@ckdocs-mathjax">addon page</a> for more details. See <a href="@ckdocs-mathjax-help">help</a> for additional instructions.',
           array(
             '@ckdocs-mathjax' => 'http://ckeditor.com/addon/mathjax',
@@ -115,6 +123,7 @@ function ckeditor_ckeditor_plugin() {
       );
       $plugins['image2'] = array(
         'name' => 'image2',
+        'module' => 'ckeditor',
         'desc' => t('Enhanced Image plugin. See <a href="@ckdocs-image2">addon page</a> for more details.',
           array('@ckdocs-image2' => 'http://ckeditor.com/addon/image2')
         ),
diff --git a/includes/ckeditor.lib.inc b/includes/ckeditor.lib.inc
index 2053baa..af0dd3c 100644
--- a/includes/ckeditor.lib.inc
+++ b/includes/ckeditor.lib.inc
@@ -332,7 +332,16 @@ function ckeditor_scayt_langcode($lang) {
  * @return array
  */
 function ckeditor_load_plugins($render = FALSE) {
-  $plugins = module_invoke_all('ckeditor_plugin');
+  $plugins = array();
+  foreach (module_implements('ckeditor_plugin') as $module) {
+    if (function_exists($function = $module . '_ckeditor_plugin')) {
+      if ($module_plugins = $function()) {
+        foreach ($module_plugins as $name => $plugin) {
+          $plugins[$name] = array('module' => $module) + $plugin;
+        }
+      }
+    }
+  }
 
   // [#2159403] introduced a slight change in CKEditor API, expecting the path
   // to a plugin returned by hook_ckeditor_plugin() to be a full URL. This
@@ -360,14 +369,16 @@ function ckeditor_load_plugins($render = FALSE) {
  */
 function ckeditor_plugins_render($plugins) {
   $render = array();
+  $render["%conf_path%"] = base_path() . conf_path() . '/';
   $render["%base_path%"] = ckeditor_base_path('relative') . '/';
   $render["%editor_path%"] = ckeditor_path('relative') . '/';
   $render["%module_path%"] = ckeditor_module_path('relative') . '/';
   $render["%plugin_dir%"] = $render["%module_path%"] . 'plugins/';
   $render["%plugin_dir_extra%"] = ckeditor_plugins_path('relative') . '/';
 
-  foreach ((array) $plugins as $i => $plugin) {
-    $plugins[$i]['path'] = str_replace(array_keys($render), array_values($render), $plugin['path']);
+  foreach ((array) $plugins as $name => $plugin) {
+    $render["%plugin_module_path%"] = !empty($plugin['module']) ? base_path() . drupal_get_path('module', $plugin['module']) . '/' : '%plugin_module_path%';
+    $plugins[$name]['path'] = str_replace(array_keys($render), array_values($render), $plugin['path']);
   }
 
   return $plugins;
-- 
1.8.3.msysgit.0

