From 48b76ced35af569e387f0570271b260fefcdaca3 Mon Sep 17 00:00:00 2001
From: Chris Leppanen <chris.leppanen@gmail.com>
Date: Fri, 16 Nov 2012 17:11:57 -0800
Subject: [PATCH] Issue #1843146 by twistor: Add pluginType() method to be able
 to determine the plugin type without having to lookup the inheritance.

---
 includes/FeedsConfigurable.inc | 9 ++++++---
 plugins/FeedsFetcher.inc       | 7 +++++++
 plugins/FeedsParser.inc        | 7 +++++++
 plugins/FeedsPlugin.inc        | 8 ++++++++
 plugins/FeedsProcessor.inc     | 8 ++++++++
 5 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/includes/FeedsConfigurable.inc b/includes/FeedsConfigurable.inc
index 0f3b013c..05300135 100644
--- a/includes/FeedsConfigurable.inc
+++ b/includes/FeedsConfigurable.inc
@@ -136,7 +136,7 @@ abstract class FeedsConfigurable {
   }
 
   /**
-   * Override magic method __get(). Make sure that $this->config goes through 
+   * Override magic method __get(). Make sure that $this->config goes through
    * getConfig().
    */
   public function __get($name) {
@@ -265,6 +265,8 @@ function feeds_form_submit($form, &$form_state) {
 
 /**
  * Helper for Feeds validate and submit callbacks.
+ *
+ * @todo This is all terrible. Remove.
  */
 function _feeds_form_helper($form, &$form_state, $action) {
   $method = $form['#feeds_form_method'] . $action;
@@ -277,12 +279,13 @@ function _feeds_form_helper($form, &$form_state, $action) {
   // This will re-initialize all of the plugins anyway, causing some tricky
   // saving issues in certain cases.
   // See http://drupal.org/node/1672880.
-
   if ($class == variable_get('feeds_importer_class', 'FeedsImporter')) {
     $form['#configurable'] = feeds_importer($id);
   }
   else {
-    $form['#configurable'] = feeds_plugin($class, $id);
+    $importer = feeds_importer($id);
+    $plugin_key = $importer->config[$form['#configurable']->pluginType()]['plugin_key'];
+    $form['#configurable'] = feeds_plugin($plugin_key, $id);
   }
 
   if (method_exists($form['#configurable'], $method)) {
diff --git a/plugins/FeedsFetcher.inc b/plugins/FeedsFetcher.inc
index 4bba44d0..faca8639 100644
--- a/plugins/FeedsFetcher.inc
+++ b/plugins/FeedsFetcher.inc
@@ -113,6 +113,13 @@ class FeedsFetcherResult extends FeedsResult {
  */
 abstract class FeedsFetcher extends FeedsPlugin {
 
+  /**
+   * Implements FeedsPlugin::pluginType().
+   */
+  public static function pluginType() {
+    return 'fetcher';
+  }
+
   /**
    * Fetch content from a source and return it.
    *
diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc
index c4923170..d63ea432 100644
--- a/plugins/FeedsParser.inc
+++ b/plugins/FeedsParser.inc
@@ -53,6 +53,13 @@ class FeedsParserResult extends FeedsResult {
  */
 abstract class FeedsParser extends FeedsPlugin {
 
+  /**
+   * Implements FeedsPlugin::pluginType().
+   */
+  public static function pluginType() {
+    return 'parser';
+  }
+
   /**
    * Parse content fetched by fetcher.
    *
diff --git a/plugins/FeedsPlugin.inc b/plugins/FeedsPlugin.inc
index be833930..97953ff2 100644
--- a/plugins/FeedsPlugin.inc
+++ b/plugins/FeedsPlugin.inc
@@ -29,6 +29,14 @@ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInter
     $this->source_config = $this->sourceDefaults();
   }
 
+  /**
+   * Returns the type of plugin.
+   *
+   * @return string
+   *   One of either 'fetcher', 'parser', or 'processor'.
+   */
+  abstract public static function pluginType();
+
   /**
    * Save changes to the configuration of this object.
    * Delegate saving to parent (= Feed) which will collect
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index bc503ca7..33397f73 100755
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -28,6 +28,14 @@ class FeedsAccessException extends Exception {}
  * Abstract class, defines interface for processors.
  */
 abstract class FeedsProcessor extends FeedsPlugin {
+
+  /**
+   * Implements FeedsPlugin::pluginType().
+   */
+  public static function pluginType() {
+    return 'processor';
+  }
+
   /**
    * @defgroup entity_api_wrapper Entity API wrapper.
    */
-- 
GitLab