You are here

public function PropertiesBase::value in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/src/Plugin/SalesforceMappingField/PropertiesBase.php \Drupal\salesforce_mapping\Plugin\SalesforceMappingField\PropertiesBase::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/PropertiesBase.php, line 85

Class

PropertiesBase
Base class for properties plugins.

Namespace

Drupal\salesforce_mapping\Plugin\SalesforceMappingField

Code

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') {
    $data = $this
      ->getDataValue($entity, $this
      ->config('drupal_field_value'));
    if (!empty($data)) {
      $strings = [];
      foreach ($data as $item) {
        $strings[] = $item
          ->getString();
      }
      return implode(';', $strings);
    }
  }
  else {
    return $this
      ->getStringValue($entity, $this
      ->config('drupal_field_value'));
  }
}