You are here

public function CommerceSmartImporerService::cardinalityPass in Commerce Smart Importer 8

Helper function for createNewProduct.

Checks if field log satisfies cardinality, returns corrected.

2 calls to CommerceSmartImporerService::cardinalityPass()
CommerceSmartImporerService::createNewProduct in src/Plugin/CommerceSmartImporerService.php
Creates product.
CommerceSmartImporerService::updateProduct in src/Plugin/CommerceSmartImporerService.php
Updates entity with given values.

File

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

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function cardinalityPass(&$field_log, $field_definition) {
  if ($field_definition['cardinality'] == -1) {
    $field_log['cardinality'] = TRUE;
  }
  elseif ($field_definition['cardinality'] < count($field_log['values'])) {
    $field_log['values'] = array_slice($field_log['values'], 0, $field_definition['cardinality']);
    $field_log['cardinality'] = FALSE;
    $field_log['has_log'] = TRUE;
  }
  else {
    $field_log['cardinality'] = TRUE;
  }
}