function DevelGenerateBase::getLangcode

Same name in other branches
  1. 4.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.

3 calls to DevelGenerateBase::getLangcode()
BlockContentDevelGenerate::develGenerateContentAddBlock in devel_generate/src/Plugin/DevelGenerate/BlockContentDevelGenerate.php
Create one block. Used by both batch and non-batch code branches.
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 314

Class

DevelGenerateBase
Provides a base DevelGenerate plugin implementation.

Namespace

Drupal\devel_generate

Code

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