diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc index 0087d2d..c5eab23 100644 --- a/plugins/FeedsNodeProcessor.inc +++ b/plugins/FeedsNodeProcessor.inc @@ -45,6 +45,15 @@ class FeedsNodeProcessor extends FeedsProcessor { // Populate properties that are set by node_object_prepare(). $node->log = 'Created by FeedsNodeProcessor'; $node->uid = $this->config['author']; + $source_node = FALSE; + 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; } @@ -170,6 +179,8 @@ class FeedsNodeProcessor extends FeedsProcessor { return array( 'expire' => FEEDS_EXPIRE_NEVER, 'author' => 0, + 'inherit' => 0, + 'inherit_fields' => array(), 'authorize' => TRUE, ) + parent::configDefaults(); } @@ -202,6 +213,57 @@ 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), + ), + ), + ); + } + // 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');