You are here

protected function AdministrativeArea::getCountrySource in Address 8

Gets the current source for the country code.

If defined in the current values of the configuration form, use that. Otherwise, fall back to the filter configuration.

Return value

string The country source.

3 calls to AdministrativeArea::getCountrySource()
AdministrativeArea::getCurrentCountry in src/Plugin/views/filter/AdministrativeArea.php
Gets the currently active country code.
AdministrativeArea::valueForm in src/Plugin/views/filter/AdministrativeArea.php
Options form subform for setting options.
AdministrativeArea::valueSubmit in src/Plugin/views/filter/AdministrativeArea.php
Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data.

File

src/Plugin/views/filter/AdministrativeArea.php, line 426

Class

AdministrativeArea
Filter by administrative area.

Namespace

Drupal\address\Plugin\views\filter

Code

protected function getCountrySource() {

  // If we're rebuilding via AJAX, we want the country source from the form
  // state, not the configuration.
  $country_source = '';
  if (!empty($this->formState)) {

    // First, see if there's a legitimate value in the form state.
    $form_value_country_source = $this->formState
      ->getValue([
      'options',
      'country',
      'country_source',
    ]);
    if (!empty($form_value_country_source)) {
      $country_source = $form_value_country_source;
    }
    else {

      // At various stages of building/validating the form, we might have
      // user input but not yet have the value saved into the form
      // state. So, if we have a form state but still don't have a value,
      // see if it is defined in the user input.
      $input = $this->formState
        ->getUserInput();
      if (!empty($input['options']['country']['country_source'])) {
        $country_source = $input['options']['country']['country_source'];
      }
    }
  }

  // If we don't have a source via the form state, use our configuration.
  if (empty($country_source)) {
    $country_source = $this->options['country']['country_source'];
  }
  return $country_source;
}