File.php in Geocoder 8.3
File
modules/geocoder_field/src/Plugin/Geocoder/Preprocessor/File.php
View source
<?php
namespace Drupal\geocoder_field\Plugin\Geocoder\Preprocessor;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Locale\CountryManagerInterface;
use Drupal\file\Entity\File as FileEntity;
use Drupal\geocoder_field\PreprocessorBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class File extends PreprocessorBase {
protected $fileSystem;
public function __construct(array $configuration, $plugin_id, $plugin_definition, CountryManagerInterface $country_manager, FileSystemInterface $file_system) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $country_manager);
$this->fileSystem = $file_system;
}
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('file_system'));
}
public function preprocess() {
parent::preprocess();
foreach ($this->field
->getValue() as $delta => $value) {
if ($value['target_id']) {
$uri = FileEntity::load($value['target_id'])
->getFileUri();
$value['value'] = $this->fileSystem
->realpath($uri);
try {
$this->field
->set($delta, $value);
} catch (\Exception $e) {
watchdog_exception('geocoder', $e);
}
}
}
return $this;
}
}
Classes
Name |
Description |
File |
Provides a geocoder preprocessor plugin for file fields. |