public function RelatedTermString::value in Salesforce Suite 5.0.x
Same name and namespace in other branches
- 8.4 modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedTermString.php \Drupal\salesforce_mapping\Plugin\SalesforceMappingField\RelatedTermString::value()
Given a Drupal entity, return the outbound value.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity being mapped.
\Drupal\salesforce_mapping\Entity\SalesforceMappingInterface $mapping: The parent SalesforceMapping to which this plugin config belongs.
Overrides SalesforceMappingFieldPluginInterface::value
File
- modules/
salesforce_mapping/ src/ Plugin/ SalesforceMappingField/ RelatedTermString.php, line 55
Class
- RelatedTermString
- Adapter for entity Reference and fields.
Namespace
Drupal\salesforce_mapping\Plugin\SalesforceMappingFieldCode
public function value(EntityInterface $entity, SalesforceMappingInterface $mapping) {
$field_name = $this
->config('drupal_field_value');
$instances = $this->entityFieldManager
->getFieldDefinitions($entity
->getEntityTypeId(), $entity
->bundle());
if (empty($instances[$field_name])) {
return;
}
$field = $entity
->get($field_name);
if (empty($field
->getValue()) || is_null($field->entity)) {
// This reference field is blank or the referenced entity no longer
// exists.
return;
}
// Map the term name to the salesforce field.
return $field->entity
->getName();
}