class GeolocationFieldProvider in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/geolocation/DataProvider/GeolocationFieldProvider.php \Drupal\geolocation\Plugin\geolocation\DataProvider\GeolocationFieldProvider
Provides default geolocation field.
Plugin annotation
@DataProvider(
id = "geolocation_field_provider",
name = @Translation("Geolocation Field"),
description = @Translation("Geolocation Field."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\geolocation\DataProviderBase implements ContainerFactoryPluginInterface, DataProviderInterface
- class \Drupal\geolocation\Plugin\geolocation\DataProvider\GeolocationFieldProvider implements DataProviderInterface
- class \Drupal\geolocation\DataProviderBase implements ContainerFactoryPluginInterface, DataProviderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of GeolocationFieldProvider
File
- src/
Plugin/ geolocation/ DataProvider/ GeolocationFieldProvider.php, line 21
Namespace
Drupal\geolocation\Plugin\geolocation\DataProviderView source
class GeolocationFieldProvider extends DataProviderBase implements DataProviderInterface {
/**
* {@inheritdoc}
*/
public function getTokenHelp(FieldDefinitionInterface $fieldDefinition = NULL) {
$element = parent::getTokenHelp($fieldDefinition);
$element['token_items'][] = [
'token' => [
'#plain_text' => '[geolocation_current_item:lat_sex]',
],
'description' => [
'#plain_text' => $this
->t('Latitude value in sexagesimal notation'),
],
];
$element['token_items'][] = [
'token' => [
'#plain_text' => '[geolocation_current_item:lng_sex]',
],
'description' => [
'#plain_text' => $this
->t('Longitude value in sexagesimal notation'),
],
];
return $element;
}
/**
* {@inheritdoc}
*/
public function replaceFieldItemTokens($text, FieldItemInterface $fieldItem) {
$token_context['geolocation_current_item'] = $fieldItem;
$text = \Drupal::token()
->replace($text, $token_context, [
'callback' => [
$this,
'geolocationItemTokens',
],
'clear' => FALSE,
]);
return parent::replaceFieldItemTokens($text, $fieldItem);
}
/**
* {@inheritdoc}
*/
public function geolocationItemTokens(array &$replacements, array $data, array $options) {
if (isset($data['geolocation_current_item'])) {
/** @var \Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem $item */
$item = $data['geolocation_current_item'];
$replacements['[geolocation_current_item:lat_sex]'] = GeolocationItem::decimalToSexagesimal($item
->get('lat')
->getValue());
$replacements['[geolocation_current_item:lng_sex]'] = GeolocationItem::decimalToSexagesimal($item
->get('lng')
->getValue());
// Handle data tokens.
$metadata = $item
->get('data')
->getValue();
if (is_array($metadata) || $metadata instanceof \Traversable) {
foreach ($metadata as $key => $value) {
try {
// Maybe there is values inside the values.
if (is_array($value) || $value instanceof \Traversable) {
foreach ($value as $deepkey => $deepvalue) {
if (is_string($deepvalue)) {
$replacements['[geolocation_current_item:data:' . $key . ':' . $deepkey . ']'] = (string) $deepvalue;
}
}
}
else {
$replacements['[geolocation_current_item:data:' . $key . ']'] = (string) $value;
}
} catch (\Exception $e) {
watchdog_exception('geolocation', $e);
}
}
}
}
}
/**
* {@inheritdoc}
*/
public function isViewsGeoOption(FieldPluginBase $views_field) {
return $views_field
->getPluginId() == 'geolocation_field';
}
/**
* {@inheritdoc}
*/
public function isFieldGeoOption(FieldDefinitionInterface $fieldDefinition) {
return $fieldDefinition
->getType() == 'geolocation';
}
/**
* {@inheritdoc}
*/
public function getPositionsFromItem(FieldItemInterface $fieldItem) {
if ($fieldItem instanceof GeolocationItem) {
return [
'lat' => $fieldItem
->get('lat')
->getValue(),
'lng' => $fieldItem
->get('lng')
->getValue(),
];
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DataProviderBase:: |
protected | property | Entity field manager. | |
DataProviderBase:: |
protected | property | Field definition. | |
DataProviderBase:: |
protected | property | Views field. | |
DataProviderBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
DataProviderBase:: |
public | function | Token replacement support function, callback to token replacement function. | |
DataProviderBase:: |
public | function |
Get positions from views row. Overrides DataProviderInterface:: |
1 |
DataProviderBase:: |
public | function |
Provide data provider settings form array. Overrides DataProviderInterface:: |
1 |
DataProviderBase:: |
public | function |
Set field definition. Overrides DataProviderInterface:: |
|
DataProviderBase:: |
public | function |
Set views field. Overrides DataProviderInterface:: |
|
DataProviderBase:: |
public | function |
Constructs a new GeocoderBase object. Overrides PluginBase:: |
1 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
GeolocationFieldProvider:: |
public | function | ||
GeolocationFieldProvider:: |
public | function |
Get positions from field item list. Overrides DataProviderBase:: |
|
GeolocationFieldProvider:: |
public | function |
Return field item tokens. Overrides DataProviderBase:: |
|
GeolocationFieldProvider:: |
public | function |
Determine valid field geo option. Overrides DataProviderInterface:: |
|
GeolocationFieldProvider:: |
public | function |
Determine valid views option. Overrides DataProviderBase:: |
|
GeolocationFieldProvider:: |
public | function |
Replace field item tokens. Overrides DataProviderBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |