You are here

public function CommerceSmartImporerService::createBool in Commerce Smart Importer 8

Creates bool value based on field settings.

1 call to CommerceSmartImporerService::createBool()
CommerceSmartImporerService::formatField in src/Plugin/CommerceSmartImporerService.php
Formats one field value based on field settings.

File

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

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function createBool($bool, $field_settings) {
  if (is_numeric($bool)) {
    $bool = (int) $bool;
  }
  if ($bool === 1 || $bool === 0) {
    return (bool) $bool;
  }
  elseif ($bool == 'on_label' || $field_settings['on_label'] == $bool) {
    return TRUE;
  }
  elseif ($bool == 'off_label' || $field_settings['off_label'] == $bool) {
    return FALSE;
  }
  else {
    throw new Exception("Not valid boolean");
  }
}