Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save orakili/3718694 to your computer and use it in GitHub Desktop.
Save orakili/3718694 to your computer and use it in GitHub Desktop.
Drupal 7 - Feeds 2.0-alpha5 - Patch combining #1001590 and #1665450 - path aliases
diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc
index 2df4b35..06e5ae9 100644
--- a/plugins/FeedsNodeProcessor.inc
+++ b/plugins/FeedsNodeProcessor.inc
@@ -219,6 +219,22 @@ class FeedsNodeProcessor extends FeedsProcessor {
$target_node->feeds['suppress_import'] = TRUE;
}
break;
+ case 'path_alias':
+ $target_node->path = array();
+
+ // Check for existing aliases.
+ if (!empty($target_node->nid)) {
+ if ($path = path_load('node/' . $target_node->nid)) {
+ $target_node->path = $path;
+ }
+ }
+
+ // Prevent Pathauto (http://drupal.org/project/pathauto) from
+ // overwriting the alias.
+ $target_node->path['pathauto'] = FALSE;
+
+ $target_node->path['alias'] = $value;
+ break;
default:
parent::setTargetElement($source, $target_node, $target_element, $value);
break;
@@ -280,6 +296,13 @@ class FeedsNodeProcessor extends FeedsProcessor {
);
}
+ // If path is enabled expose path alias.
+ if (module_exists('path')) {
+ $targets['path_alias'] = array(
+ 'name' => t('Path alias'),
+ 'description' => t('URL path alias of the node.'),
+ );
+ }
// If the target content type is a Feed node, expose its source field.
if ($id = feeds_get_importer_id($this->config['content_type'])) {
diff --git a/plugins/FeedsTermProcessor.inc b/plugins/FeedsTermProcessor.inc
index 83183b0..56f35ed 100644
--- a/plugins/FeedsTermProcessor.inc
+++ b/plugins/FeedsTermProcessor.inc
@@ -168,6 +168,22 @@ class FeedsTermProcessor extends FeedsProcessor {
}
$target_node->weight = $weight;
break;
+ case 'path_alias':
+ $target_term->path = array();
+
+ // Check for existing aliases.
+ if (!empty($target_term->tid)) {
+ if ($path = path_load('taxonomy/term/' . $target_term->tid)) {
+ $target_term->path = $path;
+ }
+ }
+
+ // Prevent Pathauto (http://drupal.org/project/pathauto) from
+ // overwriting the alias.
+ $target_term->path['pathauto'] = FALSE;
+
+ $target_term->path['alias'] = $value;
+ break;
default:
parent::setTargetElement($source, $target_node, $target_element, $value);
break;
@@ -205,6 +221,15 @@ class FeedsTermProcessor extends FeedsProcessor {
'description' => t('Description of the taxonomy term.'),
),
);
+
+ // If path is enabled expose path alias.
+ if (module_exists('path')) {
+ $targets['path_alias'] = array(
+ 'name' => t('Path alias'),
+ 'description' => t('URL path alias for the taxonomy term.'),
+ );
+ }
+
// Let implementers of hook_feeds_term_processor_targets() add their targets.
try {
self::loadMappers();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment