Address.php in Geocoder 8.2
File
modules/geocoder_address/src/Plugin/Geocoder/Preprocessor/Address.php
View source
<?php
namespace Drupal\geocoder_address\Plugin\Geocoder\Preprocessor;
use Drupal\geocoder_field\PreprocessorBase;
use Drupal\Core\Locale\CountryManagerInterface;
use Drupal\geocoder_address\AddressService;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Address extends PreprocessorBase {
protected $addressService;
public function __construct(array $configuration, $plugin_id, $plugin_definition, CountryManagerInterface $country_manager, AddressService $address_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $country_manager);
$this->addressService = $address_service;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('country_manager'), $container
->get('geocoder_address.address'));
}
public function preprocess() {
parent::preprocess();
foreach ($this->field
->getValue() as $delta => $value) {
$address = '';
if (is_array($value)) {
$address = $this->addressService
->addressArrayToGeoString($value);
}
$value['value'] = $address;
$this->field
->set($delta, $value);
}
return $this;
}
}
Classes
Name |
Description |
Address |
Provides a geocoder preprocessor plugin for address fields. |