/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $countries = $this->countryManager->getList();
     $system_date = $this->config('system.date');
     // Date settings:
     $zones = system_time_zones();
     $form['locale'] = array('#type' => 'details', '#title' => t('Locale'), '#open' => TRUE);
     $form['locale']['site_default_country'] = array('#type' => 'select', '#title' => t('Default country'), '#empty_value' => '', '#default_value' => $system_date->get('country.default'), '#options' => $countries, '#attributes' => array('class' => array('country-detect')));
     $form['locale']['date_first_day'] = array('#type' => 'select', '#title' => t('First day of week'), '#default_value' => $system_date->get('first_day'), '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')));
     $form['timezone'] = array('#type' => 'details', '#title' => t('Time zones'), '#open' => TRUE);
     $form['timezone']['date_default_timezone'] = array('#type' => 'select', '#title' => t('Default time zone'), '#default_value' => $system_date->get('timezone.default') ?: date_default_timezone_get(), '#options' => $zones);
     $configurable_timezones = $system_date->get('timezone.user.configurable');
     $form['timezone']['configurable_timezones'] = array('#type' => 'checkbox', '#title' => t('Users may set their own time zone'), '#default_value' => $configurable_timezones);
     $form['timezone']['configurable_timezones_wrapper'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="configurable_timezones"]' => array('checked' => FALSE))));
     $form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = array('#type' => 'checkbox', '#title' => t('Remind users at login if their time zone is not set'), '#default_value' => $system_date->get('timezone.user.warn'), '#description' => t('Only applied if users may set their own time zone.'));
     $form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = array('#type' => 'radios', '#title' => t('Time zone for new users'), '#default_value' => $system_date->get('timezone.user.default'), '#options' => array(DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone'), DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone'), DRUPAL_USER_TIMEZONE_SELECT => t('Users may set their own time zone at registration')), '#description' => t('Only applied if users may set their own time zone.'));
     return parent::buildForm($form, $form_state);
 }
 /**
  * @covers ::label
  * @covers ::getCountryManager
  *
  * @depends testGetLocale
  */
 function testLabel()
 {
     $languages = LanguageManager::getStandardLanguageList();
     $language_code = array_rand($languages);
     $country_code_a = strtoupper($this->randomMachineName());
     $country_code_b = strtoupper($this->randomMachineName());
     $country_code_c = strtoupper($this->randomMachineName());
     $country_list = [$country_code_a => $this->randomMachineName(), $country_code_b => $this->randomMachineName(), $country_code_c => $this->randomMachineName()];
     $this->countryManager->expects($this->atLeastOnce())->method('getList')->willReturn($country_list);
     $this->sut->setLocale($language_code, $country_code_b);
     $this->assertInstanceOf(TranslatableMarkup::class, $this->sut->label());
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['#title'] = $this->t('Configure site');
     // Warn about settings.php permissions risk
     $settings_dir = conf_path();
     $settings_file = $settings_dir . '/settings.php';
     // Check that $_POST is empty so we only show this message when the form is
     // first displayed, not on the next page after it is submitted. (We do not
     // want to repeat it multiple times because it is a general warning that is
     // not related to the rest of the installation process; it would also be
     // especially out of place on the last page of the installer, where it would
     // distract from the message that the Drupal installation has completed
     // successfully.)
     $post_params = $this->getRequest()->request->all();
     if (empty($post_params) && (!drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_dir, FILE_NOT_WRITABLE, 'dir'))) {
         drupal_set_message(t('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the <a href="@handbook_url">online handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'warning');
     }
     $form['#attached']['library'][] = 'system/drupal.system';
     // Add JavaScript time zone detection.
     $form['#attached']['library'][] = 'core/drupal.timezone';
     // We add these strings as settings because JavaScript translation does not
     // work during installation.
     $js = array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail')));
     $form['#attached']['js'][] = array('data' => $js, 'type' => 'setting');
     // Cache a fully-built schema. This is necessary for any invocation of
     // index.php because: (1) setting cache table entries requires schema
     // information, (2) that occurs during bootstrap before any module are
     // loaded, so (3) if there is no cached schema, drupal_get_schema() will
     // try to generate one but with no loaded modules will return nothing.
     //
     // @todo Move this to the 'install_finished' task?
     drupal_get_schema(NULL, TRUE);
     $form['site_information'] = array('#type' => 'fieldgroup', '#title' => $this->t('Site information'));
     $form['site_information']['site_name'] = array('#type' => 'textfield', '#title' => $this->t('Site name'), '#required' => TRUE, '#weight' => -20);
     $form['site_information']['site_mail'] = array('#type' => 'email', '#title' => $this->t('Site email address'), '#default_value' => ini_get('sendmail_from'), '#description' => $this->t("Automated emails, such as registration information, will be sent from this address. Use an address ending in your site's domain to help prevent these emails from being flagged as spam."), '#required' => TRUE, '#weight' => -15);
     $form['admin_account'] = array('#type' => 'fieldgroup', '#title' => $this->t('Site maintenance account'));
     $form['admin_account']['account']['name'] = array('#type' => 'textfield', '#title' => $this->t('Username'), '#maxlength' => USERNAME_MAX_LENGTH, '#description' => $this->t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), '#required' => TRUE, '#attributes' => array('class' => array('username')));
     $form['admin_account']['account']['pass'] = array('#type' => 'password_confirm', '#required' => TRUE, '#size' => 25);
     $form['admin_account']['account']['#tree'] = TRUE;
     $form['admin_account']['account']['mail'] = array('#type' => 'email', '#title' => $this->t('Email address'), '#required' => TRUE);
     $form['regional_settings'] = array('#type' => 'fieldgroup', '#title' => $this->t('Regional settings'));
     $countries = $this->countryManager->getList();
     $form['regional_settings']['site_default_country'] = array('#type' => 'select', '#title' => $this->t('Default country'), '#empty_value' => '', '#default_value' => $this->config('system.date')->get('country.default'), '#options' => $countries, '#description' => $this->t('Select the default country for the site.'), '#weight' => 0);
     $form['regional_settings']['date_default_timezone'] = array('#type' => 'select', '#title' => $this->t('Default time zone'), '#default_value' => date_default_timezone_get(), '#options' => system_time_zones(), '#description' => $this->t('By default, dates in this site will be displayed in the chosen time zone.'), '#weight' => 5, '#attributes' => array('class' => array('timezone-detect')));
     $form['update_notifications'] = array('#type' => 'fieldgroup', '#title' => $this->t('Update notifications'));
     $form['update_notifications']['update_status_module'] = array('#type' => 'checkboxes', '#title' => $this->t('Update notifications'), '#options' => array(1 => $this->t('Check for updates automatically'), 2 => $this->t('Receive email notifications')), '#default_value' => array(1, 2), '#description' => $this->t('The system will notify you when updates and important security releases are available for installed components. Anonymous information about your site is sent to <a href="@drupal">Drupal.org</a>.', array('@drupal' => 'http://drupal.org')), '#weight' => 15);
     $form['update_notifications']['update_status_module'][2] = array('#states' => array('visible' => array('input[name="update_status_module[1]"]' => array('checked' => TRUE))));
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save and continue'), '#weight' => 15, '#button_type' => 'primary');
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\currency\Entity\CurrencyLocaleInterface $currency_locale */
     $currency_locale = $this->getEntity();
     $options = array();
     foreach (LanguageManager::getStandardLanguageList() as $language_code => $language_names) {
         $options[$language_code] = $language_names[0];
     }
     natcasesort($options);
     $form['language_code'] = array('#default_value' => $currency_locale->getLanguageCode(), '#empty_value' => '', '#options' => $options, '#required' => TRUE, '#title' => $this->t('Language'), '#type' => 'select');
     $form['country_code'] = array('#default_value' => $currency_locale->getCountryCode(), '#empty_value' => '', '#options' => $this->countryManager->getList(), '#required' => TRUE, '#title' => $this->t('Country'), '#type' => 'select');
     $form['formatting'] = array('#open' => TRUE, '#title' => $this->t('Formatting'), '#type' => 'details');
     $form['formatting']['decimal_separator'] = array('#default_value' => $currency_locale->getDecimalSeparator(), '#maxlength' => 255, '#required' => TRUE, '#size' => 3, '#title' => $this->t('Decimal separator'), '#type' => 'textfield');
     $form['formatting']['grouping_separator'] = array('#default_value' => $currency_locale->getGroupingSeparator(), '#maxlength' => 255, '#size' => 3, '#title' => $this->t('Group separator'), '#type' => 'textfield');
     $form['formatting']['pattern'] = array('#default_value' => $currency_locale->getPattern(), '#description' => $this->t('A Unicode <abbr title="Common Locale Data Repository">CLDR</abbr> <a href="http://cldr.unicode.org/translation/number-patterns">currency number pattern</a>.'), '#maxlength' => 255, '#title' => $this->t('Pattern'), '#type' => 'textfield');
     return parent::form($form, $form_state, $currency_locale);
 }
 /**
  * @covers ::form
  */
 public function testForm()
 {
     $language_code = $this->randomMachineName();
     $country_code = $this->randomMachineName();
     $pattern = $this->randomMachineName();
     $decimal_separator = $this->randomMachineName();
     $grouping_separator = $this->randomMachineName();
     $this->currencyLocale->expects($this->once())->method('getLanguageCode')->willReturn($language_code);
     $this->currencyLocale->expects($this->once())->method('getCountryCode')->willReturn($country_code);
     $this->currencyLocale->expects($this->once())->method('getPattern')->willReturn($pattern);
     $this->currencyLocale->expects($this->once())->method('getDecimalSeparator')->willReturn($decimal_separator);
     $this->currencyLocale->expects($this->once())->method('getGroupingSeparator')->willReturn($grouping_separator);
     $language = $this->getMock(LanguageInterface::class);
     $this->currencyLocale->expects($this->any())->method('language')->willReturn($language);
     $country_list = array($this->randomMachineName() => $this->randomMachineName());
     $this->countryManager->expects($this->atLeastOnce())->method('getList')->willReturn($country_list);
     $form = array();
     $form_state = $this->getMock(FormStateInterface::class);
     $build = $this->sut->form($form, $form_state);
     unset($build['langcode']);
     unset($build['#process']);
     $expected['language_code'] = ['#default_value' => $language_code, '#empty_value' => '', '#options' => array('af' => 'Afrikaans', 'sq' => 'Albanian', 'am' => 'Amharic', 'ar' => 'Arabic', 'hy' => 'Armenian', 'ast' => 'Asturian', 'az' => 'Azerbaijani', 'ms' => 'Bahasa Malaysia', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali', 'bs' => 'Bosnian', 'bg' => 'Bulgarian', 'my' => 'Burmese', 'ca' => 'Catalan', 'zh-hans' => 'Chinese, Simplified', 'zh-hant' => 'Chinese, Traditional', 'hr' => 'Croatian', 'cs' => 'Czech', 'da' => 'Danish', 'nl' => 'Dutch', 'dz' => 'Dzongkha', 'en' => 'English', 'eo' => 'Esperanto', 'et' => 'Estonian', 'fo' => 'Faeroese', 'fil' => 'Filipino', 'fi' => 'Finnish', 'fr' => 'French', 'fy' => 'Frisian, Western', 'gl' => 'Galician', 'ka' => 'Georgian', 'de' => 'German', 'el' => 'Greek', 'gu' => 'Gujarati', 'ht' => 'Haitian Creole', 'he' => 'Hebrew', 'hi' => 'Hindi', 'hu' => 'Hungarian', 'is' => 'Icelandic', 'id' => 'Indonesian', 'ga' => 'Irish', 'it' => 'Italian', 'ja' => 'Japanese', 'jv' => 'Javanese', 'kn' => 'Kannada', 'kk' => 'Kazakh', 'km' => 'Khmer', 'ko' => 'Korean', 'ku' => 'Kurdish', 'ky' => 'Kyrgyz', 'lo' => 'Lao', 'lv' => 'Latvian', 'lt' => 'Lithuanian', 'xx-lolspeak' => 'Lolspeak', 'mk' => 'Macedonian', 'mg' => 'Malagasy', 'ml' => 'Malayalam', 'mr' => 'Marathi', 'mn' => 'Mongolian', 'ne' => 'Nepali', 'se' => 'Northern Sami', 'nb' => 'Norwegian Bokmål', 'nn' => 'Norwegian Nynorsk', 'oc' => 'Occitan', 'fa' => 'Persian, Farsi', 'pl' => 'Polish', 'pt-br' => 'Portuguese, Brazil', 'pt-pt' => 'Portuguese, Portugal', 'pa' => 'Punjabi', 'ro' => 'Romanian', 'ru' => 'Russian', 'sco' => 'Scots', 'gd' => 'Scots Gaelic', 'sr' => 'Serbian', 'si' => 'Sinhala', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'es' => 'Spanish', 'sw' => 'Swahili', 'sv' => 'Swedish', 'gsw-berne' => 'Swiss German', 'ta' => 'Tamil', 'ta-lk' => 'Tamil, Sri Lanka', 'te' => 'Telugu', 'th' => 'Thai', 'bo' => 'Tibetan', 'tr' => 'Turkish', 'tyv' => 'Tuvan', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'ug' => 'Uyghur', 'vi' => 'Vietnamese', 'cy' => 'Welsh'), '#required' => TRUE, '#type' => 'select'];
     unset($build['language_code']['#title']);
     $expected['country_code'] = ['#default_value' => $country_code, '#empty_value' => '', '#options' => $country_list, '#required' => TRUE, '#type' => 'select'];
     unset($build['country_code']['#title']);
     $expected['formatting'] = ['#open' => TRUE, '#type' => 'details'];
     unset($build['formatting']['#title']);
     $expected['formatting']['decimal_separator'] = ['#default_value' => $decimal_separator, '#maxlength' => 255, '#required' => TRUE, '#size' => 3, '#type' => 'textfield'];
     unset($build['formatting']['decimal_separator']['#title']);
     $expected['formatting']['grouping_separator'] = ['#default_value' => $grouping_separator, '#maxlength' => 255, '#size' => 3, '#type' => 'textfield'];
     unset($build['formatting']['grouping_separator']['#title']);
     $expected['formatting']['pattern'] = ['#default_value' => $pattern, '#maxlength' => 255, '#type' => 'textfield'];
     unset($build['formatting']['pattern']['#title']);
     unset($build['formatting']['pattern']['#description']);
     $expected['#after_build'] = ['::afterBuild'];
     $this->assertSame($expected, $build);
 }