You are here

protected function GenerateProducts::getLangcode in Commerce Bulk 8

Determine language based on $results.

1 call to GenerateProducts::getLangcode()
GenerateProducts::generateSaveProduct in modules/commerce_generate/src/Plugin/DevelGenerate/GenerateProducts.php
Create one product. Used by both batch and non-batch code branches.

File

modules/commerce_generate/src/Plugin/DevelGenerate/GenerateProducts.php, line 659

Class

GenerateProducts
Provides a GenerateProducts plugin.

Namespace

Drupal\commerce_generate\Plugin\DevelGenerate

Code

protected function getLangcode($results) {
  if (!empty($results['add_language'])) {
    $langcodes = $results['add_language'];
    $langcode = $langcodes[array_rand($langcodes)];
  }
  elseif (!empty($results['languages']['add_language'])) {
    $langcodes = $results['languages']['add_language'];
    $langcode = $langcodes[array_rand($langcodes)];
  }
  else {
    $langcode = $this->languageManager
      ->getDefaultLanguage()
      ->getId();
  }
  return $langcode;
}