You are here

protected function Select2BoxesAutocompleteListWidget::setCountriesList in Select2 Boxes 8

Specifies the countries list options if needed.

1 call to Select2BoxesAutocompleteListWidget::setCountriesList()
Select2BoxesAutocompleteListWidget::formElement in src/Plugin/Field/FieldWidget/Select2BoxesAutocompleteListWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/Select2BoxesAutocompleteListWidget.php, line 147

Class

Select2BoxesAutocompleteListWidget
Class Select2BoxesAutocompleteList.

Namespace

Drupal\select2boxes\Plugin\Field\FieldWidget

Code

protected function setCountriesList() {
  if (!isset($this->options)) {

    // Specify the default "none" option in case of using single-value widget.
    $this->options = [
      '_none' => $this
        ->t('- None -'),
    ];

    // Add the countries list using country manager service.
    $this->options += \Drupal::service('country_manager')
      ->getList();
  }
}