You are here

class SearchAPI in Geolocation Field 8.2

Same name and namespace in other branches
  1. 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

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\DataProvider
View 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

Namesort descending Modifiers Type Description Overrides
DataProviderBase::$entityFieldManager protected property Entity field manager.
DataProviderBase::$fieldDefinition protected property Field definition.
DataProviderBase::$viewsField protected property Views field.
DataProviderBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
DataProviderBase::fieldItemTokens public function Token replacement support function, callback to token replacement function.
DataProviderBase::getPositionsFromItem public function Get positions from field item list. Overrides DataProviderInterface::getPositionsFromItem 3
DataProviderBase::getSettingsForm public function Provide data provider settings form array. Overrides DataProviderInterface::getSettingsForm 1
DataProviderBase::getTokenHelp public function Return field item tokens. Overrides DataProviderInterface::getTokenHelp 1
DataProviderBase::replaceFieldItemTokens public function Replace field item tokens. Overrides DataProviderInterface::replaceFieldItemTokens 1
DataProviderBase::setFieldDefinition public function Set field definition. Overrides DataProviderInterface::setFieldDefinition
DataProviderBase::setViewsField public function Set views field. Overrides DataProviderInterface::setViewsField
DataProviderBase::__construct public function Constructs a new GeocoderBase object. Overrides PluginBase::__construct 1
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SearchAPI::getPositionsFromViewsRow public function Get positions from views row. Overrides DataProviderBase::getPositionsFromViewsRow
SearchAPI::isFieldGeoOption public function Determine valid field geo option. Overrides DataProviderInterface::isFieldGeoOption
SearchAPI::isViewsGeoOption public function Determine valid views option. Overrides DataProviderBase::isViewsGeoOption
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.