diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc index 519dfc5..010d11e 100644 --- a/plugins/FeedsNodeProcessor.inc +++ b/plugins/FeedsNodeProcessor.inc @@ -30,6 +30,7 @@ class FeedsNodeProcessor extends FeedsProcessor { * Creates a new node in memory and returns it. */ protected function newEntity(FeedsSource $source) { + $source_node = FALSE; $node = new stdClass(); $node->type = $this->bundle(); $node->changed = REQUEST_TIME; @@ -40,6 +41,15 @@ class FeedsNodeProcessor extends FeedsProcessor { // Populate properties that are set by node_object_prepare(). $node->log = 'Created by FeedsNodeProcessor'; $node->uid = $this->config['author']; + + if ($source->feed_nid && $this->config['inherit']) { + $source_node = node_load($source->feed_nid); + } + if ($source_node) { + foreach ($this->config['inherit_fields'] as $id) { + $node->{$id} = $source_node->{$id}; + } + } return $node; } @@ -172,6 +182,8 @@ class FeedsNodeProcessor extends FeedsProcessor { return array( 'expire' => FEEDS_EXPIRE_NEVER, 'author' => 0, + 'inherit' => 0, + 'inherit_fields' => array(), 'authorize' => TRUE, ) + parent::configDefaults(); } @@ -204,6 +216,56 @@ class FeedsNodeProcessor extends FeedsProcessor { '#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); + if (isset($importer->config['content_type']) && $this->bundle()) { + $form['inherit'] = array( + '#type' => 'checkbox', + '#title' => t('Inherit properties from feeds node'), + '#description' => t('Passes properties from the feeds node to any nodes that are created.'), + '#default_value' => $this->config['inherit'], + ); + + // Add node fields to those we can inherit. + $fields = array(); + $node = new stdClass(); + $node->type = $importer->config['content_type']; + $node->changed = REQUEST_TIME; + $node->created = REQUEST_TIME; + $node->language = NULL; + node_object_prepare($node); + foreach ($node as $id => $v) { + if ($id == 'type') { + continue; + } + $fields[$id] = $id; + } + + // Add fields module fields to those we can inherit. + $instances = field_info_instances('node', $importer->config['content_type']); + $node_instances = field_info_instances('node', $this->bundle()); + foreach ($instances as $id => $field) { + // Make sure the target node type also has this field. + if (isset($node_instances[$id])) { + $fields[$id] = $id; + } + } + + $form['inherit_fields'] = array( + '#type' => 'select', + '#title' => t('Inherit fields'), + '#description' => t('Select the fields that you would like created nodes to inherit from the feeds node.'), + '#options' => $fields, + '#default_value' => $this->config['inherit_fields'], + '#multiple' => TRUE, + '#states' => array( + 'invisible' => array( + 'input[name="inherit"]' => array('checked' => FALSE), + ), + ), + ); + } return $form; }