You are here

function path_feeds_set_target in Feeds 8.2

Same name and namespace in other branches
  1. 7.2 mappers/path.inc \path_feeds_set_target()

Callback for mapping. Here is where the actual mapping happens.

When the callback is invoked, $target contains the name of the field the user has decided to map to and $value contains the value of the feed item element the user has picked as a source.

1 string reference to 'path_feeds_set_target'
path_feeds_processor_targets_alter in mappers/path.inc
Implements hook_feeds_processor_targets_alter().

File

mappers/path.inc, line 36
On behalf implementation of Feeds mapping API for path.module.

Code

function path_feeds_set_target($source, $entity, $target, $value, $mapping) {
  if (empty($value)) {
    $value = '';
  }

  // Path alias cannot be multi-valued, so use the first value.
  if (is_array($value)) {
    $value = $value[0];
  }
  $entity->path = array();
  if ($entity
    ->id()) {
    $uri = $entity
      ->uri();

    // Check for existing aliases.
    if ($path = path_load($uri['path'])) {
      $entity->path = $path;
    }
  }
  $entity->path['pathauto'] = FALSE;

  // Allow pathauto to set the path alias if the option is set, and this value
  // is empty.
  if (!empty($mapping['pathauto_override']) && !$value) {
    $entity->path['pathauto'] = TRUE;
  }
  else {
    $entity->path['alias'] = ltrim($value, '/');
  }
}