Skip to content
Snippets Groups Projects
Commit 85736b59 authored by Italo Mairo's avatar Italo Mairo
Browse files

Implementation of Geocoder additional option for Locale code/id settings, that...

Implementation of Geocoder additional option for Locale code/id settings, that is being used in the Geocoder Query withLocale() method. It is falling back into the Current Interface Language code/id if left empty (Issue #3403048 by tanc, itamair, ekes: Photon provider is only compatible with certain lang codes.)
parent 7f88e8c2
Branches
Tags
No related merge requests found
...@@ -41,6 +41,13 @@ geocoder_provider_configuration: ...@@ -41,6 +41,13 @@ geocoder_provider_configuration:
type: geocoder_throttle_configuration type: geocoder_throttle_configuration
label: 'Throttle' label: 'Throttle'
nullable: true nullable: true
geocoder:
type: mapping
label: 'Geocoder Additional Options'
mapping:
locale:
type: string
label: 'Locale'
geocoder_throttle_configuration: geocoder_throttle_configuration:
type: mapping type: mapping
......
...@@ -98,10 +98,13 @@ abstract class ProviderUsingHandlerBase extends ProviderBase { ...@@ -98,10 +98,13 @@ abstract class ProviderUsingHandlerBase extends ProviderBase {
* @throws \ReflectionException * @throws \ReflectionException
*/ */
protected function getHandlerWrapper(): StatefulGeocoder { protected function getHandlerWrapper(): StatefulGeocoder {
// Define the locale on the basis of the geocoder additional option,
// or falling back to the current Interface language code/id.
$locale = $this->configuration['geocoder']['locale'] ?? $this->languageManager->getCurrentLanguage()->getId();
if ($this->handlerWrapper === NULL) { if ($this->handlerWrapper === NULL) {
$this->handlerWrapper = new StatefulGeocoder( $this->handlerWrapper = new StatefulGeocoder(
$this->getHandler(), $this->getHandler(),
$this->languageManager->getCurrentLanguage()->getId() $locale
); );
} }
......
...@@ -7,7 +7,9 @@ namespace Drupal\geocoder\Traits; ...@@ -7,7 +7,9 @@ namespace Drupal\geocoder\Traits;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Core\Config\Schema\SchemaIncompleteException; use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Logger\LoggerChannelTrait; use Drupal\Core\Logger\LoggerChannelTrait;
use Drupal\Core\Url;
/** /**
* Trait containing reusable code for configuring Geocoder provider plugins. * Trait containing reusable code for configuring Geocoder provider plugins.
...@@ -121,6 +123,24 @@ trait ConfigurableProviderTrait { ...@@ -121,6 +123,24 @@ trait ConfigurableProviderTrait {
$form['options']['throttle']['#open'] = TRUE; $form['options']['throttle']['#open'] = TRUE;
} }
} }
$form['options']['geocoder'] = [
'#type' => 'details',
'#title' => $this->t("Geocoder Additional Options"),
'#weight' => 15,
];
$form['options']['geocoder']['locale'] = [
'#type' => 'textfield',
'#title' => $this->t('Locale'),
'#maxlength' => 4,
'#placeholder' => $this->languageManager->getCurrentLanguage()->getId(),
'#default_value' => $this->configuration['geocoder']['locale'] ?? '',
'#description' => $this->t('Define your specific language code (en, fr, de, it, es ... etc.) that should be used / forced in the @geocoder_query_link.<br>Alter this only if specifically aware of its functionality.<br><u>If left empty the Current Interface Language code/id will be used.</u>', [
'@geocoder_query_link' => Link::fromTextAndUrl('Geocoder Query withLocale() method', Url::fromUri('https://github.com/geocoder-php/php-common/blob/master/Query/GeocodeQuery.php#L81'))->toString(),
]),
];
return $form; return $form;
} }
...@@ -149,6 +169,9 @@ trait ConfigurableProviderTrait { ...@@ -149,6 +169,9 @@ trait ConfigurableProviderTrait {
*/ */
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
try { try {
$this->configuration['geocoder']['locale'] = $form_state->getValue('locale');
foreach (array_keys($this->getPluginArguments()) as $argument) { foreach (array_keys($this->getPluginArguments()) as $argument) {
$this->configuration[$argument] = $form_state->getValue($argument); $this->configuration[$argument] = $form_state->getValue($argument);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment