public function ConfigEntityReference::setTarget in Feeds 8.3
Sets the values on an object.
Parameters
\Drupal\feeds\FeedInterface $feed: The feed object.
\Drupal\Core\Entity\EntityInterface $entity: The target object.
string $target: The name of the target to set.
array $values: A list of values to set on the target.
Overrides FieldTargetBase::setTarget
1 call to ConfigEntityReference::setTarget()
- UserRole::setTarget in src/
Feeds/ Target/ UserRole.php - Sets the values on an object.
1 method overrides ConfigEntityReference::setTarget()
- UserRole::setTarget in src/
Feeds/ Target/ UserRole.php - Sets the values on an object.
File
- src/
Feeds/ Target/ ConfigEntityReference.php, line 120
Class
- ConfigEntityReference
- Defines a config entity reference mapper.
Namespace
Drupal\feeds\Feeds\TargetCode
public function setTarget(FeedInterface $feed, EntityInterface $entity, $field_name, array $raw_values) {
$values = [];
foreach ($raw_values as $delta => $columns) {
try {
$this
->prepareValue($delta, $columns);
$values[] = $columns;
} catch (ReferenceNotFoundException $e) {
// The referenced entity is not found. We need to enforce Feeds to try
// to import the same item again on the next import.
// Feeds stores a hash of every imported item in order to make the
// import process more efficient by ignoring items it has already seen.
// In this case we need to destroy the hash in order to be able to
// import the reference on a next import.
$entity
->get('feeds_item')->hash = NULL;
$feed
->getState(StateInterface::PROCESS)
->setMessage($e
->getFormattedMessage(), 'warning', TRUE);
} catch (EmptyFeedException $e) {
// Nothing wrong here.
} catch (TargetValidationException $e) {
// Validation failed.
$this
->addMessage($e
->getFormattedMessage(), 'error');
}
}
if (!empty($values)) {
$entity_target = $this
->getEntityTarget($feed, $entity);
if ($entity_target) {
$item_list = $entity_target
->get($field_name);
// Append these values to the existing values.
$values = array_merge($item_list
->getValue(), $values);
$item_list
->setValue($values);
}
}
}