public function WebformEntityElements::value in Salesforce Suite 5.0.x
Same name and namespace in other branches
- 8.4 modules/salesforce_webform/src/Plugin/SalesforceMappingField/WebformEntityElements.php \Drupal\salesforce_webform\Plugin\SalesforceMappingField\WebformEntityElements::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/ WebformEntityElements.php, line 70
Class
- WebformEntityElements
- 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 {
$value = $entity
->getElementData($main_element_name);
$mappedObjects = $this->mappedObjectStorage
->loadByDrupal($webform_element['#target_type'], $value);
if (!empty($mappedObjects)) {
$mappedObject = reset($mappedObjects);
return $mappedObject
->sfid();
}
} catch (\Exception $e) {
return NULL;
}
}