Skip to content

Commit

Permalink
Settings cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Feb 15, 2024
1 parent bd0e3e9 commit bed5432
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 29 deletions.
6 changes: 1 addition & 5 deletions src/fields/EasyAddressFieldField.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ public function getInputHtml($value, ElementInterface $element = null): string
$id = Craft::$app->getView()->formatInputId($this->handle);
$namespacedId = Craft::$app->getView()->namespaceInputId($id);

$pluginSettings = EasyAddressField::getInstance()->getSettings();
$fieldSettings = $this->getSettings();

return Craft::$app->getView()->renderTemplate(
'easy-address-field/_field/_input',
[
Expand All @@ -188,8 +185,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
'id' => $id,
'countries' => EasyAddressField::getInstance()->countries->getCountriesAsArray(),
'namespacedId' => $namespacedId,
'fieldSettings' => $fieldSettings,
'pluginSettings' => $pluginSettings,
'fieldSettings' => $this->getSettings(),
]
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/services/CountriesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function getCountryNameByAlpha2($code, $locale)
$country = $data->alpha2($code);

try {
$translatedLocale = Locale::getDisplayRegion('-' . $country['alpha2'], $locale);
return $translatedLocale;
return Locale::getDisplayRegion('-' . $country['alpha2'], $locale);
} catch (\Exception $e) {
return $country['name'];
}
Expand Down
8 changes: 0 additions & 8 deletions src/services/GeoLocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@

class GeoLocationService extends Component
{
public $settings;

public function init(): void
{
parent::init(); // TODO: Change the autogenerated stub
$this->settings = EasyAddressField::getInstance()->getSettings();
}

/**
* @param EasyAddressFieldModel $model
*
Expand Down
1 change: 0 additions & 1 deletion src/translations/nl/easy-address-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
'Postal code' => 'Postcode',
'City' => 'Stad of gemeente',
'Pick an address on the map' => 'Kies een adres op de kaart',

];
15 changes: 2 additions & 13 deletions src/web/twig/variables/AddressVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@
namespace studioespresso\easyaddressfield\web\twig\variables;

use studioespresso\easyaddressfield\EasyAddressField;
use studioespresso\easyaddressfield\services\CountriesService;

class AddressVariable
{
private $settings;

public function __construct()
public function countries(): array
{
$pluginSettings = EasyAddressField::getInstance()->getSettings();
$this->settings = $pluginSettings;
}

public function countries()
{
$countriesService = new CountriesService();

return $countriesService->getCountriesAsArray();
return EasyAddressField::getInstance()->countries->getCountriesAsArray();
}
}

0 comments on commit bed5432

Please sign in to comment.