public function WebformElements::value in Salesforce Suite 5.0.x
Same name and namespace in other branches
- 8.4 modules/salesforce_webform/src/Plugin/SalesforceMappingField/WebformElements.php \Drupal\salesforce_webform\Plugin\SalesforceMappingField\WebformElements::value()
- 8.3 modules/salesforce_webform/src/Plugin/SalesforceMappingField/WebformElements.php \Drupal\salesforce_webform\Plugin\SalesforceMappingField\WebformElements::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_webform/ src/ Plugin/ SalesforceMappingField/ WebformElements.php, line 63
Class
- WebformElements
- Adapter for Webform elements.
Namespace
Drupal\salesforce_webform\Plugin\SalesforceMappingFieldCode
public function value(EntityInterface $entity, SalesforceMappingInterface $mapping) {
$element_parts = explode('__', $this
->config('drupal_field_value'));
$main_element_name = reset($element_parts);
$webform = $this->entityTypeManager
->getStorage('webform')
->load($mapping
->get('drupal_bundle'));
$webform_element = $webform
->getElement($main_element_name);
if (!$webform_element) {
// This reference field does not exist.
return;
}
try {
$describe = $this->salesforceClient
->objectDescribe($mapping
->getSalesforceObjectType());
$field_definition = $describe
->getField($this
->config('salesforce_field'));
if ($field_definition['type'] == 'multipicklist') {
return implode(';', $entity
->getElementData($main_element_name));
}
else {
$value = $entity
->getElementData($main_element_name);
if (isset($element_parts[1])) {
$value = $value[$element_parts[1]];
}
return $value;
}
} catch (\Exception $e) {
return NULL;
}
}