diff --git a/feeds.info b/feeds.info index 79134ac..1d924de 100644 --- a/feeds.info +++ b/feeds.info @@ -33,3 +33,4 @@ files[] = views/feeds_views_handler_field_log_message.inc files[] = views/feeds_views_handler_field_severity.inc files[] = views/feeds_views_handler_field_source.inc files[] = views/feeds_views_handler_filter_severity.inc +files[] = plugins/FeedsEntityProcessor.inc diff --git a/feeds.module b/feeds.module index 2084b78..7478887 100644 --- a/feeds.module +++ b/feeds.module @@ -915,9 +915,11 @@ function feeds_source($importer_id, $feed_nid = 0) { */ function feeds_plugin($plugin, $id) { ctools_include('plugins'); + if ($class = ctools_plugin_load_class('feeds', 'plugins', $plugin, 'handler')) { return FeedsConfigurable::instance($class, $id); } + $args = array('%plugin' => $plugin, '@id' => $id); if (user_access('administer feeds')) { $args['@link'] = url('admin/structure/feeds/' . $id); @@ -1140,20 +1142,8 @@ function feeds_get_subscription_jobs() { * Implements hook_entity_property_info_alter(). */ function feeds_entity_property_info_alter(&$info) { - // Gather entities supported by Feeds processors. - $processors = FeedsPlugin::byType('processor'); - $supported_entities = array(); - foreach ($processors as $processor) { - $instance = feeds_plugin($processor['handler']['class'], '__none__'); - if (method_exists($instance, 'entityType')) { - $supported_entities[] = $instance->entityType(); - } - } - // Feeds processors can fake the entity info. Only set the property for - // defined entities. - $supported_entities = array_intersect(array_keys($info), $supported_entities); - - foreach ($supported_entities as $entity_type) { + // Add the feed_nid property to all entities. + foreach ($info as $entity_type => $entity_info) { $info[$entity_type]['properties']['feed_nid'] = array( 'label' => 'Feed NID', 'type' => 'integer', diff --git a/feeds.plugins.inc b/feeds.plugins.inc index 3f23cb8..432bff0 100644 --- a/feeds.plugins.inc +++ b/feeds.plugins.inc @@ -140,6 +140,29 @@ function _feeds_feeds_plugins() { 'path' => $path, ), ); + if (module_exists('entity')) { + foreach (entity_get_info() as $type => $entity_info) { + // @todo: test for saving and whatever else necessary? + if (entity_type_supports($type, 'create')) { + $info['FeedsEntityProcessor' . drupal_ucfirst($type)] = array( + 'name' => 'Entity processor ' . $entity_info['label'], + // @todo: Use plural label if there. + 'description' => 'Create and update ' . $entity_info['label'] . 's.', + 'help' => 'Create and update ' . $entity_info['label'] . 's from parsed content.', + 'plugin_key' => 'FeedsEntityProcessor', + 'handler' => array( + 'parent' => 'FeedsProcessor', + 'class' => 'FeedsEntityProcessor', + 'file' => 'FeedsEntityProcessor.inc', + 'path' => $path, + ), + // Add in the entity type used. + // @see FeedsEntityProcessor::entityType() + 'type' => $type, + ); + } + } + } $info['FeedsUserProcessor'] = array( 'name' => 'User processor', 'description' => 'Create users.', diff --git a/feeds_ui/feeds_ui.admin.inc b/feeds_ui/feeds_ui.admin.inc index 1799fe5..ab99e34 100644 --- a/feeds_ui/feeds_ui.admin.inc +++ b/feeds_ui/feeds_ui.admin.inc @@ -430,6 +430,7 @@ function feeds_ui_plugin_form($form, &$form_state, $importer, $type) { $form = array(); $form['#importer'] = $importer->id; $form['#plugin_type'] = $type; + $config = $importer->getConfig(); foreach ($plugins as $key => $plugin) { $form['plugin_key'][$key] = array( @@ -438,7 +439,7 @@ function feeds_ui_plugin_form($form, &$form_state, $importer, $type) { '#title' => check_plain($plugin['name']), '#description' => filter_xss(isset($plugin['help']) ? $plugin['help'] : $plugin['description']), '#return_value' => $key, - '#default_value' => ($plugin['handler']['class'] == get_class($importer->$type)) ? $key : '', + '#default_value' => ($key == $config[$type]['plugin_key']) ? $key : '', ); } $form['submit'] = array( diff --git a/includes/FeedsConfigurable.inc b/includes/FeedsConfigurable.inc index 0f3b013..d15a9ce 100644 --- a/includes/FeedsConfigurable.inc +++ b/includes/FeedsConfigurable.inc @@ -268,8 +268,8 @@ function feeds_form_submit($form, &$form_state) { */ function _feeds_form_helper($form, &$form_state, $action) { $method = $form['#feeds_form_method'] . $action; - $class = get_class($form['#configurable']); $id = $form['#configurable']->id; + $class = get_class($form['#configurable']); // Re-initialize the configurable object. Using feeds_importer() and // feeds_plugin() will ensure that we're using the same instance. We can't @@ -277,12 +277,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 4bba44d..e25e13c 100644 --- a/plugins/FeedsFetcher.inc +++ b/plugins/FeedsFetcher.inc @@ -112,7 +112,9 @@ class FeedsFetcherResult extends FeedsResult { * Implements FeedsSourceInfoInterface to expose source forms to Feeds. */ abstract class FeedsFetcher extends FeedsPlugin { - + public function pluginType() { + return 'fetcher'; + } /** * Fetch content from a source and return it. * diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc index 5cdac88..2c3a6df 100644 --- a/plugins/FeedsParser.inc +++ b/plugins/FeedsParser.inc @@ -52,6 +52,9 @@ class FeedsParserResult extends FeedsResult { * Abstract class, defines interface for parsers. */ abstract class FeedsParser extends FeedsPlugin { + public function pluginType() { + return 'parser'; + } /** * Parse content fetched by fetcher. diff --git a/plugins/FeedsPlugin.inc b/plugins/FeedsPlugin.inc index be83393..1a43f49 100644 --- a/plugins/FeedsPlugin.inc +++ b/plugins/FeedsPlugin.inc @@ -18,6 +18,7 @@ class FeedsResult {} * an object that is being passed into a Feed object and its plugins. */ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInterface { + abstract public function pluginType(); /** * Constructor. @@ -206,6 +207,9 @@ class FeedsMissingPlugin extends FeedsPlugin { public function menuItem() { return array(); } + public function pluginType() { + return 'missing'; + } } /** diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc index dab37ed..cf078ee 100644 --- a/plugins/FeedsProcessor.inc +++ b/plugins/FeedsProcessor.inc @@ -93,6 +93,10 @@ abstract class FeedsProcessor extends FeedsPlugin { /** * @} */ + + public function pluginType() { + return 'processor'; + } /** * Process the result of the parsing stage. @@ -358,9 +362,8 @@ abstract class FeedsProcessor extends FeedsPlugin { if (!isset($sources[$this->id])) { $sources[$this->id] = feeds_importer($this->id)->parser->getMappingSources(); } - static $targets; - if (!isset($targets[$this->id])) { - $targets[$this->id] = $this->getMappingTargets(); + if (!isset($this->targets)) { + $this->targets = $this->getMappingTargets(); } $parser = feeds_importer($this->id)->parser; if (empty($target_item)) { @@ -403,11 +406,11 @@ abstract class FeedsProcessor extends FeedsPlugin { } // Map the source element's value to the target. - if (isset($targets[$this->id][$mapping['target']]) && - is_array($targets[$this->id][$mapping['target']]) && - isset($targets[$this->id][$mapping['target']]['callback']) && - function_exists($targets[$this->id][$mapping['target']]['callback'])) { - $callback = $targets[$this->id][$mapping['target']]['callback']; + if (isset($this->targets[$mapping['target']]) && + is_array($this->targets[$mapping['target']]) && + isset($this->targets[$mapping['target']]['callback']) && + function_exists($this->targets[$mapping['target']]['callback'])) { + $callback = $this->targets[$mapping['target']]['callback']; $callback($source, $target_item, $mapping['target'], $value, $mapping); } else { @@ -507,7 +510,7 @@ abstract class FeedsProcessor extends FeedsPlugin { * * @ingroup mappingapi */ - public function setTargetElement(FeedsSource $source, $target_item, $target_element, $value) { + public function setTargetElement(FeedsSource $source, $target_item, $target_element, $value, $mapping) { switch ($target_element) { case 'url': case 'guid':