You are here

class ClientLocationOriginFilter in Geofield 8

Defines 'Geofield Client Location Origin' plugin.

@package Drupal\geofield\Plugin

Plugin annotation


@GeofieldProximitySource(
  id = "geofield_client_location_origin",
  label = @Translation("Client Location Origin"),
  description = @Translation("Gets the Client Location through the browser HTML5 Geolocation API."),
  context = {
    "filter",
  },
  exposedOnly = true
)

Hierarchy

Expanded class hierarchy of ClientLocationOriginFilter

File

src/Plugin/GeofieldProximitySource/ClientLocationOriginFilter.php, line 23

Namespace

Drupal\geofield\Plugin\GeofieldProximitySource
View source
class ClientLocationOriginFilter extends ManualOriginDefault {

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(array &$form, FormStateInterface $form_state, array $options_parents, $is_exposed = FALSE) {
    $form['#attributes'] = [
      'class' => [
        'proximity-origin-client',
      ],
    ];
    $form["origin"] = [
      '#title' => $this
        ->t('Client Coordinates'),
      '#type' => 'geofield_latlon',
      '#description' => $this
        ->t('Value in decimal degrees. Use dot (.) as decimal separator.'),
      '#default_value' => [
        'lat' => '',
        'lon' => '',
      ],
      '#attributes' => [
        'class' => [
          'visually-hidden',
        ],
      ],
    ];

    // If it is a proximity filter context and IS NOT exposed, render origin
    // summary option.
    if ($this->viewHandler->configuration['id'] == 'geofield_proximity_filter' && !$is_exposed) {
      $form['origin_summary_flag'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Show the Client Origin coordinates as summary in the Exposed Form'),
        '#default_value' => isset($this->configuration['origin_summary_flag']) ? $this->configuration['origin_summary_flag'] : TRUE,
      ];
    }

    // If it IS exposed load the geolocation library.
    if ($is_exposed) {
      $form['origin']['#attached']['library'][] = 'geofield/geolocation';

      // And eventually Render the Origin Summary.
      if (isset($this->configuration['origin_summary_flag']) && $this->configuration['origin_summary_flag']) {
        $form['origin_summary'] = [
          "#type" => 'html_tag',
          "#tag" => 'div',
          '#value' => $this
            ->t('from Latitude: @lat and Longitude: @lon.', [
            '@lat' => new FormattableMarkup('<span class="geofield-lat-summary">@lat</span>', [
              '@lat' => $this
                ->t('undefined'),
            ]),
            '@lon' => new FormattableMarkup('<span class="geofield-lon-summary">@lon</span>', [
              '@lon' => $this
                ->t('undefined'),
            ]),
          ]),
        ];
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClientLocationOriginFilter::buildOptionsForm public function Builds the specific form elements for the geofield proximity plugin. Overrides ManualOriginDefault::buildOptionsForm
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::getHaversineOptions public function Gets the haversine options. Overrides GeofieldProximitySourceInterface::getHaversineOptions
GeofieldProximitySourceBase::getOrigin public function Gets the proximity distance origin. Overrides GeofieldProximitySourceInterface::getOrigin 2
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
ManualOriginDefault::__construct public function Constructs a ManualOriginDefault object. Overrides PluginBase::__construct
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.