From b5b1fc8ccbc556e690d3cad074b29b587bc28d3c Mon Sep 17 00:00:00 2001
From: Gordon Heydon <gordon@heydon.com.au>
Date: Sun, 31 Mar 2013 19:53:24 +1100
Subject: [PATCH 3/5] Add new hook_feeds_defaults()

---
 feeds.api.php                  | 19 +++++++++++++++++++
 includes/FeedsConfigurable.inc |  5 ++++-
 plugins/FeedsCSVParser.inc     |  2 +-
 plugins/FeedsFileFetcher.inc   |  2 +-
 plugins/FeedsHTTPFetcher.inc   |  2 +-
 plugins/FeedsProcessor.inc     |  2 +-
 6 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/feeds.api.php b/feeds.api.php
index 025f08a..7f80dbc 100644
--- a/feeds.api.php
+++ b/feeds.api.php
@@ -356,5 +356,24 @@ function hook_feeds_postsave(FeedsSource $source, FeedsProcessor $processor, Fee
 }
 
 /**
+ * Example of hook_feeds_defaults().
+ *
+ * @param FeedsConfigurable $configurable
+ *  The current configurable item which is being called to add information to.
+ *
+ * @return
+ *  Return an array of default values.
+ */
+function hook_feeds_defaults(FeedsConfigurable $configurable) {
+  if (is_a($configurable, 'FeedsProcessor')) {
+    return array(
+      'purge_unseen_items' => 0,
+      'purge_after_period' => NULL,
+      'purge_delete' => 0,
+    );
+  }
+}
+
+/**
  * @}
  */
diff --git a/includes/FeedsConfigurable.inc b/includes/FeedsConfigurable.inc
index 0530013..c112490 100644
--- a/includes/FeedsConfigurable.inc
+++ b/includes/FeedsConfigurable.inc
@@ -166,7 +166,10 @@ abstract class FeedsConfigurable {
    *   values are their default values.
    */
   public function configDefaults() {
-    return array();
+    $hook = 'feeds_' . get_class($this) . '_defaults';
+    $defaults = array_merge(module_invoke_all($hook, $this), module_invoke_all('feeds_defaults', $this));
+
+    return $defaults;
   }
 
   /**
diff --git a/plugins/FeedsCSVParser.inc b/plugins/FeedsCSVParser.inc
index 7044440..ae6c2f3 100644
--- a/plugins/FeedsCSVParser.inc
+++ b/plugins/FeedsCSVParser.inc
@@ -174,7 +174,7 @@ class FeedsCSVParser extends FeedsParser {
     return array(
       'delimiter' => ',',
       'no_headers' => 0,
-    );
+    )+parent::configDefaults();
   }
 
   /**
diff --git a/plugins/FeedsFileFetcher.inc b/plugins/FeedsFileFetcher.inc
index 5e8e116..552083b 100644
--- a/plugins/FeedsFileFetcher.inc
+++ b/plugins/FeedsFileFetcher.inc
@@ -216,7 +216,7 @@ class FeedsFileFetcher extends FeedsFetcher {
       'direct' => FALSE,
       'directory' => $scheme . '://feeds',
       'allowed_schemes' => $schemes,
-    );
+    )+parent::configDefaults();
   }
 
   /**
diff --git a/plugins/FeedsHTTPFetcher.inc b/plugins/FeedsHTTPFetcher.inc
index 4e7afc7..901c80f 100644
--- a/plugins/FeedsHTTPFetcher.inc
+++ b/plugins/FeedsHTTPFetcher.inc
@@ -108,7 +108,7 @@ class FeedsHTTPFetcher extends FeedsFetcher {
       'use_pubsubhubbub' => FALSE,
       'designated_hub' => '',
       'request_timeout' => NULL,
-    );
+    )+parent::configDefaults();
   }
 
   /**
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index cb4d546..2f22483 100755
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -539,7 +539,7 @@ abstract class FeedsProcessor extends FeedsPlugin {
       'input_format' => NULL,
       'skip_hash_check' => FALSE,
       'bundle' => $bundle,
-    );
+    )+parent::configDefaults();
   }
 
   /**
-- 
1.7.11.3

