diff --git a/feeds.info b/feeds.info index 8041cbf..fbb66b1 100644 --- a/feeds.info +++ b/feeds.info @@ -14,6 +14,7 @@ files[] = libraries/PuSHSubscriber.inc ; Plugins files[] = plugins/FeedsCSVParser.inc +files[] = plugins/FeedsEntityProcessor.inc files[] = plugins/FeedsFetcher.inc files[] = plugins/FeedsFileFetcher.inc files[] = plugins/FeedsHTTPFetcher.inc diff --git a/feeds.module b/feeds.module index f581d3f..903aaaa 100644 --- a/feeds.module +++ b/feeds.module @@ -1165,20 +1165,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) { + foreach ($info as $entity_type => $entity_info) { $info[$entity_type]['properties']['feed_nid'] = array( 'label' => 'Feed NID', 'type' => 'integer', @@ -1249,3 +1237,67 @@ function feeds_api_version() { $version = feeds_ctools_plugin_api('feeds', 'plugins'); return $version['version']; } + +function node_form_feedsentityprocessor_feeds_form_alter(&$form, &$form_state) { + if ($form['#configurable']->entityType() == 'node') { + unset($form['values']['title']); + $form['values']['author']['#required'] = FALSE; + $form['values']['author']['#autocomplete_path'] = 'user/autocomplete'; + array_unshift($form['#validate'], 'node_form_feedsentityprocessor_feeds_form_validate'); + if (is_numeric($form['values']['author']['#default_value']) && + $account = user_load($form['values']['author']['#default_value'])) { + $form['values']['author']['#default_value'] = $account->name; + } + } +} + +function node_form_feedsentityprocessor_feeds_form_validate(&$form, &$form_state) { + if (empty($form_state['values']['values']['author'])) { + form_set_value($form['values']['author'], 0, $form_state); + } + else { + $account = user_load_by_name($form_state['values']['values']['author']); + if ($account) { + form_set_value($form['values']['author'], $account->uid, $form_state); + } + } +} + +function node_feeds_processor_targets_alter(&$targets, $entity_type, $bundle) { + if ($entity_type == 'node') { + $targets['nid']['name'] = t('Node id'); + $targets['nid']['description'] = t('The nid of the node. NOTE: use this feature with care, node ids are usually assigned by Drupal.'); + } +} + +function user_form_feedsentityprocessor_feeds_form_alter(&$form, &$form_state) { + if ($form['#configurable']->entityType() == 'user') { + unset($form['values']['name']); + $form['values']['mail']['#required'] = FALSE; + } +} + +function taxonomy_form_feedsentityprocessor_feeds_form_alter(&$form, &$form_state) { + if ($form['#configurable']->entityType() == 'taxonomy_term') { + unset($form['values']['name']); + if (empty($form['values']['weight']['#default_value'])) { + $form['values']['weight']['#default_value']= ''; + } + array_unshift($form['#validate'], 'taxonomy_form_feedsentityprocessor_feeds_form_validate'); + unset($form['values']['parent']); + $form['values']['machine_name'] = $form['values']['vocabulary']; + $form['values']['vocabulary']['#access'] = FALSE; + } + elseif ($form['#configurable']->entityType() == 'taxonomy_vocabulary') { + unset($form['values']['name']); + unset($form['values']['machine_name']); + unset($form['values']['vid']); + } +} + +function taxonomy_form_feedsentityprocessor_feeds_form_validate(&$form, &$form_state) { + if (empty($form_state['values']['values']['weight'])) { + form_set_value($form['values']['weight'], 0, $form_state); + } + form_set_value($form['values']['vocabulary'], $form_state['values']['values']['machine_name'], $form_state); +} diff --git a/feeds.plugins.inc b/feeds.plugins.inc index c7d5d81..1e87d3f 100644 --- a/feeds.plugins.inc +++ b/feeds.plugins.inc @@ -166,5 +166,30 @@ function _feeds_feeds_plugins() { ), ); } + 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'] . ' - EXPERIMENTAL', + // @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. + This processor is still experimental. Test throughly before using in a + production environment.', + '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, + ); + } + } + } return $info; } diff --git a/mappers/taxonomy.inc b/mappers/taxonomy.inc index 02ac54e..a8e4c48 100644 --- a/mappers/taxonomy.inc +++ b/mappers/taxonomy.inc @@ -70,6 +70,11 @@ function taxonomy_feeds_processor_targets_alter(&$targets, $entity_type, $bundle ); } } + if ($entity_type == 'taxonomy_term') { + $targets['tid']['name'] = t('Term id'); + $targets['tid']['description'] = t('The tid of the taxonomy term. NOTE: use this feature with care, node ids are usually assigned by Drupal.'); + unset($targets['vocabulary']); + } } /** diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc index 13fcaa0..5f58224 100644 --- a/plugins/FeedsParser.inc +++ b/plugins/FeedsParser.inc @@ -63,7 +63,7 @@ abstract class FeedsParser extends FeedsPlugin { /** * Parse content fetched by fetcher. * - * Extending classes must implement this method. + * `Extending classes must implement this method. * * @param FeedsSource $source * Source information. diff --git a/plugins/FeedsPlugin.inc b/plugins/FeedsPlugin.inc index 259eedb..fbce296 100644 --- a/plugins/FeedsPlugin.inc +++ b/plugins/FeedsPlugin.inc @@ -38,6 +38,20 @@ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInter abstract public function pluginType(); /** + * Returns the plugin definition. + * + * @return array + * The plugin definition array. + * + * @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); + } + + /** * Save changes to the configuration of this object. * Delegate saving to parent (= Feed) which will collect * information from this object by way of getConfig() and store it. diff --git a/views/feeds.views.inc b/views/feeds.views.inc index 01ba7d4..0836f0e 100644 --- a/views/feeds.views.inc +++ b/views/feeds.views.inc @@ -166,7 +166,7 @@ function feeds_views_data() { // Add a relationship for each entity type relating the entity's base table // to the feeds_item table whre feeds_item.entity_type = 'entity_type'. - foreach (array('node', 'taxonomy_term', 'user') as $entity_type) { + foreach (array('node', 'taxonomy_term', 'user', 'file') as $entity_type) { $info = entity_get_info($entity_type); $data['feeds_item']['table']['join'][$info['base table']] = array( 'left_field' => $info['entity keys']['id'], @@ -319,6 +319,7 @@ function feeds_views_data() { 'type' => 'LEFT', ), ); - + + return $data; }