function MediaDevelGenerate::getLangcode

Same name in other branches
  1. 5.x devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MediaDevelGenerate::getLangcode()

Determine language based on $results.

Parameters

array $results: The input values from the settings form.

Return value

string The language code.

Overrides DevelGenerateBase::getLangcode

1 call to MediaDevelGenerate::getLangcode()
MediaDevelGenerate::createMediaItem in devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php
Create one media item. Used by both batch and non-batch code branches.

File

devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php, line 528

Class

MediaDevelGenerate
Provides a plugin that generates media entities.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

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