You are here

class ContextProximityFilter in Geofield 8

Defines 'Geofield Context Filter' plugin.

@package Drupal\geofield\Plugin

Plugin annotation


@GeofieldProximitySource(
  id = "geofield_context_filter",
  label = @Translation("Context Filter (By context filter)"),
  description = @Translation("Allow the contextual input of Distance and Origin (as couple of Latitude and Longitude in decimal degrees.)"),
  exposedDescription = @Translation("Contextual input of Distance and Origin (as couple of Latitude and Longitude in decimal degrees.)"),
  context = {
    "sort",
    "field",
  },
)

Hierarchy

Expanded class hierarchy of ContextProximityFilter

File

src/Plugin/GeofieldProximitySource/ContextProximityFilter.php, line 27

Namespace

Drupal\geofield\Plugin\GeofieldProximitySource
View source
class ContextProximityFilter extends GeofieldProximitySourceBase implements ContainerFactoryPluginInterface {

  /**
   * The geofield proximity manager.
   *
   * @var \Drupal\geofield\Plugin\GeofieldProximitySourceManager
   */
  protected $proximitySourceManager;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('plugin.manager.geofield_proximity_source'));
  }

  /**
   * Constructs a GeocodeOrigin object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\geofield\Plugin\GeofieldProximitySourceManager $proximitySourceManager
   *   The Geofield Proximity Source manager service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, GeofieldProximitySourceManager $proximitySourceManager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->proximitySourceManager = $proximitySourceManager;
  }

  /**
   * {@inheritdoc}
   */
  public function getOrigin() {
    $origin = [];
    if (isset($this->viewHandler)) {

      /** @var \Drupal\geofield\Plugin\views\argument\GeofieldProximityArgument $geofield_proximity_argument */
      $geofield_proximity_argument = $this->viewHandler->view->argument;
      foreach ($this->viewHandler->view->argument as $k => $argument) {
        if ($argument instanceof GeofieldProximityArgument) {
          $geofield_proximity_argument = $argument;
        }
      }
      if (isset($geofield_proximity_argument)) {
        $argument_values = $geofield_proximity_argument
          ->getParsedReferenceLocation();
        $origin = [
          'lat' => $argument_values['lat'],
          'lon' => $argument_values['lon'],
        ];
      }
    }
    return $origin;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContextProximityFilter::$proximitySourceManager protected property The geofield proximity manager.
ContextProximityFilter::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ContextProximityFilter::getOrigin public function Gets the proximity distance origin. Overrides GeofieldProximitySourceBase::getOrigin
ContextProximityFilter::__construct public function Constructs a GeocodeOrigin object. Overrides PluginBase::__construct
GeofieldProximitySourceBase::$origin protected property The origin point to measure proximity from.
GeofieldProximitySourceBase::$units protected property The name of the constant defining the measurement unit.
GeofieldProximitySourceBase::$viewHandler protected property The view handler which uses this proximity plugin.
GeofieldProximitySourceBase::buildOptionsForm public function Builds the specific form elements for the geofield proximity plugin. Overrides GeofieldProximitySourceInterface::buildOptionsForm 2
GeofieldProximitySourceBase::getHaversineOptions public function Gets the haversine options. Overrides GeofieldProximitySourceInterface::getHaversineOptions
GeofieldProximitySourceBase::getProximity public function Get the calculated proximity. Overrides GeofieldProximitySourceInterface::getProximity
GeofieldProximitySourceBase::getUnits public function Get the current units. Overrides GeofieldProximitySourceInterface::getUnits
GeofieldProximitySourceBase::getUnitsOptions public function Get the list of valid options for units.
GeofieldProximitySourceBase::isEmptyLocation public function Check if Location is empty. Overrides GeofieldProximitySourceInterface::isEmptyLocation
GeofieldProximitySourceBase::isValidLocation public function Check for a valid couple of latitude and longitude. Overrides GeofieldProximitySourceInterface::isValidLocation
GeofieldProximitySourceBase::setOrigin public function Sets the proximity distance origin. Overrides GeofieldProximitySourceInterface::setOrigin
GeofieldProximitySourceBase::setUnits public function Set the units to perform the calculation in. Overrides GeofieldProximitySourceInterface::setUnits
GeofieldProximitySourceBase::setViewHandler public function Sets view handler which uses this proximity plugin. Overrides GeofieldProximitySourceInterface::setViewHandler
GeofieldProximitySourceBase::validateOptionsForm public function Validates the options form for the geofield proximity plugin. Overrides GeofieldProximitySourceInterface::validateOptionsForm 1
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.
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.