You are here

public function CommerceSmartImporerService::exportEntity in Commerce Smart Importer 8

Helper function for exportField.

Exports entity name(title).

1 call to CommerceSmartImporerService::exportEntity()
CommerceSmartImporerService::exportField in src/Plugin/CommerceSmartImporerService.php
Force different types of fields to string.

File

src/Plugin/CommerceSmartImporerService.php, line 1669
Main Commerce Smart Importer Service.

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function exportEntity($entity, $field_definition) {
  $values = [];
  foreach ($entity
    ->get($field_definition['machine_names'])
    ->getValue() as $item) {
    $entity = $this
      ->entityTypeManager()
      ->getStorage($field_definition['field_settings']['target_type'])
      ->load($item['target_id']);
    if (!$entity) {
      continue;
    }

    // TODO: Rewrite this to use entity key label instead of hard coding it.
    if ($entity
      ->hasField('name')) {
      $values[] = $entity
        ->getName();
    }
    elseif ($entity
      ->hasField('title')) {
      $values[] = $entity
        ->getTitle();
    }
  }
  $values = implode('|', $values);
  return $values;
}