class SearchAPI in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 modules/geolocation_search_api/src/Plugin/geolocation/DataProvider/SearchAPI.php \Drupal\geolocation_search_api\Plugin\geolocation\DataProvider\SearchAPI
Provides Google Maps.
Plugin annotation
@DataProvider(
id = "search_api",
name = @Translation("Search API"),
description = @Translation("Search API indexed fields support, works with Search API Location module too."),
)
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_search_api\Plugin\geolocation\DataProvider\SearchAPI implements DataProviderInterface
- class \Drupal\geolocation\DataProviderBase implements ContainerFactoryPluginInterface, DataProviderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of SearchAPI
File
- modules/
geolocation_search_api/ src/ Plugin/ geolocation/ DataProvider/ SearchAPI.php, line 22
Namespace
Drupal\geolocation_search_api\Plugin\geolocation\DataProviderView source
class SearchAPI extends DataProviderBase implements DataProviderInterface {
/**
* {@inheritdoc}
*/
public function isViewsGeoOption(FieldPluginBase $views_field) {
if ($views_field instanceof SearchApiEntityField) {
$index_id = str_replace('search_api_index_', '', $views_field->table);
$index = Index::load($index_id);
if (empty($index)) {
return FALSE;
}
/** @var \Drupal\search_api\Item\FieldInterface $search_api_field */
$search_api_field = $index
->getField($views_field->field);
if (empty($search_api_field)) {
return FALSE;
}
elseif ($search_api_field
->getType() == 'location') {
return TRUE;
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function isFieldGeoOption(FieldDefinitionInterface $fieldDefinition) {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getPositionsFromViewsRow(ResultRow $row, FieldPluginBase $views_field = NULL) {
$positions = [];
if (!$views_field instanceof SearchApiEntityField) {
return [];
}
foreach ($views_field
->getItems($row) as $item) {
if (!empty($item['value'])) {
$pieces = explode(',', $item['value']);
if (count($pieces) != 2) {
continue;
}
$positions[] = [
'lat' => $pieces[0],
'lng' => $pieces[1],
];
}
elseif (!empty($item['raw'])) {
/** @var \Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem $geolocation_item */
$geolocation_item = $item['raw'];
$positions[] = [
'lat' => $geolocation_item
->get('lat')
->getValue(),
'lng' => $geolocation_item
->get('lng')
->getValue(),
];
}
}
return $positions;
}
}
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 field item list. Overrides DataProviderInterface:: |
3 |
DataProviderBase:: |
public | function |
Provide data provider settings form array. Overrides DataProviderInterface:: |
1 |
DataProviderBase:: |
public | function |
Return field item tokens. Overrides DataProviderInterface:: |
1 |
DataProviderBase:: |
public | function |
Replace field item tokens. 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 | |
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. | |
SearchAPI:: |
public | function |
Get positions from views row. Overrides DataProviderBase:: |
|
SearchAPI:: |
public | function |
Determine valid field geo option. Overrides DataProviderInterface:: |
|
SearchAPI:: |
public | function |
Determine valid views option. Overrides DataProviderBase:: |
|
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. |