You are here

public function SalesforceMapping::getKeyValue in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 modules/salesforce_mapping/src/Entity/SalesforceMapping.php \Drupal\salesforce_mapping\Entity\SalesforceMapping::getKeyValue()
  2. 5.0.x modules/salesforce_mapping/src/Entity/SalesforceMapping.php \Drupal\salesforce_mapping\Entity\SalesforceMapping::getKeyValue()

Given a Drupal entity, get the value to be upserted.

Return value

mixed The upsert field value.

Overrides SalesforceMappingInterface::getKeyValue

File

modules/salesforce_mapping/src/Entity/SalesforceMapping.php, line 439

Class

SalesforceMapping
Defines a Salesforce Mapping configuration entity class.

Namespace

Drupal\salesforce_mapping\Entity

Code

public function getKeyValue(EntityInterface $entity) {
  if (!$this
    ->hasKey()) {
    throw new \Exception('No key defined for this mapping.');
  }

  // @TODO #fieldMappingField
  foreach ($this
    ->getFieldMappings() as $i => $field_plugin) {
    if ($field_plugin
      ->get('salesforce_field') == $this
      ->getKeyField()) {
      return $field_plugin
        ->value($entity, $this);
    }
  }
  throw new \Exception($this
    ->t('Key %key not found for this mapping.', [
    '%key' => $this
      ->getKeyField(),
  ]));
}