From 79918b8f89220301a656b9d2166f32a34a123df6 Mon Sep 17 00:00:00 2001
From: twistor <twistor@473738.no-reply.drupal.org>
Date: Mon, 1 Jun 2015 10:48:17 -0700
Subject: [PATCH] Issue #2497507 by twistor: Pass plugin definition to
 FeedsPlugin objects

---
 plugins/FeedsPlugin.inc | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/plugins/FeedsPlugin.inc b/plugins/FeedsPlugin.inc
index 4bad07e1..2629fb9e 100644
--- a/plugins/FeedsPlugin.inc
+++ b/plugins/FeedsPlugin.inc
@@ -29,14 +29,16 @@ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInter
   /**
    * Constructs a FeedsPlugin object.
    *
+   * A copy of FeedsConfigurable::__construct() that doesn't call
+   * configDefaults() so that we avoid circular dependencies.
+   *
    * @param string $id
-   *   The plugin id.
-   * @param array $plugin_definition
-   *   The plugin definition.
+   *   The importer id.
    */
-  protected function __construct($id, array $plugin_definition) {
-    $this->pluginDefinition = $plugin_definition;
-    parent::__construct($id);
+  protected function __construct($id) {
+    $this->id = $id;
+    $this->export_type = FEEDS_EXPORT_NONE;
+    $this->disabled = FALSE;
   }
 
   /**
@@ -54,7 +56,13 @@ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInter
     static $instances = array();
 
     if (!isset($instances[$class][$id])) {
-      $instances[$class][$id] = new $class($id, $plugin_definition);
+      $instance = new $class($id);
+
+      // The ordering here is important. The plugin definition should be usable
+      // in getConfig().
+      $instance->setPluginDefinition($plugin_definition);
+      $instance->setConfig($instance->configDefaults());
+      $instances[$class][$id] = $instance;
     }
 
     return $instances[$class][$id];
@@ -80,6 +88,18 @@ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInter
     return $this->pluginDefinition;
   }
 
+  /**
+   * Sets the plugin definition.
+   *
+   * This is protected since we're only using it in FeedsPlugin::instance().
+   *
+   * @param array $plugin_definition
+   *   The plugin definition.
+   */
+  protected function setPluginDefinition(array $plugin_definition) {
+    $this->pluginDefinition = $plugin_definition;
+  }
+
   /**
    * Save changes to the configuration of this object.
    * Delegate saving to parent (= Feed) which will collect
-- 
GitLab