public function Language::buildForm

Implements \Drupal\Core\Form\FormInterface::buildForm().

Overrides ConditionPluginBase::buildForm

File

drupal/core/modules/language/lib/Drupal/language/Plugin/Condition/Language.php, line 34
Contains \Drupal\language\Plugin\Condition\Language.

Class

Language
Provides a 'Language' condition.

Namespace

Drupal\language\Plugin\Condition

Code

public function buildForm(array $form, array &$form_state) {
  $form = parent::buildForm($form, $form_state);
  if (language_multilingual()) {

    // Fetch languages.
    $languages = language_list(Lang::STATE_ALL);
    $langcodes_options = array();
    foreach ($languages as $language) {

      // @todo $language->name is not wrapped with t(), it should be replaced
      //   by CMI translation implementation.
      $langcodes_options[$language->langcode] = $language->name;
    }
    $form['langcodes'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Language selection'),
      '#default_value' => !empty($this->configuration['langcodes']) ? $this->configuration['langcodes'] : array(),
      '#options' => $langcodes_options,
      '#description' => t('Select languages to enforce. If none are selected, all languages will be allowed.'),
    );
  }
  else {
    $form['language']['langcodes'] = array(
      '#type' => 'value',
      '#value' => !empty($this->configuration['langcodes']) ? $this->configuration['langcodes'] : array(),
    );
  }
  return $form;
}