You are here

protected function DevelGenerateBase::getLanguageForm in Devel 4.x

Same name and namespace in other branches
  1. 8.3 devel_generate/src/DevelGenerateBase.php \Drupal\devel_generate\DevelGenerateBase::getLanguageForm()

Creates the language and translation section of the form.

This is used by both Content and Term generation.

Parameters

string $items: The name of the things that are being generated - 'nodes' or 'terms'.

Return value

array The language details section of the form.

2 calls to DevelGenerateBase::getLanguageForm()
ContentDevelGenerate::settingsForm in devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php
Returns the form for the plugin.
TermDevelGenerate::settingsForm in devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php
Returns the form for the plugin.

File

devel_generate/src/DevelGenerateBase.php, line 252

Class

DevelGenerateBase
Provides a base DevelGenerate plugin implementation.

Namespace

Drupal\devel_generate

Code

protected function getLanguageForm($items) {

  // We always need a language, even if the language module is not installed.
  $options = [];
  $languages = $this->languageManager
    ->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
  foreach ($languages as $langcode => $language) {
    $options[$langcode] = $language
      ->getName();
  }
  $language_module_exists = $this->moduleHandler
    ->moduleExists('language');
  $translation_module_exists = $this->moduleHandler
    ->moduleExists('content_translation');
  $form['language'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Language'),
    '#open' => $language_module_exists,
  ];
  $form['language']['add_language'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Select the primary language(s) for @items', [
      '@items' => $items,
    ]),
    '#multiple' => TRUE,
    '#description' => $language_module_exists ? '' : $this
      ->t('Disabled - requires Language module'),
    '#options' => $options,
    '#default_value' => [
      $this->languageManager
        ->getDefaultLanguage()
        ->getId(),
    ],
    '#disabled' => !$language_module_exists,
  ];
  $form['language']['translate_language'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Select the language(s) for translated @items', [
      '@items' => $items,
    ]),
    '#multiple' => TRUE,
    '#description' => $translation_module_exists ? $this
      ->t('Translated @items will be created for each language selected.', [
      '@items' => $items,
    ]) : $this
      ->t('Disabled - requires Content Translation module.'),
    '#options' => $options,
    '#disabled' => !$translation_module_exists,
  ];
  return $form;
}