public function Properties::value in Salesforce Suite 8.3
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/ Properties.php, line 65
Class
- Properties
- Adapter for entity properties and fields.
Namespace
Drupal\salesforce_mapping\Plugin\SalesforceMappingFieldCode
public function value(EntityInterface $entity, SalesforceMappingInterface $mapping) {
// No error checking here. If a property is not defined, it's a
// configuration bug that needs to be solved elsewhere.
// Multipicklist is the only target type that handles multi-valued fields.
$describe = $this->salesforceClient
->objectDescribe($mapping
->getSalesforceObjectType());
$field_definition = $describe
->getField($this
->config('salesforce_field'));
if ($field_definition['type'] == 'multipicklist') {
$values = [];
foreach ($entity
->get($this
->config('drupal_field_value')) as $value) {
$values[] = $value->value;
}
return implode(';', $values);
}
else {
return $entity
->get($this
->config('drupal_field_value'))->value;
}
}