protected function EntityProcessorBase::clearTarget in Feeds 8.3
Clears the target on the entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to clear the target on.
\Drupal\feeds\Plugin\Type\Target\TargetInterface $target: The target plugin.
string $target_name: The property to clear on the entity.
1 call to EntityProcessorBase::clearTarget()
- EntityProcessorBase::map in src/
Feeds/ Processor/ EntityProcessorBase.php - Execute mapping on an item.
File
- src/
Feeds/ Processor/ EntityProcessorBase.php, line 1109
Class
- EntityProcessorBase
- Defines a base entity processor.
Namespace
Drupal\feeds\Feeds\ProcessorCode
protected function clearTarget(EntityInterface $entity, TargetInterface $target, $target_name) {
if (!$target
->isMutable()) {
// Don't clear immutable targets.
return;
}
$entity_target = $entity;
// If the target implements TranslatableTargetInterface and has a language
// configured, empty the value for the targeted language only.
// In all other cases, empty the target for the entity in the default
// language or just the whole target if the entity isn't translatable.
if ($entity instanceof TranslatableInterface && $target instanceof TranslatableTargetInterface && $entity
->isTranslatable()) {
// We expect the target to return a langcode. If it doesn't return one, we
// expect that the target for the entity in the default language must be
// emptied.
$langcode = $target
->getLangcode();
if ($langcode) {
// Langcode exists, check if the entity is available in that language.
if ($entity
->hasTranslation($langcode)) {
$entity_target = $entity
->getTranslation($langcode);
}
else {
// Entity hasn't got a translation in the given langcode yet, so we
// don't need to empty anything.
return;
}
}
}
unset($entity_target->{$target_name});
}