You are here

public function Language::buildConfigurationForm in Drupal 10

Same name in this branch
  1. 10 core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::buildConfigurationForm()
  2. 10 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Language::buildConfigurationForm()
Same name and namespace in other branches
  1. 8 core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::buildConfigurationForm()
  2. 9 core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::buildConfigurationForm()

File

core/modules/language/src/Plugin/Condition/Language.php, line 67

Class

Language
Provides a 'Language' condition.

Namespace

Drupal\language\Plugin\Condition

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  if ($this->languageManager
    ->isMultilingual()) {

    // Fetch languages.
    $languages = $this->languageManager
      ->getLanguages();
    $langcodes_options = [];
    foreach ($languages as $language) {
      $langcodes_options[$language
        ->getId()] = $language
        ->getName();
    }
    $form['langcodes'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Language selection'),
      '#default_value' => $this->configuration['langcodes'],
      '#options' => $langcodes_options,
      '#description' => $this
        ->t('Select languages to enforce. If none are selected, all languages will be allowed.'),
    ];
  }
  else {
    $form['langcodes'] = [
      '#type' => 'value',
      '#default_value' => $this->configuration['langcodes'],
    ];
  }
  return parent::buildConfigurationForm($form, $form_state);
}