diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc index 0087d2d..05e6ae2 100644 --- a/plugins/FeedsNodeProcessor.inc +++ b/plugins/FeedsNodeProcessor.inc @@ -168,10 +168,12 @@ public function expiryTime() { */ public function configDefaults() { return array( - 'expire' => FEEDS_EXPIRE_NEVER, - 'author' => 0, - 'authorize' => TRUE, - ) + parent::configDefaults(); + 'expire' => FEEDS_EXPIRE_NEVER, + 'author' => 0, + 'inherit_properties' => FALSE, + 'inherited_properties' => array(), + 'authorize' => TRUE, + ) + parent::configDefaults(); } /** @@ -202,6 +204,47 @@ public function configForm(&$form_state) { '#description' => t("Select after how much time nodes should be deleted. The node's published date will be used for determining the node's age, see Mapping settings."), '#default_value' => $this->config['expire'], ); + + // Inherit options are only available if the importer is attached to a node. + $importer = feeds_importer($this->id); + // TODO Referesh inhertiable properties list with AJAX. + if (isset($importer->config['content_type']) && $this->bundle()) { + $form['inherit_properties'] = array( + '#type' => 'checkbox', + '#title' => t('Inherit properties from attached feed node'), + '#description' => t('Allow imported nodes to inherit properties from the feed node.'), + '#default_value' => $this->config['inherit_properties'], + ); + + $node = new stdClass(); + $node->type = $importer->config['content_type']; + $node->is_new = TRUE; + node_object_prepare($node); + $node = (array) $node; + $properties = drupal_map_assoc(array_keys($node)); + // These properties should not be inherited. + unset($properties['is_new']); + unset($properties['type']); + // Add common fields to inheritable properties. + $feed_node_fields = array_keys(field_info_instances('node', $importer->config['content_type'])); + $target_node_fields = array_keys(field_info_instances('node', $this->bundle())); + $properties += drupal_map_assoc(array_intersect($target_node_fields, $feed_node_fields)); + + $form['inherited_properties'] = array( + '#type' => 'select', + '#title' => t('Inherit properties'), + '#description' => t('Selected properties of the feed node which should be inherited by any imported node.'), + '#options' => $properties, + '#default_value' => $this->config['inherited_properties'], + '#multiple' => TRUE, + '#states' => array( + 'invisible' => array( + 'input[name="inherit_properties"]' => array('checked' => FALSE), + ), + ), + ); + } + // Add on the "Unpublish" option for nodes, update wording. if (isset($form['update_non_existent'])) { $form['update_non_existent']['#options'][FEEDS_UNPUBLISH_NON_EXISTENT] = t('Unpublish non-existent nodes'); @@ -416,4 +459,22 @@ protected function clean(FeedsState $state) { } } + /** + * Overrides FeedsProcessor::map(). + * + * Allows imported nodes to inherit properties from feed node. + */ + protected function map(FeedsSource $source, FeedsParserResult $result, $target_item = NULL) { + $target_item = parent::map($source, $result, $target_item); + if ($this->config['inherit_properties'] && $source->feed_nid) { + $source_node = node_load($source->feed_nid); + if ($source_node) { + foreach ($this->config['inherited_properties'] as $id) { + $target_item->{$id} = $source_node->{$id}; + } + } + } + return $target_item; + } + }