function DevelGenerateBase::getLangcode

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

Return a language code.

Parameters

array $add_language: Optional array of language codes from which to select one at random. If empty then return the site's default language.

Return value

string The language code to use.

2 calls to DevelGenerateBase::getLangcode()
ContentDevelGenerate::develGenerateContentAddNode in devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php
Create one node. Used by both batch and non-batch code branches.
TermDevelGenerate::generateTerms in devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php
Generates taxonomy terms for a list of given vocabularies.
1 method overrides DevelGenerateBase::getLangcode()
MediaDevelGenerate::getLangcode in devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php
Determine language based on $results.

File

devel_generate/src/DevelGenerateBase.php, line 300

Class

DevelGenerateBase
Provides a base DevelGenerate plugin implementation.

Namespace

Drupal\devel_generate

Code

protected function getLangcode(array $add_language) {
    if (empty($add_language)) {
        return $this->languageManager
            ->getDefaultLanguage()
            ->getId();
    }
    return $add_language[array_rand($add_language)];
}