diff --git a/feeds.module b/feeds.module index 9d9f6ed6d8f0d5785670f66135db3c4e89d07048..e74582e1401f251f37df12b39fb06ca1e168c7f9 100644 --- a/feeds.module +++ b/feeds.module @@ -1011,22 +1011,21 @@ function feeds_source($importer_id, $feed_nid = 0) { /** * Gets an instance of a class for a given plugin and id. * - * @param $plugin + * @param string $plugin * A string that is the key of the plugin to load. - * @param $id + * @param string $id * A string that is the id of the object. * - * @return + * @return FeedsPlugin * A FeedsPlugin object. - * - * @throws Exception - * If plugin can't be instantiated. */ function feeds_plugin($plugin, $id) { ctools_include('plugins'); + if ($class = ctools_plugin_load_class('feeds', 'plugins', $plugin, 'handler')) { - return FeedsConfigurable::instance($class, $id); + return FeedsPlugin::instance($class, $id, ctools_get_plugins('feeds', 'plugins', $plugin)); } + $args = array('%plugin' => $plugin, '@id' => $id); if (user_access('administer feeds')) { $args['@link'] = url('admin/structure/feeds/' . $id); @@ -1035,8 +1034,10 @@ function feeds_plugin($plugin, $id) { else { drupal_set_message(t('Missing Feeds plugin %plugin. Please contact your site administrator.', $args), 'warning', FALSE); } + $class = ctools_plugin_load_class('feeds', 'plugins', 'FeedsMissingPlugin', 'handler'); - return FeedsConfigurable::instance($class, $id); + + return FeedsPlugin::instance($class, $id); } /** diff --git a/plugins/FeedsPlugin.inc b/plugins/FeedsPlugin.inc index cfe3ecfd01f734d0b803c5a0d49d7ef021e45731..ec489a89d8e50fba7f14870d067e607a52e00389 100644 --- a/plugins/FeedsPlugin.inc +++ b/plugins/FeedsPlugin.inc @@ -19,6 +19,47 @@ class FeedsResult {} */ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInterface { + /** + * The plugin definition. + * + * @var array + */ + protected $pluginDefinition; + + /** + * Constructs a FeedsPlugin object. + * + * @param string $id + * The plugin id. + * @param array $plugin_definition + * The plugin definition. + */ + protected function __construct($id, array $plugin_definition) { + $this->pluginDefinition = $plugin_definition; + parent::__construct($id); + } + + /** + * Instantiates a FeedsPlugin object. + * + * Don't use directly, use feeds_plugin() instead. + * + * @see feeds_plugin() + */ + public static function instance($class, $id, array $plugin_definition = array()) { + if (!strlen($id)) { + throw new InvalidArgumentException(t('Empty configuration identifier.')); + } + + static $instances = array(); + + if (!isset($instances[$class][$id])) { + $instances[$class][$id] = new $class($id, $plugin_definition); + } + + return $instances[$class][$id]; + } + /** * Returns the type of plugin. * @@ -36,9 +77,7 @@ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInter * @see ctools_get_plugins() */ public function pluginDefinition() { - $importer = feeds_importer($this->id); - $plugin_key = $importer->config[$this->pluginType()]['plugin_key']; - return ctools_get_plugins('feeds', 'plugins', $plugin_key); + return $this->pluginDefinition; } /**