Commit 3ac20d4a authored by Jacob Rockowitz's avatar Jacob Rockowitz Committed by Jacob Rockowitz
Browse files

Issue #3283192 by jrockowitz, narendra.rajwar27: Use CountryManager::getList()...

Issue #3283192 by jrockowitz, narendra.rajwar27: Use CountryManager::getList() instead of ::getStandardList()
parent aab569f0
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -46,7 +46,9 @@ function webform_webform_options_time_zones_alter(array &$options, array $elemen
 */
function webform_webform_options_country_codes_alter(array &$options, array $element = []) {
  if (empty($options)) {
    $options = CountryManager::getStandardList();
    /** @var \Drupal\Core\Locale\CountryManagerInterface $country_manager */
    $country_manager = \Drupal::service('country_manager');
    $options = $country_manager->getList();
  }
}

@@ -55,7 +57,9 @@ function webform_webform_options_country_codes_alter(array &$options, array $ele
 */
function webform_webform_options_country_names_alter(array &$options, array $element = []) {
  if (empty($options)) {
    $countries = CountryManager::getStandardList();
    /** @var \Drupal\Core\Locale\CountryManagerInterface $country_manager */
    $country_manager = \Drupal::service('country_manager');
    $countries = $country_manager->getList();
    $options = array_combine($countries, $countries);
  }
}
+10 −3
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ namespace Drupal\webform\Plugin\WebformElement;
use Drupal\Component\Serialization\Json;
use Drupal\webform\Element\WebformMessage as WebformMessageElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Locale\CountryManager;
use Drupal\webform\WebformInterface;
use Drupal\webform\WebformSubmissionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -38,6 +37,13 @@ class Telephone extends TextBase {
   */
  protected $telephoneValidator;

  /**
   * The country manager.
   *
   * @var \Drupal\Core\Locale\CountryManagerInterface
   */
  protected $countryManager;

  /**
   * {@inheritdoc}
   */
@@ -47,6 +53,7 @@ class Telephone extends TextBase {
    $instance->telephoneValidator = ($instance->moduleHandler->moduleExists('telephone_validation'))
      ? $container->get('telephone_validation.validator')
      : NULL;
    $instance->countryManager = $container->get('country_manager');
    return $instance;
  }

@@ -159,7 +166,7 @@ class Telephone extends TextBase {
      '#title' => $this->t('Initial country'),
      '#type' => 'select',
      '#empty_option' => $this->t('- None -'),
      '#options' => CountryManager::getStandardList(),
      '#options' => $this->countryManager->getList(),
      '#states' => [
        'visible' => [':input[name="properties[international]"]' => ['checked' => TRUE]],
      ],
@@ -167,7 +174,7 @@ class Telephone extends TextBase {
    $form['telephone']['international_preferred_countries'] = [
      '#title' => $this->t('Preferred countries'),
      '#type' => 'select',
      '#options' => CountryManager::getStandardList(),
      '#options' => $this->countryManager->getList(),
      '#description' => $this->t('Specify the countries to appear at the top of the list.'),
      '#select2' => TRUE,
      '#multiple' => TRUE,
+19 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\webform\Plugin\WebformElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Locale\CountryManager;
use Drupal\webform\WebformSubmissionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides a 'telephone' (composite) element.
@@ -20,6 +21,22 @@ use Drupal\webform\WebformSubmissionInterface;
 */
class WebformTelephone extends WebformCompositeBase {

  /**
   * The country manager.
   *
   * @var \Drupal\Core\Locale\CountryManagerInterface
   */
  protected $countryManager;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    $instance->countryManager = $container->get('country_manager');
    return $instance;
  }

  /**
   * {@inheritdoc}
   */
@@ -102,6 +119,7 @@ class WebformTelephone extends WebformCompositeBase {
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);

    $form['composite']['phone__international'] = [
      '#title' => $this->t('Enhance support for international phone numbers'),
      '#type' => 'checkbox',
@@ -114,7 +132,7 @@ class WebformTelephone extends WebformCompositeBase {
      '#empty_option' => $this->t('- None -'),
      '#options' => [
        'auto' => $this->t('Auto detect'),
      ] + CountryManager::getStandardList(),
      ] + $this->countryManager->getList(),
      '#states' => [
        'visible' => [
          ':input[name="properties[phone__international]"]' => ['checked' => TRUE],