getDefaultOptions example


  public static function processLanguageConfiguration(&$element, FormStateInterface $form_state, &$form) {
    $options = $element['#options'] ?? [];
    // Avoid validation failure since we are moving the '#options' key in the     // nested 'language' select element.     unset($element['#options']);
    /** @var \Drupal\language\Entity\ContentLanguageSettings $default_config */
    $default_config = $element['#default_value'];
    $element['langcode'] = [
      '#type' => 'select',
      '#title' => t('Default language'),
      '#options' => $options + static::getDefaultOptions(),
      '#description' => t('Explanation of the language options is found on the <a href=":languages_list_page">languages list page</a>.', [':languages_list_page' => Url::fromRoute('entity.configurable_language.collection')->toString()]),
      '#default_value' => ($default_config != NULL) ? $default_config->getDefaultLangcode() : LanguageInterface::LANGCODE_SITE_DEFAULT,
    ];

    $element['language_alterable'] = [
      '#type' => 'checkbox',
      '#title' => t('Show language selector on create and edit pages'),
      '#default_value' => ($default_config != NULL) ? $default_config->isLanguageAlterable() : FALSE,
    ];

    // Add the entity type and bundle information to the form if they are set.
Home | Imprint | This part of the site doesn't use cookies.